coupons effect are recalculated after each product's cart modification. Fix #237
This commit is contained in:
@@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
<th class="total">{intl l="Total"}</th>
|
||||
<td class="total">
|
||||
<div class="total-price">
|
||||
<span class="price">{cart attr="total_taxed_price"} {currency attr="symbol"}</span>
|
||||
<span class="price">{cart attr="total_taxed_price_without_discount"} {currency attr="symbol"}</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user