coupons effect are recalculated after each product's cart modification. Fix #237

This commit is contained in:
Manuel Raynaud
2014-03-03 17:40:54 +01:00
parent c30abacfbc
commit 06539ad9bf
7 changed files with 32 additions and 8 deletions

View File

@@ -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),
);
}
}

View File

@@ -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;

View File

@@ -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);
}
/**

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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())

View File

@@ -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>