diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index ed19c64b9..82de51bdf 100644 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -161,6 +161,22 @@ class Coupon extends BaseAction implements EventSubscriberInterface $event->setDiscount($totalDiscount); } + public function updateOrderDiscount($event) + { + + $discount = $this->couponManager->getDiscount(); + + $this->request + ->getSession() + ->getCart() + ->setDiscount($discount) + ->save(); + $this->request + ->getSession() + ->getOrder() + ->setDiscount($discount); + } + /** * Call the Model and delegate the create or delete action * Feed the Event with the updated model @@ -310,6 +326,9 @@ class Coupon extends BaseAction implements EventSubscriberInterface TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128), TheliaEvents::ORDER_SET_POSTAGE => array("testFreePostage", 256), TheliaEvents::ORDER_BEFORE_PAYMENT => array("afterOrder", 128), + TheliaEvents::CART_ADDITEM => array("updateOrderDiscount", 10), + TheliaEvents::CART_UPDATEITEM => array("updateOrderDiscount", 10), + TheliaEvents::CART_DELETEITEM => array("updateOrderDiscount", 10), ); } } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index bdc477551..c6119811a 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -202,6 +202,9 @@ class DataAccessFunctions extends AbstractSmartyPlugin case "total_taxed_price": $result = $cart->getTaxedAmount($taxCountry); break; + case "total_taxed_price_without_discount": + $result = $cart->getTaxedAmount($taxCountry, false); + break; } return $result; diff --git a/core/lib/Thelia/Coupon/BaseFacade.php b/core/lib/Thelia/Coupon/BaseFacade.php index 51a43064f..b8f5c9a7f 100644 --- a/core/lib/Thelia/Coupon/BaseFacade.php +++ b/core/lib/Thelia/Coupon/BaseFacade.php @@ -129,7 +129,7 @@ class BaseFacade implements FacadeInterface { $taxCountry = $this->getContainer()->get('thelia.taxEngine')->getDeliveryCountry(); - return $this->getCart()->getTaxedAmount($taxCountry); + return $this->getCart()->getTaxedAmount($taxCountry, false); } /** diff --git a/core/lib/Thelia/Coupon/CouponManager.php b/core/lib/Thelia/Coupon/CouponManager.php index 92fc8e572..f072ad69b 100644 --- a/core/lib/Thelia/Coupon/CouponManager.php +++ b/core/lib/Thelia/Coupon/CouponManager.php @@ -76,7 +76,7 @@ class CouponManager $discount = $this->getEffect($couponsKept); // Just In Case test - $checkoutTotalPrice = $this->facade->getCartTotalPrice(); + $checkoutTotalPrice = $this->facade->getCartTotalTaxPrice(); if ($discount >= $checkoutTotalPrice) { $discount = $checkoutTotalPrice; } diff --git a/core/lib/Thelia/Model/Cart.php b/core/lib/Thelia/Model/Cart.php index efd37c344..7cf66eeb3 100644 --- a/core/lib/Thelia/Model/Cart.php +++ b/core/lib/Thelia/Model/Cart.php @@ -71,7 +71,7 @@ class Cart extends BaseCart ; } - public function getTaxedAmount(Country $country) + public function getTaxedAmount(Country $country, $discount = true) { $total = 0; @@ -79,7 +79,9 @@ class Cart extends BaseCart $total += $cartItem->getRealTaxedPrice($country) * $cartItem->getQuantity(); } - $total -= $this->getDiscount(); + if ($discount) { + $total -= $this->getDiscount(); + } return $total; } diff --git a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php index f19c4c04b..0286efdd4 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php @@ -166,7 +166,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua ->method('getCheckoutPostagePrice') ->will($this->returnValue(8.30)); $stubFacade->expects($this->any()) - ->method('getCartTotalPrice') + ->method('getCartTotalTaxPrice') ->will($this->returnValue(122.53)); $couponManager = new CouponManager($stubContainer); @@ -227,7 +227,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua ->method('getCheckoutPostagePrice') ->will($this->returnValue(8.30)); $stubFacade->expects($this->any()) - ->method('getCartTotalPrice') + ->method('getCartTotalTaxPrice') ->will($this->returnValue(122.53)); $couponManager = new CouponManager($stubContainer); @@ -543,7 +543,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua ->will($this->returnValue($currencies)); $stubFacade->expects($this->any()) - ->method('getCartTotalPrice') + ->method('getCartTotalTaxPrice') ->will($this->returnValue($cartTotalPrice)); $stubFacade->expects($this->any()) diff --git a/templates/frontOffice/default/cart.html b/templates/frontOffice/default/cart.html index 8e70cbb21..bb5f644be 100644 --- a/templates/frontOffice/default/cart.html +++ b/templates/frontOffice/default/cart.html @@ -124,7 +124,7 @@ {intl l="Total"}
- {cart attr="total_taxed_price"} {currency attr="symbol"} + {cart attr="total_taxed_price_without_discount"} {currency attr="symbol"}