// Add "Allow seperated package" checkbox on the cart

This commit is contained in:
mDeflotte
2011-11-28 10:50:54 +00:00
parent e00d70b932
commit 26acff7c7b
4 changed files with 62 additions and 6 deletions
+30 -6
View File
@@ -1085,8 +1085,12 @@ class CartCore extends ObjectModel
* );
* @todo Add avaibility check
*/
public function getPackageList()
public function getPackageList($flush = false)
{
static $cache = false;
if ($cache !== false && !$flush)
return $cache;
$product_list = $this->getProducts();
// Step 1 : Get product informations (warehouse_list and carrier_list), count warehouse
// Determine the best warehouse to determine the packages
@@ -1174,7 +1178,7 @@ class CartCore extends ObjectModel
if (!$this->allow_seperated_package)
$key = 'in_stock';
else
$key = ($product['in_stock']) ? 'in_stock' : 'out_of_stock';
$key = (!$product['out_of_stock']) ? 'in_stock' : 'out_of_stock';
$product['carrier_list'] = Carrier::getAvailableCarrierList($product, $id_warehouse);
@@ -1291,6 +1295,7 @@ class CartCore extends ObjectModel
'id_warehouse' => $id_warehouse,
);
}
$cache = $final_package_list;
return $final_package_list;
}
@@ -1321,8 +1326,12 @@ class CartCore extends ObjectModel
* ),
* );
*/
public function getDeliveryOptionList(Country $default_country = null)
public function getDeliveryOptionList(Country $default_country = null, $flush = false)
{
static $cache = false;
if ($cache !== false && !$flush)
return $cache;
$delivery_option_list = array();
$carriers_price = array();
$carrier_collection = array();
@@ -1482,6 +1491,7 @@ class CartCore extends ObjectModel
$delivery_option_list[$id_address][$key]['total_price_without_tax'] = $total_price_without_tax;
}
}
$cache = $delivery_option_list;
return $delivery_option_list;
}
@@ -1548,12 +1558,26 @@ class CartCore extends ObjectModel
*/
public function getDeliveryOption($default_country = null)
{
$delivery_option_list = $this->getDeliveryOptionList($default_country);
// The delivery option was selected
if (isset($this->delivery_option) && $this->delivery_option != '')
return unserialize($this->delivery_option);
// The delivery option is not selected, get the better for all option
{
$delivery_option = unserialize($this->delivery_option);
$validated = true;
foreach ($delivery_option as $id_address => $key)
if (!isset($delivery_option_list[$id_address][$key]))
{
$validated = false;
break;
}
if ($validated)
return $delivery_option;
}
// No delivery option selected or delivery option selected is not valid, get the better for all options
$delivery_option = array();
foreach ($this->getDeliveryOptionList($default_country) as $id_address => $options)
foreach ($delivery_option_list as $id_address => $options)
foreach ($options as $key => $option)
if ($option['is_best_price'])
{