From b36947f364b20afe2ab4483d03a0bb8f736aec1d Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Mon, 6 Feb 2012 14:19:39 +0000 Subject: [PATCH] [-] BO : #PSTEST-661 - Fix bug with non-assigned context git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13029 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Cart.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index ff9d73026..fb658e3e2 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -294,11 +294,15 @@ class CartCore extends ObjectModel WHERE `id_cart` = '.(int)$this->id ); + // Define virtual context to prevent case where the cart is not the in the global context + $virtual_context = Context::getContext()->cloneContext(); + $virtual_context->cart = $this; + foreach ($result as &$row) { $row['obj'] = new CartRule($row['id_cart_rule'], (int)$this->id_lang); - $row['value_real'] = $row['obj']->getContextualValue(true); - $row['value_tax_exc'] = $row['obj']->getContextualValue(false); + $row['value_real'] = $row['obj']->getContextualValue(true, $virtual_context); + $row['value_tax_exc'] = $row['obj']->getContextualValue(false, $virtual_context); // Retro compatibility < 1.5.0.2 $row['id_discount'] = $row['id_cart_rule']; @@ -1201,6 +1205,10 @@ class CartCore extends ObjectModel Cart::ONLY_WRAPPING, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING ); + + // Define virtual context to prevent case where the cart is not the in the global context + $virtual_context = Context::getContext()->cloneContext(); + $virtual_context->cart = $this; if (!in_array($type, $array_type)) die(Tools::displayError()); @@ -1321,7 +1329,7 @@ class CartCore extends ObjectModel { $result = $this->getCartRules(); foreach ($result as $row) - $order_total_discount += Tools::ps_round($row['obj']->getContextualValue($with_taxes), 2); + $order_total_discount += Tools::ps_round($row['obj']->getContextualValue($with_taxes, $virtual_context), 2); $order_total_discount = min(Tools::ps_round($order_total_discount, 2), $wrapping_fees + $order_total_products + $shipping_fees); $order_total -= $order_total_discount;