[-] FO : automatic refresh of the cart when a cart rule is added
This commit is contained in:
@@ -855,7 +855,7 @@ class CartRuleCore extends ObjectModel
|
||||
public static function autoRemoveFromCart($context = null)
|
||||
{
|
||||
if (!CartRule::isFeatureActive())
|
||||
return;
|
||||
return array();
|
||||
|
||||
$errors = array();
|
||||
if (!$context)
|
||||
|
||||
@@ -34,6 +34,8 @@ class CartControllerCore extends FrontController
|
||||
protected $id_address_delivery;
|
||||
protected $customization_id;
|
||||
protected $qty;
|
||||
|
||||
protected $ajax_refresh = false;
|
||||
|
||||
/**
|
||||
* This is not a public page, so the canonical redirection is disabled
|
||||
@@ -111,7 +113,9 @@ class CartControllerCore extends FrontController
|
||||
$this->context->cart->update();
|
||||
}
|
||||
}
|
||||
CartRule::autoRemoveFromCart();
|
||||
$removed = CartRule::autoRemoveFromCart();
|
||||
if (count($removed))
|
||||
$this->ajax_refresh = true;
|
||||
}
|
||||
|
||||
protected function processChangeProductAddressDelivery()
|
||||
@@ -215,6 +219,7 @@ class CartControllerCore extends FrontController
|
||||
|
||||
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'));
|
||||
if ($updateQuantity < 0)
|
||||
{
|
||||
@@ -224,9 +229,18 @@ class CartControllerCore extends FrontController
|
||||
}
|
||||
else if (!$updateQuantity)
|
||||
$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)
|
||||
die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors)));
|
||||
if ($this->ajax_refresh)
|
||||
die(Tools::jsonEncode(array('refresh' => true)));
|
||||
|
||||
if (Tools::getIsset('summary'))
|
||||
{
|
||||
|
||||
@@ -258,11 +258,13 @@ function deleteProductFromSummary(id)
|
||||
var errors = '';
|
||||
for(error in jsonData.errors)
|
||||
//IE6 bug fix
|
||||
if(error != 'indexOf')
|
||||
if (error != 'indexOf')
|
||||
errors += jsonData.errors[error] + "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jsonData.refresh)
|
||||
location.reload();
|
||||
if (parseInt(jsonData.summary.products.length) == 0)
|
||||
{
|
||||
$('#center_column').children().each(function() {
|
||||
@@ -308,7 +310,7 @@ function deleteProductFromSummary(id)
|
||||
|
||||
function upQuantity(id, qty)
|
||||
{
|
||||
if(typeof(qty)=='undefined' || !qty)
|
||||
if (typeof(qty) == 'undefined' || !qty)
|
||||
qty = 1;
|
||||
var customizationId = 0;
|
||||
var productId = 0;
|
||||
@@ -344,6 +346,8 @@ function upQuantity(id, qty)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jsonData.refresh)
|
||||
location.reload();
|
||||
updateCustomizedDatas(jsonData.customizedDatas);
|
||||
updateCartSummary(jsonData.summary);
|
||||
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
|
||||
@@ -403,6 +407,8 @@ function downQuantity(id, qty)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jsonData.refresh)
|
||||
location.reload();
|
||||
updateCustomizedDatas(jsonData.customizedDatas);
|
||||
updateCartSummary(jsonData.summary);
|
||||
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
|
||||
|
||||
Reference in New Issue
Block a user