/** * 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); } }
/** * Load cart total price. * * @param CartInterface $cart Cart */ public function loadCartTotalAmount(CartInterface $cart) { $currency = $this->currencyWrapper->get(); $finalAmount = clone $cart->getPurchasableAmount(); /** * Calculates the shipping amount. */ $shippingAmount = $cart->getShippingAmount(); if ($shippingAmount instanceof MoneyInterface) { $convertedShippingAmount = $this->currencyConverter->convertMoney($shippingAmount, $currency); $finalAmount = $finalAmount->add($convertedShippingAmount); } /** * Calculates the coupon amount. */ $couponAmount = $cart->getCouponAmount(); if ($couponAmount instanceof MoneyInterface) { $convertedCouponAmount = $this->currencyConverter->convertMoney($couponAmount, $currency); $finalAmount = $finalAmount->subtract($convertedCouponAmount); } $cart->setAmount($finalAmount); }