From d0511c32113c0512e2dce3e2ce28d33fda4cd1a9 Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Thu, 22 Dec 2011 17:37:27 +0000 Subject: [PATCH] // Improving method getAvailableCarrierList git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11648 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Carrier.php | 13 +++---------- classes/Cart.php | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/classes/Carrier.php b/classes/Carrier.php index c6e0cf4b2..a0a49466c 100644 --- a/classes/Carrier.php +++ b/classes/Carrier.php @@ -1020,18 +1020,11 @@ class CarrierCore extends ObjectModel * For a given {product, warehouse}, gets the carrier available * * @since 1.5.0 - * @param $product integer The id of the product, or an array with at least the package size and weight + * @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, $id_warehouse, $id_shop = null) + public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null) { - if (is_numeric($product)) - $product = new Product((int)$product); - else if (is_array($product)) - { - $product['id'] = $product['id_product']; - $product = (object)$product; - } if (is_null($id_shop)) $id_shop = Context::getContext()->shop->getID(true); @@ -1065,7 +1058,7 @@ class CarrierCore extends ObjectModel if (empty($carrier_list)) // No carriers defined, get all available carriers { $carrier_list = array(); - $id_address = ((isset($product->id_address_delivery) && $product->id_address_delivery != 0) ? $product->id_address_delivery : Context::getContext()->cart->id_address_delivery); + $id_address = (!is_null($id_address_delivery) && $id_address_delivery != 0) ? $id_address_delivery : Context::getContext()->cart->id_address_delivery; $address = new Address($id_address); $id_zone = Address::getZoneById($address->id); $carriers = Carrier::getCarriersForOrder($id_zone, Context::getContext()->customer->getGroups()); diff --git a/classes/Cart.php b/classes/Cart.php index 95c4cb53f..0ba81547a 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1459,7 +1459,7 @@ class CartCore extends ObjectModel else $key = (!$product['out_of_stock']) ? 'in_stock' : 'out_of_stock'; - $product['carrier_list'] = Carrier::getAvailableCarrierList($product, $id_warehouse); + $product['carrier_list'] = Carrier::getAvailableCarrierList(new Product($product['id_product']), $id_warehouse, $product['id_address_delivery']); if (empty($product['carrier_list'])) $product['carrier_list'] = array(0);