/** * A new Order has been created. * * This method adds Coupon logic in this transformation * * @param CartInterface $cart Cart * @param OrderInterface $order Order */ public function createOrderCouponsByCartCoupons(CartInterface $cart, OrderInterface $order) { $cartCouponAmount = $cart->getCouponAmount(); if ($cartCouponAmount instanceof MoneyInterface) { $order->setCouponAmount($cartCouponAmount); } /** * @var CouponInterface $coupons */ $coupons = $this->cartCouponManager->getCoupons($cart); if (empty($coupons)) { return; } /** * Before applying Coupons to Order, we should remove old references * if exist. */ $this->orderCouponTruncator->truncateOrderCoupons($order); /** * An event is dispatched for each convertible coupon. */ foreach ($coupons as $coupon) { $this->orderCouponEventDispatcher->dispatchOrderCouponOnApplyEvent($order, $coupon); } }
/** * 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); } }