// Retrocompatibility : Now old 1.4 template works with new chechout process. Multishipping cannot be enabled.

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10948 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
mDeflotte
2011-12-05 17:11:26 +00:00
parent 07420a2c0d
commit 31e90d9031
5 changed files with 145 additions and 12 deletions
+99 -2
View File
@@ -1580,6 +1580,7 @@ class CartCore extends ObjectModel
/**
* Get all deliveries options available for the current cart
* @param Country $default_country
* @param boolean $flush Force flushing cache
*
* @return array array(
* 0 => array( // First address
@@ -1598,8 +1599,9 @@ class CartCore extends ObjectModel
* ),
* is_best_grade => true, // Does this option have the biggest grade (quick shipping) for this shipping address
* is_best_price => true, // Does this option have the lower price for this shipping address
* price_with_tax => 12.5,
* price_without_tax => 12.5,
* unique_carrier => true, // Does this option use a unique carrier
* total_price_with_tax => 12.5,
* total_price_without_tax => 12.5,
* ),
* ),
* );
@@ -1784,6 +1786,101 @@ class CartCore extends ObjectModel
$cache = $delivery_option_list;
return $delivery_option_list;
}
/**
* Get all deliveries options available for the current cart formated like Carriers::getCarriersForOrder
* This method was wrote for retrocompatibility with 1.4 theme
* New theme need to use Cart::getDeliveryOptionList() to generate carriers option in the checkout process
*
* @since 1.5.0
*
* @param Country $default_country
* @param boolean $flush Force flushing cache
*
*/
public function simulateCarriersOutput(Country $default_country = null, $flush = false)
{
static $cache = false;
if ($cache !== false && !$flush)
return $cache;
$delivery_option_list = $this->getDeliveryOptionList($default_country, $flush);
// This method cannot work if there is multiple address delivery
if (count($delivery_option_list) > 1 || empty($delivery_option_list))
return array();
$carriers = array();
foreach (reset($delivery_option_list) as $key => $option)
{
$price = $option['total_price_with_tax'];
$price_tax_exc = $option['total_price_without_tax'];
if ($option['unique_carrier'])
{
$carrier = reset($option['carrier_list']);
$name = $carrier['instance']->name;
$img = $carrier['logo'];
$delay = $carrier['instance']->delay;
}
else
{
$nameList = array();
foreach ($option['carrier_list'] as $carrier)
$nameList[] = $carrier['instance']->name;
$name = join(' -' , $nameList);
$img = ''; // No images if multiple carriers
$delay = '';
}
$carriers[] = array(
'name' => $name,
'img' => $img,
'delay' => $delay[Context::getContext()->language->id],
'price' => $price,
'price_tax_exc' => $price_tax_exc,
'id_carrier' => self::intifier($key), // Need to translate to an integer for retrocompatibility reason, in 1.4 template we used intval
'is_module' => false,
);
}
return $carriers;
}
public function simulateCarrierSelectedOutput()
{
$delivery_option = $this->getDeliveryOption();
if (count($delivery_option) > 1 || empty($delivery_option))
return 0;
return self::intifier(reset($delivery_option));
}
/**
* Translate a string option_delivery identifier ('24,3,') in a int (3240002000)
*
* The option_delivery identifier is a list of integers separated by a ','.
* This method replace the delimiter by a sequence of '0'.
* The size of this sequence is fixed by the first digit of the return
*
* @return int
*/
public static function intifier($string, $delimiter = ',')
{
$elm = explode($delimiter, $string);
$max = max($elm);
return strlen($max).join(str_repeat('0', strlen($max)+1), $elm);
}
/**
* Translate a int option_delivery identifier (3240002000) in a string ('24,3,')
*/
public static function desintifier($int, $delimiter = ',')
{
$delimiter_len = $int[0];
$int = substr($int, 1);
$elm = explode(str_repeat('0',$delimiter_len+1), $int);
return join($delimiter, $elm);
}
/**
* Does the cart use multiple address
+1 -2
View File
@@ -268,8 +268,7 @@ class CartControllerCore extends FrontController
if ($this->context->cart->id_address_delivery)
$deliveryAddress = new Address($this->context->cart->id_address_delivery);
$id_country = (isset($deliveryAddress) && $deliveryAddress->id) ? $deliveryAddress->id_country : Configuration::get('PS_COUNTRY_DEFAULT');
$result['carriers'] = Carrier::getCarriersForOrder(Country::getIdZone($id_country), $groups);
//$result['checked'] = Carrier::getDefaultCarrierSelection($result['carriers'], (int)$this->cart->id_carrier);
$result['HOOK_EXTRACARRIER'] = Hook::exec('extraCarrier', array('address' => (isset($deliveryAddress) && (int)$deliveryAddress->id) ? $deliveryAddress : null));
}
$result['summary'] = $this->context->cart->getSummaryDetails();
+7 -4
View File
@@ -64,7 +64,7 @@ class OrderOpcControllerCore extends ParentOrderController
}
break;
case 'updateCarrierAndGetPayments':
if (Tools::isSubmit('delivery_option') AND Tools::isSubmit('recyclable') AND Tools::isSubmit('gift') AND Tools::isSubmit('gift_message'))
if ((Tools::isSubmit('delivery_option') || Tools::isSubmit('id_carrier')) AND Tools::isSubmit('recyclable') AND Tools::isSubmit('gift') AND Tools::isSubmit('gift_message'))
{
if ($this->_processCarrier())
{
@@ -358,11 +358,12 @@ class OrderOpcControllerCore extends ParentOrderController
{
if (!$this->isLogged)
{
$carriers = Carrier::getCarriersForOrder(Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT')));
$carriers = $this->context->cart->simulateCarriersOutput();
$this->context->smarty->assign(array(
'HOOK_EXTRACARRIER' => NULL,
'HOOK_BEFORECARRIER' => Hook::exec('beforeCarrier', array(
'carriers' => $carriers,
'checked' => $this->context->cart->simulateCarrierSelectedOutput(),
'delivery_option_list' => $this->context->cart->getDeliveryOptionList(),
'delivery_option' => $this->context->cart->getDeliveryOption()
))
@@ -432,6 +433,8 @@ class OrderOpcControllerCore extends ParentOrderController
else
$link_conditions .= '&content_only=1';
$carriers = $this->context->cart->simulateCarriersOutput();
$this->context->smarty->assign(array(
'checkedTOS' => (int)($this->context->cookie->checkedTOS),
'recyclablePackAllowed' => (int)(Configuration::get('PS_RECYCLABLE_PACK')),
@@ -442,6 +445,8 @@ class OrderOpcControllerCore extends ParentOrderController
'recyclable' => (int)($this->context->cart->recyclable),
'gift_wrapping_price' => (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')),
'delivery_option_list' => $this->context->cart->getDeliveryOptionList(),
'carriers' => $carriers,
'checked' => $this->context->cart->simulateCarrierSelectedOutput(),
'delivery_option' => $this->context->cart->getDeliveryOption(),
'address_collection' => $this->context->cart->getAddressCollection(),
'opc' => true));
@@ -456,8 +461,6 @@ class OrderOpcControllerCore extends ParentOrderController
$this->errors[] = Tools::displayError('This address is invalid.');
else
{
$carriers = Carrier::getCarriersForOrder((int)Address::getZoneById((int)($address_delivery->id)), $groups);
$result = array(
'HOOK_BEFORECARRIER' => Hook::exec('beforeCarrier', array(
'carriers' => $carriers,
+23 -4
View File
@@ -216,9 +216,25 @@ class ParentOrderControllerCore extends FrontController
}
else
$id_zone = Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT'));
if (Tools::getIsset('delivery_option') && $this->validateDeliveryOption(Tools::getValue('delivery_option')))
$this->context->cart->setDeliveryOption(Tools::getValue('delivery_option'));
if (Tools::getIsset('delivery_option'))
{
if ($this->validateDeliveryOption(Tools::getValue('delivery_option')))
$this->context->cart->setDeliveryOption(Tools::getValue('delivery_option'));
}
elseif (Tools::getIsset('id_carrier'))
{
// For retrocompatibility reason, try to transform carrier to an delivery option list
$delivery_option_list = $this->context->cart->getDeliveryOptionList();
if (count($delivery_option_list) == 1)
{
$delivery_option = reset($delivery_option_list);
$key = Cart::desintifier(Tools::getValue('id_carrier'));
foreach ($delivery_option_list as $id_address => $options)
if (isset($options[$key]))
$this->context->cart->setDeliveryOption(array($id_address => $key));
}
}
Hook::exec('processCarrier', array('cart' => $this->context->cart));
@@ -377,17 +393,20 @@ class ParentOrderControllerCore extends FrontController
{
$address = new Address($this->context->cart->id_address_delivery);
$id_zone = Address::getZoneById($address->id);
$carriers = Carrier::getCarriersForOrder($id_zone, $this->context->customer->getGroups());
$carriers = $this->context->cart->simulateCarriersOutput();
$this->context->smarty->assign(array(
'address_collection' => $this->context->cart->getAddressCollection(),
'delivery_option_list' => $this->context->cart->getDeliveryOptionList(),
'carriers' => $carriers,
'checked' => $this->context->cart->simulateCarrierSelectedOutput(),
'delivery_option' => $this->context->cart->getDeliveryOption()
));
$this->context->smarty->assign(array(
'HOOK_EXTRACARRIER' => Hook::exec('extraCarrier', array('address' => $address)),
'HOOK_BEFORECARRIER' => Hook::exec('beforeCarrier', array(
'carriers' => $carriers,
'checked' => $this->context->cart->simulateCarrierSelectedOutput(),
'delivery_option_list' => $this->context->cart->getDeliveryOptionList(),
'delivery_option' => $this->context->cart->getDeliveryOption()
))
+15
View File
@@ -224,3 +224,18 @@ function resizeAddressesBox(nameBox)
});
$(nameBox).height(maxHeight);
}
$(document).ready(function() {
$.fn.checkboxChange = function(fnChecked, fnUnchecked) {
if ($(this).attr('checked') && fnChecked)
fnChecked.call(this);
else if(fnUnchecked)
fnUnchecked.call(this);
if (!$(this).attr('eventCheckboxChange'))
{
$(this).live('change', function() { $(this).checkboxChange(fnChecked, fnUnchecked) });
$(this).attr('eventCheckboxChange', true);
}
}
});