[-] FO: Fix Cart::getDeliveryOption() cache

This commit is contained in:
Rémi Gaillard
2013-02-11 16:59:16 +01:00
parent d2ce6050d2
commit cc15bf0243
+8 -7
View File
@@ -2322,11 +2322,12 @@ class CartCore extends ObjectModel
* Get the delivery option seleted, or if no delivery option was selected, the cheapest option for each address * Get the delivery option seleted, or if no delivery option was selected, the cheapest option for each address
* @return array delivery option * @return array delivery option
*/ */
public function getDeliveryOption($default_country = null, $dontAutoSeletectOptions = false, $use_cache = true) public function getDeliveryOption($default_country = null, $dontAutoSelectOptions = false, $use_cache = true)
{ {
static $cache = array(0 => false, 1 => false); static $cache = array();
if ($cache[(int)$dontAutoSeletectOptions] !== false && $use_cache) $cache_id = (int)$default_country.'-'.(int)$dontAutoSelectOptions;
return $cache[(int)$dontAutoSeletectOptions]; if (isset($cache[$cache_id]) && $use_cache)
return $cache[$cache_id];
$delivery_option_list = $this->getDeliveryOptionList($default_country); $delivery_option_list = $this->getDeliveryOptionList($default_country);
@@ -2344,12 +2345,12 @@ class CartCore extends ObjectModel
if ($validated) if ($validated)
{ {
$cache[(int)$dontAutoSeletectOptions] = $delivery_option; $cache[$cache_id] = $delivery_option;
return $delivery_option; return $delivery_option;
} }
} }
if ($dontAutoSeletectOptions) if ($dontAutoSelectOptions)
return false; return false;
// No delivery option selected or delivery option selected is not valid, get the better for all options // No delivery option selected or delivery option selected is not valid, get the better for all options
@@ -2378,7 +2379,7 @@ class CartCore extends ObjectModel
$delivery_option[$id_address] = key($options); $delivery_option[$id_address] = key($options);
} }
$cache[(int)$dontAutoSeletectOptions] = $delivery_option; $cache[$cache_id] = $delivery_option;
return $delivery_option; return $delivery_option;
} }