[-] FO : automatic refresh of the cart when a cart rule is added

This commit is contained in:
dMetzger committed 2012-02-23 18:24:23 +00:00
1 parent da4993d666
commit 3568be9aa0
3 files changed
+25 -3

No files matched your search

+1 -1
View File
@@ -855,7 +855,7 @@ class CartRuleCore extends ObjectModel
public static function autoRemoveFromCart($context = null) public static function autoRemoveFromCart($context = null)
{ {
if (!CartRule::isFeatureActive()) if (!CartRule::isFeatureActive())
return; return array();
$errors = array(); $errors = array();
if (!$context) if (!$context)
+18 -2
View File
@@ -35,6 +35,8 @@ class CartControllerCore extends FrontController
protected $customization_id; protected $customization_id;
protected $qty; protected $qty;
protected $ajax_refresh = false;
/** /**
* This is not a public page, so the canonical redirection is disabled * This is not a public page, so the canonical redirection is disabled
*/ */
@@ -111,7 +113,9 @@ class CartControllerCore extends FrontController
$this->context->cart->update(); $this->context->cart->update();
} }
} }
CartRule::autoRemoveFromCart(); $removed = CartRule::autoRemoveFromCart();
if (count($removed))
$this->ajax_refresh = true;
} }
protected function processChangeProductAddressDelivery() protected function processChangeProductAddressDelivery()
@@ -215,6 +219,7 @@ class CartControllerCore extends FrontController
if (!$this->errors) if (!$this->errors)
{ {
$cart_rules = $this->context->cart->getCartRules();
$updateQuantity = $this->context->cart->updateQty($this->qty, $this->id_product, $this->id_product_attribute, $this->customization_id, $this->id_address_delivery, Tools::getValue('op', 'up')); $updateQuantity = $this->context->cart->updateQty($this->qty, $this->id_product, $this->id_product_attribute, $this->customization_id, $this->id_address_delivery, Tools::getValue('op', 'up'));
if ($updateQuantity < 0) if ($updateQuantity < 0)
{ {
@@ -224,9 +229,18 @@ class CartControllerCore extends FrontController
} }
else if (!$updateQuantity) else if (!$updateQuantity)
$this->errors[] = Tools::displayError('You already have the maximum quantity available for this product.', false); $this->errors[] = Tools::displayError('You already have the maximum quantity available for this product.', false);
else
{
$cart_rules2 = $this->context->cart->getCartRules();
if (count($cart_rules2) != count($cart_rules))
$this->ajax_refresh = true;
} }
} }
CartRule::autoRemoveFromCart(); }
$removed = CartRule::autoRemoveFromCart();
if (count($removed))
$this->ajax_refresh = true;
} }
/** /**
@@ -255,6 +269,8 @@ class CartControllerCore extends FrontController
{ {
if ($this->errors) if ($this->errors)
die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors))); die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors)));
if ($this->ajax_refresh)
die(Tools::jsonEncode(array('refresh' => true)));
if (Tools::getIsset('summary')) if (Tools::getIsset('summary'))
{ {
+6
View File
@@ -263,6 +263,8 @@ function deleteProductFromSummary(id)
} }
else else
{ {
if (jsonData.refresh)
location.reload();
if (parseInt(jsonData.summary.products.length) == 0) if (parseInt(jsonData.summary.products.length) == 0)
{ {
$('#center_column').children().each(function() { $('#center_column').children().each(function() {
@@ -344,6 +346,8 @@ function upQuantity(id, qty)
} }
else else
{ {
if (jsonData.refresh)
location.reload();
updateCustomizedDatas(jsonData.customizedDatas); updateCustomizedDatas(jsonData.customizedDatas);
updateCartSummary(jsonData.summary); updateCartSummary(jsonData.summary);
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
@@ -403,6 +407,8 @@ function downQuantity(id, qty)
} }
else else
{ {
if (jsonData.refresh)
location.reload();
updateCustomizedDatas(jsonData.customizedDatas); updateCustomizedDatas(jsonData.customizedDatas);
updateCartSummary(jsonData.summary); updateCartSummary(jsonData.summary);
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);