title: Symfony2/Doctrine, having to put business logic in my controller? And duplicating controller?
body: <p>I have a somewhat complex pricing mechanism in my application- Here are some of my business rules to set the stage (Entities are <strong>bolded</strong>):</p>
  
  <ul>
  <li>A <strong>Product</strong> may have unique <strong>Price Points</strong> for a given <strong>Customer</strong>, <strong>Website</strong>, or <strong>Customer Group</strong>.</li>
  <li>A <strong>Product</strong> can sometimes have one or more additional <strong>Options</strong> that may have their own <strong>Price Points</strong> <em>or</em> <strong>Price Rules</strong>.</li>
  <li>A <strong>Product</strong> has one <strong>Unique Addition</strong> selected by the user, which is essentially a price and an integer.</li>
  </ul>
  
  <p>Right now, I have an EntityRepository for <strong>Price Points</strong> to essentially determine the correct price point for the base product. The same goes for the <strong>Unique Addition</strong> and the <strong>Options</strong>.</p>
  
  <h1>PricePointRepository</h1>
  
  <pre><code>public function getThePrice($Product, $qty, $Website, $Customer = null) 
  {
      //all logic to get product price for this given instance goes here. Good.
  }
  </code></pre>
  
  <h1>Controller (simplified)</h1>
  
  <pre><code>public function indexAction() 
  {
      $Product = $em-&gt;dostuffwithpostdata;
      $qty = POST['qty']; //inb4insecure trolls
      $Website = $em-&gt;dostuff();
      $Customer = (if user is logged in, return their object with $em, otherwise null as it is a guest or public person); // No business logic here, just understanding the request.
  
      $price = $em-&gt;getRepository(PricePointRepository)-&gt;getThePrice($Product,$qty,Website,$Customer);
  
      $Options[] = $em-&gt;dostuffwithPOSTdata;
      $optionsPrice = 0;
      //Below is some logic directly related to pricing the product. 
      foreach($Options as $option) {
          if($option-&gt;hasRule()) {
              $optionsPrice += $ruleprice; //after some other stuff of course)
          } else {
              $optionsPrice += $em-&gt;getRepository(OptionPricePoints)-&gt;getPrice($option-&gt;getID(),$qty);
          }
      }
  
      $uniqueAdditionPrice = $em-&gt;stuff;
  
      $finalprice = $price + $optionsPrice + $uniqueAdditionPrice; //This is logic related to how I price this type of product!
      $unitprice = $finalprice / $qty;
  
      //twig stuff to render and show $finalprice, $unitprice, $uniqueAdditionPrice
  }
  </code></pre>
  
  <p>That's just for the product page. What happens when I get to the cart, saving the order, etc, when this <strong>logic</strong> needs to be reused. As you can see, I use Doctrine throughout to pull data based on my business logic in the repository classes.</p>
  
  <p>I gladly welcome urdoingitwrong answers, because I really do think this is wrong. How do I go about fixing this? Something beautiful would be a service that essentially goes like this:</p>
  
  <pre><code>$pricer = getPricerService-&gt;Pricer($Entities,$postdata,$etc);
  $unitPrice = $pricer-&gt;getUnitPrice();
  $totalPrice = $pricer-&gt;getTotalPrice();
  $optionsPrice = $pricer-&gt;getOptionsPrice();
  </code></pre>
  
  <p>But I have no idea how to go about doing that inside of Symfony/Doctrine, especially the way Doctrine and Repositories are accessed in Controllers.</p>