From c1d76587493367cb37692b1adc19200b41d60b53 Mon Sep 17 00:00:00 2001 From: dMetzger Date: Wed, 25 Apr 2012 12:58:35 +0000 Subject: [PATCH] [-] FO : sometimes the cart rules total was doubled - fixed! #PSTEST-1202 git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14871 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Cart.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index 359f2e96a..9cd536bf1 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -314,8 +314,8 @@ class CartCore extends ObjectModel // If the cart has not been saved, then there can't be any cart rule applied if (!CartRule::isFeatureActive() || !$this->id) return array(); - - $cache_key = 'Cart::getCartRules'.$this->id; + + $cache_key = 'Cart::getCartRules'.$this->id.'-'.$filter; if (!Cache::isStored($cache_key)) { $result = Db::getInstance()->executeS(' @@ -326,7 +326,10 @@ class CartCore extends ObjectModel cd.`id_cart_rule` = crl.`id_cart_rule` AND crl.id_lang = '.(int)$this->id_lang.' ) - WHERE `id_cart` = '.(int)$this->id + WHERE `id_cart` = '.(int)$this->id.' + '.($filter == CartRule::FILTER_ACTION_SHIPPING ? 'AND free_shipping = 1' : '').' + '.($filter == CartRule::FILTER_ACTION_GIFT ? 'AND gift_product != 0' : '').' + '.($filter == CartRule::FILTER_ACTION_REDUCTION ? 'AND (reduction_percent != 0 OR reduction_amount != 0)' : '') ); Cache::store($cache_key, $result); } @@ -1413,8 +1416,20 @@ class CartCore extends ObjectModel if ($with_shipping) $cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_ALL); else - $cart_rules = array_merge($this->getCartRules(CartRule::FILTER_ACTION_REDUCTION), $this->getCartRules(CartRule::FILTER_ACTION_GIFT)); - + { + $cart_rules = $this->getCartRules(CartRule::FILTER_ACTION_REDUCTION); + // Cart Rules array are merged manually in order to avoid doubles + foreach ($this->getCartRules(CartRule::FILTER_ACTION_GIFT) as $tmp_cart_rule) + { + $flag = false; + foreach ($cart_rules as $cart_rule) + if ($tmp_cart_rule['id_cart_rule'] == $cart_rule['id_cart_rule']) + $flag = true; + if (!$flag) + $cart_rules[] = $tmp_cart_rule; + } + } + foreach ($cart_rules as $cart_rule) if ($with_shipping) $order_total_discount += Tools::ps_round($cart_rule['obj']->getContextualValue($with_taxes, $virtual_context, CartRule::FILTER_ACTION_ALL), 2);