// 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'])
{
+12
View File
@@ -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()
{
+16
View File
@@ -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();
}
});
});
});
+4
View File
@@ -312,6 +312,10 @@
{/foreach}
</ul>
{/if}
<p>
<input type="checkbox" name="allow_seperated_package" id="allow_seperated_package" {if $cart->allow_seperated_package}checked="checked"{/if} />
<label for="allow_seperated_package">{l s="allow seperated package"}</label>
</p>
<form action="{if $opc}{$link->getPageLink('order-opc', true)}{else}{$link->getPageLink('order', true)}{/if}" method="post" id="voucher">
<fieldset>
<h4>{l s='Vouchers'}</h4>