// Add "Allow seperated package" checkbox on the cart
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10698 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+30
-6
@@ -1085,8 +1085,12 @@ class CartCore extends ObjectModel
|
|||||||
* );
|
* );
|
||||||
* @todo Add avaibility check
|
* @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();
|
$product_list = $this->getProducts();
|
||||||
// Step 1 : Get product informations (warehouse_list and carrier_list), count warehouse
|
// Step 1 : Get product informations (warehouse_list and carrier_list), count warehouse
|
||||||
// Determine the best warehouse to determine the packages
|
// Determine the best warehouse to determine the packages
|
||||||
@@ -1174,7 +1178,7 @@ class CartCore extends ObjectModel
|
|||||||
if (!$this->allow_seperated_package)
|
if (!$this->allow_seperated_package)
|
||||||
$key = 'in_stock';
|
$key = 'in_stock';
|
||||||
else
|
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);
|
$product['carrier_list'] = Carrier::getAvailableCarrierList($product, $id_warehouse);
|
||||||
|
|
||||||
@@ -1291,6 +1295,7 @@ class CartCore extends ObjectModel
|
|||||||
'id_warehouse' => $id_warehouse,
|
'id_warehouse' => $id_warehouse,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
$cache = $final_package_list;
|
||||||
return $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();
|
$delivery_option_list = array();
|
||||||
$carriers_price = array();
|
$carriers_price = array();
|
||||||
$carrier_collection = 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;
|
$delivery_option_list[$id_address][$key]['total_price_without_tax'] = $total_price_without_tax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$cache = $delivery_option_list;
|
||||||
return $delivery_option_list;
|
return $delivery_option_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1548,12 +1558,26 @@ class CartCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public function getDeliveryOption($default_country = null)
|
public function getDeliveryOption($default_country = null)
|
||||||
{
|
{
|
||||||
|
$delivery_option_list = $this->getDeliveryOptionList($default_country);
|
||||||
|
|
||||||
// The delivery option was selected
|
// The delivery option was selected
|
||||||
if (isset($this->delivery_option) && $this->delivery_option != '')
|
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();
|
$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)
|
foreach ($options as $key => $option)
|
||||||
if ($option['is_best_price'])
|
if ($option['is_best_price'])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ class CartControllerCore extends FrontController
|
|||||||
$this->processDeleteProductInCart();
|
$this->processDeleteProductInCart();
|
||||||
else if(Tools::getIsset('changeAddressDelivery'))
|
else if(Tools::getIsset('changeAddressDelivery'))
|
||||||
$this->processChangeProductAddressDelivery();
|
$this->processChangeProductAddressDelivery();
|
||||||
|
else if(Tools::getIsset('allowSeperatedPackage'))
|
||||||
|
$this->processAllowSeperatedPackage();
|
||||||
else if(Tools::getIsset('duplicate'))
|
else if(Tools::getIsset('duplicate'))
|
||||||
$this->processDuplicateProduct();
|
$this->processDuplicateProduct();
|
||||||
|
|
||||||
@@ -125,6 +127,16 @@ class CartControllerCore extends FrontController
|
|||||||
$new_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()
|
protected function processDuplicateProduct()
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -623,4 +623,20 @@ $(document).ready(function() {
|
|||||||
$(this).parent().parent().find('.delivery_option_carrier').hide();
|
$(this).parent().parent().find('.delivery_option_carrier').hide();
|
||||||
$(this).parent().find('.delivery_option_carrier').show();
|
$(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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -312,6 +312,10 @@
|
|||||||
{/foreach}
|
{/foreach}
|
||||||
</ul>
|
</ul>
|
||||||
{/if}
|
{/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">
|
<form action="{if $opc}{$link->getPageLink('order-opc', true)}{else}{$link->getPageLink('order', true)}{/if}" method="post" id="voucher">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<h4>{l s='Vouchers'}</h4>
|
<h4>{l s='Vouchers'}</h4>
|
||||||
|
|||||||
Reference in New Issue
Block a user