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);
|
$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
|
* Call the Model and delegate the create or delete action
|
||||||
* Feed the Event with the updated model
|
* 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::COUPON_CONDITION_UPDATE => array("updateCondition", 128),
|
||||||
TheliaEvents::ORDER_SET_POSTAGE => array("testFreePostage", 256),
|
TheliaEvents::ORDER_SET_POSTAGE => array("testFreePostage", 256),
|
||||||
TheliaEvents::ORDER_BEFORE_PAYMENT => array("afterOrder", 128),
|
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":
|
case "total_taxed_price":
|
||||||
$result = $cart->getTaxedAmount($taxCountry);
|
$result = $cart->getTaxedAmount($taxCountry);
|
||||||
break;
|
break;
|
||||||
|
case "total_taxed_price_without_discount":
|
||||||
|
$result = $cart->getTaxedAmount($taxCountry, false);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ class BaseFacade implements FacadeInterface
|
|||||||
{
|
{
|
||||||
$taxCountry = $this->getContainer()->get('thelia.taxEngine')->getDeliveryCountry();
|
$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);
|
$discount = $this->getEffect($couponsKept);
|
||||||
|
|
||||||
// Just In Case test
|
// Just In Case test
|
||||||
$checkoutTotalPrice = $this->facade->getCartTotalPrice();
|
$checkoutTotalPrice = $this->facade->getCartTotalTaxPrice();
|
||||||
if ($discount >= $checkoutTotalPrice) {
|
if ($discount >= $checkoutTotalPrice) {
|
||||||
$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;
|
$total = 0;
|
||||||
|
|
||||||
@@ -79,7 +79,9 @@ class Cart extends BaseCart
|
|||||||
$total += $cartItem->getRealTaxedPrice($country) * $cartItem->getQuantity();
|
$total += $cartItem->getRealTaxedPrice($country) * $cartItem->getQuantity();
|
||||||
}
|
}
|
||||||
|
|
||||||
$total -= $this->getDiscount();
|
if ($discount) {
|
||||||
|
$total -= $this->getDiscount();
|
||||||
|
}
|
||||||
|
|
||||||
return $total;
|
return $total;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
|||||||
->method('getCheckoutPostagePrice')
|
->method('getCheckoutPostagePrice')
|
||||||
->will($this->returnValue(8.30));
|
->will($this->returnValue(8.30));
|
||||||
$stubFacade->expects($this->any())
|
$stubFacade->expects($this->any())
|
||||||
->method('getCartTotalPrice')
|
->method('getCartTotalTaxPrice')
|
||||||
->will($this->returnValue(122.53));
|
->will($this->returnValue(122.53));
|
||||||
|
|
||||||
$couponManager = new CouponManager($stubContainer);
|
$couponManager = new CouponManager($stubContainer);
|
||||||
@@ -227,7 +227,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
|||||||
->method('getCheckoutPostagePrice')
|
->method('getCheckoutPostagePrice')
|
||||||
->will($this->returnValue(8.30));
|
->will($this->returnValue(8.30));
|
||||||
$stubFacade->expects($this->any())
|
$stubFacade->expects($this->any())
|
||||||
->method('getCartTotalPrice')
|
->method('getCartTotalTaxPrice')
|
||||||
->will($this->returnValue(122.53));
|
->will($this->returnValue(122.53));
|
||||||
|
|
||||||
$couponManager = new CouponManager($stubContainer);
|
$couponManager = new CouponManager($stubContainer);
|
||||||
@@ -543,7 +543,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
|||||||
->will($this->returnValue($currencies));
|
->will($this->returnValue($currencies));
|
||||||
|
|
||||||
$stubFacade->expects($this->any())
|
$stubFacade->expects($this->any())
|
||||||
->method('getCartTotalPrice')
|
->method('getCartTotalTaxPrice')
|
||||||
->will($this->returnValue($cartTotalPrice));
|
->will($this->returnValue($cartTotalPrice));
|
||||||
|
|
||||||
$stubFacade->expects($this->any())
|
$stubFacade->expects($this->any())
|
||||||
|
|||||||
@@ -124,7 +124,7 @@
|
|||||||
<th class="total">{intl l="Total"}</th>
|
<th class="total">{intl l="Total"}</th>
|
||||||
<td class="total">
|
<td class="total">
|
||||||
<div class="total-price">
|
<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>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user