diff --git a/classes/CartRule.php b/classes/CartRule.php index 402094aff..fa378e7de 100644 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -969,7 +969,7 @@ class CartRuleCore extends ObjectModel public static function autoRemoveFromCart($context = null) { - if (!CartRule::isFeatureActive()) + if (!CartRule::isFeatureActive() || !Validate::isLoadedObject($context->cart)) return array(); $errors = array(); diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index eed5c208f..ce6eb96b1 100755 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -177,10 +177,6 @@ class FrontControllerCore extends Controller { $this->context->customer->logout(); - // Login information have changed, so we check if the cart rules still apply - CartRule::autoRemoveFromCart($this->context); - CartRule::autoAddToCart($this->context); - Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null); } elseif (isset($_GET['mylogout'])) @@ -249,6 +245,10 @@ class FrontControllerCore extends Controller $cart->id_address_delivery = 0; $cart->id_address_invoice = 0; } + + // Needed if the merchant want to give a free product to every visitors + $this->context->cart = $cart; + CartRule::autoAddToCart($this->context); } $locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')).'_'.strtoupper(Configuration::get('PS_LOCALE_COUNTRY').'.UTF-8');