From 8dc8455e78bd61ce34401a77afa1e6dbaf12de01 Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Tue, 7 Feb 2012 17:15:44 +0000 Subject: [PATCH] // fix bug with missing $context->cart and $context->customer durring payment process git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13089 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Carrier.php | 15 ++++++++++----- classes/Cart.php | 2 +- classes/PaymentModule.php | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/classes/Carrier.php b/classes/Carrier.php index f2876e756..56f24c079 100644 --- a/classes/Carrier.php +++ b/classes/Carrier.php @@ -504,11 +504,12 @@ class CarrierCore extends ObjectModel * @param Array $groups group of the customer * @return Array */ - public static function getCarriersForOrder($id_zone, $groups = null) + public static function getCarriersForOrder($id_zone, $groups = null, $cart = null) { $context = Context::getContext(); $id_lang = $context->language->id; - $cart = $context->cart; + if (is_null($cart)) + $cart = $context->cart; $id_currency = $context->currency->id; if (is_array($groups) && !empty($groups)) @@ -1023,10 +1024,13 @@ class CarrierCore extends ObjectModel * @param Product $product The id of the product, or an array with at least the package size and weight * @return array */ - public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null) + public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null, $cart = null) { if (is_null($id_shop)) $id_shop = Context::getContext()->shop->getID(true); + if (is_null($cart)) + $cart = Context::getContext()->cart; + // Does the product is linked with carriers? $query = new DbQuery(); @@ -1057,7 +1061,7 @@ class CarrierCore extends ObjectModel if (empty($carrier_list)) // No carriers defined, get all available carriers { $carrier_list = array(); - $id_address = (int)((!is_null($id_address_delivery) && $id_address_delivery != 0) ? $id_address_delivery : Context::getContext()->cart->id_address_delivery); + $id_address = (int)((!is_null($id_address_delivery) && $id_address_delivery != 0) ? $id_address_delivery : $cart->id_address_delivery); if ($id_address) { $address = new Address($id_address); @@ -1068,7 +1072,8 @@ class CarrierCore extends ObjectModel $country = new Country(Configuration::get('PS_COUNTRY_DEFAULT')); $id_zone = $country->id_zone; } - $carriers = Carrier::getCarriersForOrder($id_zone, Context::getContext()->customer->getGroups()); + $customer = new Customer($cart->id_customer); + $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups(), $cart); foreach ($carriers as $carrier) $carrier_list[] = $carrier['id_carrier']; } diff --git a/classes/Cart.php b/classes/Cart.php index fb658e3e2..d7d06e960 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1479,7 +1479,7 @@ class CartCore extends ObjectModel else $key = (!$product['out_of_stock']) ? 'in_stock' : 'out_of_stock'; - $product['carrier_list'] = Carrier::getAvailableCarrierList(new Product($product['id_product']), $id_warehouse, $product['id_address_delivery']); + $product['carrier_list'] = Carrier::getAvailableCarrierList(new Product($product['id_product']), $id_warehouse, $product['id_address_delivery'], null, $this); if (empty($product['carrier_list'])) $product['carrier_list'] = array(0); diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index e94ef9696..5a85cc3a7 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -87,6 +87,7 @@ abstract class PaymentModuleCore extends Module $secure_key = false, Shop $shop = null) { $cart = new Cart($id_cart); + $this->context->cart = $cart; if (!$shop) $shop = Context::getContext()->shop;