Esempio n. 1
0
 /**
  * Create from array of product
  *
  * @param User $user
  * @param User $seller
  * @param array $products
  * @param string $currencyCode
  * @param mixed $orderInfo
  *
  * @return Order $order|false
  */
 public function createOrderFromProductsForUser(User $user, User $seller, $products, $currencyCode, $orderInfo)
 {
     $order = $this->createEmptyOrder($user, $seller, $currencyCode, $orderInfo);
     $em = $this->getEntityManager();
     $total = 0;
     foreach ($products as $product) {
         $total = $total + $product->getPrice() * 1;
         $orderItem = new OrderItem();
         $orderItem->setName($product->getName());
         $orderItem->setPrice($product->getPrice());
         $orderItem->setQty(1);
         $orderItem->setProduct($product);
         $orderItem->setOrder($order);
         $em->persist($orderItem);
     }
     $em->flush();
     // Set totals
     $order->setTotalAmount($total);
     $em->persist($order);
     $em->flush();
     return $order;
 }
Esempio n. 2
0
 /**
  * Remove item
  *
  * @param OrderItem $item
  */
 public function removeItem(OrderItem $item)
 {
     $this->item->removeElement($item);
 }