/** * Check if cart meets minimum price requirements for a coupon. * * @param CartInterface $cart Cart * @param CouponInterface $coupon Coupon * * @throws CouponBelowMinimumPurchaseException Minimum value not reached */ public function validateCartCouponMinimumPrice(CartInterface $cart, CouponInterface $coupon) { $couponMinimumPrice = $coupon->getMinimumPurchase(); if ($couponMinimumPrice->getAmount() === 0) { return; } $productMoney = $cart->getPurchasableAmount(); if ($couponMinimumPrice->getCurrency() != $productMoney->getCurrency()) { $couponMinimumPrice = $this->currencyConverter->convertMoney($couponMinimumPrice, $productMoney->getCurrency()); } if ($productMoney->isLessThan($couponMinimumPrice)) { throw new CouponBelowMinimumPurchaseException(); } }
/** * 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); }
/** * Calculate coupon absolute value. * * @param CartInterface $cart Cart * @param CouponInterface $coupon Coupon * * @return MoneyInterface|false Absolute value for this coupon in this cart. */ public function getCouponAbsoluteValue(CartInterface $cart, CouponInterface $coupon) { $couponPercent = $coupon->getDiscount(); return $cart->getPurchasableAmount()->multiply($couponPercent / 100); }
/** * Given ShippingPriceRange is satisfied by a cart * * @param CartInterface $cart Cart * @param ShippingRangeInterface $shippingRange Carrier Range * * @return boolean ShippingRange is satisfied by cart */ private function isShippingPriceRangeSatisfiedByCart(CartInterface $cart, ShippingRangeInterface $shippingRange) { $cartPrice = $cart->getPurchasableAmount(); $cartPriceCurrency = $cartPrice->getCurrency(); $shippingRangeFromPrice = $shippingRange->getFromPrice(); $shippingRangeToPrice = $shippingRange->getToPrice(); return $this->isShippingRangeZonesSatisfiedByCart($cart, $shippingRange) && $this->currencyConverter->convertMoney($shippingRangeFromPrice, $cartPriceCurrency)->compareTo($cartPrice) <= 0 && $this->currencyConverter->convertMoney($shippingRangeToPrice, $cartPriceCurrency)->compareTo($cartPrice) > 0; }