/** * If the cart's shipping amount is not defined, then put an empty Money * value * * @param CartInterface $cart Cart */ public function validateEmptyShippingAmount(CartInterface $cart) { $shippingAmount = $cart->getShippingAmount(); if (!$shippingAmount instanceof MoneyInterface) { $cart->setShippingAmount($this->emptyMoneyWrapper->get()); } }
/** * 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); }