/**
  * A new Order has been created.
  *
  * This method adds Coupon logic in this transformation
  *
  * @param OrderOnCreatedEvent $orderOnCreatedEvent OrderOnCreated Event
  *
  * @return null
  */
 public function convertCouponToOrder(OrderOnCreatedEvent $orderOnCreatedEvent)
 {
     $order = $orderOnCreatedEvent->getOrder();
     $cart = $orderOnCreatedEvent->getCart();
     $cartCouponAmount = $cart->getCouponAmount();
     if ($cartCouponAmount instanceof MoneyInterface) {
         $order->setCouponAmount($cartCouponAmount);
     }
     /**
      * @var CouponInterface[]|Collection $coupons
      */
     $coupons = $this->cartCouponManager->getCoupons($cart);
     if ($coupons->isEmpty()) {
         return null;
     }
     /**
      * Before applying Coupons to Order, we should remove old references
      * if exist. Otherwise,
      */
     $this->truncateOrderCoupons($order);
     /**
      * An event is dispatched for each convertible coupon
      */
     foreach ($coupons as $coupon) {
         $this->orderCouponEventDispatcher->dispatchOrderCouponOnApplyEvent($order, $coupon);
     }
 }
 /**
  * Performs all processes to be performed after the order creation
  *
  * Flushes all loaded order and related entities.
  *
  * @param OrderOnCreatedEvent $event Event
  *
  * @return $this Self object
  */
 public function saveOrder(OrderOnCreatedEvent $event)
 {
     $cart = $event->getCart();
     $shippingMethodId = $cart->getShippingMethod();
     if (empty($shippingMethodId)) {
         return $this;
     }
     $shippingMethod = $this->shippingWrapper->getOneById($cart, $shippingMethodId);
     $order = $event->getOrder();
     if ($shippingMethod instanceof ShippingMethod) {
         $order->setShippingAmount($shippingMethod->getPrice());
         $order->setShippingMethod($shippingMethod);
     }
     return $this;
 }
예제 #3
0
 /**
  * After an Order is created, the cart is set as Ordered enabling related
  * flag
  *
  * @param OrderOnCreatedEvent $event Event
  */
 public function setCartAsOrdered(OrderOnCreatedEvent $event)
 {
     $cart = $event->getCart()->setOrdered(true);
     $this->cartObjectManager->flush($cart);
 }
 /**
  * Load cart shipping amount
  *
  * @param OrderOnCreatedEvent $event Event
  */
 public function loadOrderShippingMethod(OrderOnCreatedEvent $event)
 {
     $this->orderShippingMethodLoader->loadOrderShippingMethod($event->getCart(), $event->getOrder());
 }
 /**
  * A new Order has been created.
  *
  * @param OrderOnCreatedEvent $event OrderOnCreated Event
  */
 public function createOrderCouponsByCartCoupons(OrderOnCreatedEvent $event)
 {
     $this->cartCouponToOrderTransformer->createOrderCouponsByCartCoupons($event->getCart(), $event->getOrder());
 }