Пример #1
0
 private function addProduct($product)
 {
     $op = new \Club\ShopBundle\Entity\OrderProduct();
     $op->setOrder($this->order);
     $op->setPrice($product->getPrice());
     $op->setProductName($product->getProductName());
     $op->setQuantity($product->getQuantity());
     $op->setType($product->getType());
     if ($product->getProduct()) {
         $op->setProduct($product->getProduct());
     }
     $this->order->addOrderProduct($op);
     foreach ($product->getProductAttributes() as $attr) {
         $opa = new \Club\ShopBundle\Entity\OrderProductAttribute();
         $opa->setOrderProduct($op);
         $opa->setAttributeName($attr->getAttributeName());
         $opa->setValue($attr->getValue());
         $op->addOrderProductAttribute($opa);
         $this->em->persist($opa);
     }
     if ($product->getProduct() instanceof \Club\ShopBundle\Entity\Product) {
         switch (true) {
             case $product->getProduct()->getQuantity() == '0':
                 throw new \Club\ShopBundle\Exception\NotInStockException('No more products left');
                 break;
             case $product->getProduct()->getQuantity() == '-1':
                 break;
             default:
                 $quantity = $product->getProduct()->getQuantity() - 1;
                 $this->em->persist($product->getProduct());
         }
     }
     $this->em->persist($op);
 }
Пример #2
0
 private function addProduct($product)
 {
     $op = new \Club\ShopBundle\Entity\OrderProduct();
     $op->setOrder($this->order);
     $op->setPrice($product->getPrice());
     $op->setProductName($product->getProductName());
     $op->setVatRate($product->getVatRate());
     $op->setQuantity($product->getQuantity());
     $op->setType($product->getType());
     if ($product->getProduct()) {
         $op->setProduct($product->getProduct());
     }
     $this->order->addOrderProduct($op);
     foreach ($product->getProductAttributes() as $attr) {
         $opa = new \Club\ShopBundle\Entity\OrderProductAttribute();
         $opa->setOrderProduct($op);
         $opa->setAttributeName($attr->getAttributeName());
         $opa->setValue($attr->getValue());
         $op->addOrderProductAttribute($opa);
         $this->em->persist($opa);
     }
     $this->em->persist($op);
 }