Ejemplo n.º 1
0
 /**
  * This method creates a Order given a Cart.
  *
  * If cart has a order, this one is taken as order to be used, otherwise
  * new order will be created from the scratch
  *
  * This method dispatches these events
  *
  * ElcodiPurchaseEvents::ORDER_PRECREATED
  * ElcodiPurchaseEvents::ORDER_ONCREATED
  * ElcodiPurchaseEvents::ORDER_POSTCREATED
  *
  * @param CartInterface $cart Cart to create order from
  *
  * @return OrderInterface the created order
  */
 public function createOrderFromCart(CartInterface $cart)
 {
     $this->orderEventDispatcher->dispatchOrderPreCreatedEvent($cart);
     $order = $cart->getOrder() instanceof OrderInterface ? $cart->getOrder() : $this->orderFactory->create();
     $cart->setOrder($order);
     $orderLines = $this->cartLineOrderLineTransformer->createOrderLinesByCartLines($order, $cart->getCartLines());
     $order->setCustomer($cart->getCustomer())->setCart($cart)->setQuantity($cart->getQuantity())->setProductAmount($cart->getProductAmount())->setAmount($cart->getAmount())->setOrderLines($orderLines);
     $this->orderEventDispatcher->dispatchOrderOnCreatedEvent($cart, $order);
     return $order;
 }
Ejemplo n.º 2
0
 /**
  * This method creates a Order given a Cart.
  *
  * If cart has a order, this one is taken as order to be used, otherwise
  * new order will be created from the scratch
  *
  * This method dispatches these events
  *
  * ElcodiPurchaseEvents::ORDER_PRECREATED
  * ElcodiPurchaseEvents::ORDER_ONCREATED
  * ElcodiPurchaseEvents::ORDER_POSTCREATED
  *
  * @param CartInterface $cart Cart to create order from
  *
  * @return OrderInterface the created order
  */
 public function createOrderFromCart(CartInterface $cart)
 {
     $this->orderEventDispatcher->dispatchOrderPreCreatedEvent($cart);
     $order = $cart->getOrder() instanceof OrderInterface ? $cart->getOrder() : $this->orderFactory->create();
     $cart->setOrder($order);
     $orderLines = $this->cartLineOrderLineTransformer->createOrderLinesByCartLines($order, $cart->getCartLines());
     /**
      * @var OrderInterface $order
      */
     $order->setCustomer($cart->getCustomer())->setCart($cart)->setQuantity($cart->getQuantity())->setProductAmount($cart->getProductAmount())->setShippingAmount($cart->getShippingAmount())->setAmount($cart->getAmount())->setHeight($cart->getHeight())->setWidth($cart->getWidth())->setDepth($cart->getDepth())->setWeight($cart->getWeight())->setBillingAddress($cart->getBillingAddress())->setDeliveryAddress($cart->getDeliveryAddress())->setOrderLines($orderLines);
     $couponAmount = $cart->getCouponAmount();
     if ($couponAmount instanceof MoneyInterface) {
         $order->setCouponAmount($couponAmount);
     }
     $this->orderEventDispatcher->dispatchOrderOnCreatedEvent($cart, $order);
     return $order;
 }
Ejemplo n.º 3
0
 /**
  * This method creates a Order given a Cart.
  *
  * If cart has a order, this one is taken as order to be used, otherwise
  * new order will be created from the scratch
  *
  * This method dispatches these events
  *
  * ElcodiPurchaseEvents::ORDER_PRECREATED
  * ElcodiPurchaseEvents::ORDER_ONCREATED
  * ElcodiPurchaseEvents::ORDER_POSTCREATED
  *
  * @param CartInterface $cart Cart to create order from
  *
  * @return OrderInterface the created order
  */
 public function createOrderFromCart(CartInterface $cart)
 {
     $this->orderEventDispatcher->dispatchOrderPreCreatedEvent($cart);
     $order = $cart->getOrder() instanceof OrderInterface ? $cart->getOrder() : $this->orderFactory->create();
     $cart->setOrder($order);
     $orderLines = $this->cartLineOrderLineTransformer->createOrderLinesByCartLines($order, $cart->getCartLines());
     /**
      * @var OrderInterface $order
      */
     $order->setCustomer($cart->getCustomer())->setCart($cart)->setQuantity($cart->getTotalItemNumber())->setPurchasableAmount($cart->getPurchasableAmount())->setShippingAmount($cart->getShippingAmount())->setAmount($cart->getAmount())->setHeight($cart->getHeight())->setWidth($cart->getWidth())->setDepth($cart->getDepth())->setWeight($cart->getWeight())->setBillingAddress($cart->getBillingAddress())->setDeliveryAddress($cart->getDeliveryAddress())->setOrderLines($orderLines);
     $couponAmount = $cart->getCouponAmount();
     if ($couponAmount instanceof MoneyInterface) {
         $order->setCouponAmount($couponAmount);
     }
     $this->orderEventDispatcher->dispatchOrderOnCreatedEvent($cart, $order);
     // Salvataggio per fare in modo che rimanga collegato orderLineId al cartLine
     foreach ($cart->getCartLines() as $cartLine) {
         $this->cartLineObjectManager->persist($cartLine);
     }
     $this->cartLineObjectManager->flush();
     return $order;
 }