diff --git a/classes/Cart.php b/classes/Cart.php index ff03ac047..5e15b6e53 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -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']) { diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index 638882a21..cee94f8b0 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -72,6 +72,8 @@ class CartControllerCore extends FrontController $this->processDeleteProductInCart(); else if(Tools::getIsset('changeAddressDelivery')) $this->processChangeProductAddressDelivery(); + else if(Tools::getIsset('allowSeperatedPackage')) + $this->processAllowSeperatedPackage(); else if(Tools::getIsset('duplicate')) $this->processDuplicateProduct(); @@ -124,6 +126,16 @@ class CartControllerCore extends FrontController $old_id_address_delivery, $new_id_address_delivery); } + + protected function processAllowSeperatedPackage() + { + if (Tools::getValue('value') === false) + die('{"error":true, "error_message": "No value setted"}'); + + $this->context->cart->allow_seperated_package = (boolean)Tools::getValue('value'); + $this->context->cart->update(); + die('{"error":false}'); + } protected function processDuplicateProduct() { diff --git a/themes/prestashop/js/cart-summary.js b/themes/prestashop/js/cart-summary.js index a7b1a7488..078cd5cda 100644 --- a/themes/prestashop/js/cart-summary.js +++ b/themes/prestashop/js/cart-summary.js @@ -623,4 +623,20 @@ $(document).ready(function() { $(this).parent().parent().find('.delivery_option_carrier').hide(); $(this).parent().find('.delivery_option_carrier').show(); }); + + $('#allow_seperated_package').live('click', function() { + $.ajax({ + type: 'GET', + url: baseDir, + async: true, + cache: false, + data: 'controller=cart&ajax=true&allowSeperatedPackage&value=' + +($(this).attr('checked') ? '1' : '0') + +'&token='+static_token, + success: function(jsonData) + { + getCarrierListAndUpdate(); + } + }); + }); }); \ No newline at end of file diff --git a/themes/prestashop/shopping-cart.tpl b/themes/prestashop/shopping-cart.tpl index d8466c445..81498314d 100644 --- a/themes/prestashop/shopping-cart.tpl +++ b/themes/prestashop/shopping-cart.tpl @@ -312,6 +312,10 @@ {/foreach} {/if} +
+ allow_seperated_package}checked="checked"{/if} /> + +