[-] FO : #PSCFV-2147 - Fix bug with date of delivery
This commit is contained in:
+17
-1
@@ -1473,7 +1473,23 @@ class CartCore extends ObjectModel
|
||||
|
||||
return Tools::ps_round((float)$order_total, 2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of packages
|
||||
*
|
||||
* @return int number of packages
|
||||
*/
|
||||
public function getNbOfPackages()
|
||||
{
|
||||
static $nb_packages = 0;
|
||||
|
||||
if (!$nb_packages)
|
||||
foreach ($this->getPackageList() as $by_address)
|
||||
$nb_packages += count($by_address);
|
||||
|
||||
return $nb_packages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get products grouped by package and by addresses to be sent individualy (one package = one shipping cost).
|
||||
*
|
||||
|
||||
@@ -27,41 +27,66 @@
|
||||
{if $datesDelivery|count}
|
||||
<script type="text/javascript">
|
||||
{literal}
|
||||
var datesDelivery = new Array();
|
||||
var datesDelivery = {};
|
||||
{/literal}
|
||||
{foreach from=$datesDelivery item=date key=k}
|
||||
{if $date}
|
||||
datesDelivery[{$k}] = new Array();
|
||||
datesDelivery[{$k}]['minimal'] = "{$date.0}";
|
||||
datesDelivery[{$k}]['maximal'] = "{$date.1}";
|
||||
{/if}
|
||||
{foreach $datesDelivery as $by_address}
|
||||
datesDelivery[{$by_address@key}] = {};
|
||||
{foreach $by_address as $date}
|
||||
{if $date && isset($date[0])}
|
||||
datesDelivery[{$by_address@key}]["{$date@key}"] = {};
|
||||
datesDelivery[{$by_address@key}]["{$date@key}"]['minimal'] = ["{$date.0.0}",{$date.0.1}];
|
||||
datesDelivery[{$by_address@key}]["{$date@key}"]['maximal'] = ["{$date.1.0}",{$date.1.1}];
|
||||
{/if}
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
{literal}
|
||||
|
||||
$(function(){
|
||||
if (datesDelivery[{/literal}{$id_carrier}{literal}] != undefined)
|
||||
function refreshDateOfDelivery()
|
||||
{
|
||||
var date_from = null;
|
||||
var date_to = null;
|
||||
var set = true;
|
||||
$.each($('.delivery_option_radio:checked'), function()
|
||||
{
|
||||
$('span#minimal').html('<b>'+datesDelivery[{/literal}{$id_carrier}{literal}]['minimal']+'</b>');
|
||||
$('span#maximal').html('<b>'+datesDelivery[{/literal}{$id_carrier}{literal}]['maximal']+'</b>');
|
||||
var date = datesDelivery[$(this).attr('name').replace(/delivery_option\[(.*)\]/, '$1')][$(this).val()];
|
||||
if (typeof(date) != 'undefined')
|
||||
{
|
||||
if (date_from == null || date_from[1] < date['minimal'][1])
|
||||
date_from = date['minimal'];
|
||||
if (date_to == null || date_to[1] < date['maximal'][1])
|
||||
date_to = date['maximal'];
|
||||
}
|
||||
else
|
||||
set = false;
|
||||
});
|
||||
|
||||
if (date_from != null && date_to != null && set)
|
||||
{
|
||||
$('p#dateofdelivery').show();
|
||||
$('span#minimal').html('<b>'+date_from[0]+'</b>');
|
||||
$('span#maximal').html('<b>'+date_to[0]+'</b>');
|
||||
}
|
||||
else
|
||||
$('p#dateofdelivery').hide();
|
||||
|
||||
$('input[name=id_carrier]').click(function(){
|
||||
if (datesDelivery[$(this).val()] != undefined)
|
||||
{
|
||||
$('p#dateofdelivery').show();
|
||||
$('span#minimal').html('<b>'+datesDelivery[$(this).val()]['minimal']+'</b>');
|
||||
$('span#maximal').html('<b>'+datesDelivery[$(this).val()]['maximal']+'</b>');
|
||||
}
|
||||
else
|
||||
$('p#dateofdelivery').hide();
|
||||
}
|
||||
$(function(){
|
||||
refreshDateOfDelivery();
|
||||
$('input[name=id_carrier]').change(function(){
|
||||
refreshDateOfDelivery();
|
||||
});
|
||||
});
|
||||
{/literal}
|
||||
</script>
|
||||
|
||||
<br />
|
||||
<p id="dateofdelivery">{l s='Approximate date of delivery with this carrier is between' mod='dateofdelivery'} <span id="minimal"></span> {l s='and' mod='dateofdelivery'} <span id="maximal"></span> <sup>*</sup></p>
|
||||
<p style="font-size:10px;margin:0padding:0;"><sup>*</sup> {l s='with direct payment methods (e.g. credit card)' mod='dateofdelivery'}</p>
|
||||
<p id="dateofdelivery">
|
||||
{if $nbPackages <= 1}
|
||||
{l s='Approximate date of delivery with this carrier is between' mod='dateofdelivery'}
|
||||
{else}
|
||||
{l s='There are %s packages, that will be approximately delivered with the delivery option you choose between' sprintf=$nbPackages mod='dateofdelivery'}
|
||||
{/if}
|
||||
<span id="minimal"></span> {l s='and' mod='dateofdelivery'} <span id="maximal"></span> <sup>*</sup>
|
||||
<br />
|
||||
<span style="font-size:10px;margin:0padding:0;"><sup>*</sup> {l s='with direct payment methods (e.g. credit card)' mod='dateofdelivery'}
|
||||
</p>
|
||||
{/if}
|
||||
@@ -49,10 +49,10 @@ class DateOfDelivery extends Module
|
||||
public function install()
|
||||
{
|
||||
if (!parent::install()
|
||||
OR !$this->registerHook('beforeCarrier')
|
||||
OR !$this->registerHook('orderDetailDisplayed')
|
||||
OR !$this->registerHook('displayPDFInvoice'))
|
||||
return false;
|
||||
|| !$this->registerHook('beforeCarrier')
|
||||
|| !$this->registerHook('orderDetailDisplayed')
|
||||
||!$this->registerHook('displayPDFInvoice'))
|
||||
return false;
|
||||
|
||||
if (!Db::getInstance()->execute('
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'dateofdelivery_carrier_rule` (
|
||||
@@ -102,21 +102,54 @@ class DateOfDelivery extends Module
|
||||
|
||||
public function hookBeforeCarrier($params)
|
||||
{
|
||||
if (!sizeof($params['carriers']))
|
||||
if (!count($params['delivery_option_list']))
|
||||
return false;
|
||||
|
||||
$oos = false; // For out of stock management
|
||||
foreach ($params['cart']->getProducts() as $product)
|
||||
if ($product['stock_quantity'] <= 0 OR ($product['quantity_attribute'] <= 0 AND $product['id_product_attribute']))
|
||||
$oos = true;
|
||||
$package_list = $params['cart']->getPackageList();
|
||||
|
||||
$datesDelivery = array();
|
||||
foreach ($params['carriers'] as $carrier)
|
||||
$datesDelivery[(int)($carrier['id_carrier'])] = $this->_getDatesOfDelivery((int)($carrier['id_carrier']), $oos);
|
||||
foreach ($params['delivery_option_list'] as $id_address => $by_address)
|
||||
{
|
||||
$datesDelivery[$id_address] = array();
|
||||
foreach ($by_address as $key => $delivery_option)
|
||||
{
|
||||
$date_from = null;
|
||||
$date_to = null;
|
||||
$datesDelivery[$id_address][$key] = array();
|
||||
|
||||
foreach ($delivery_option['carrier_list'] as $id_carrier => $carrier)
|
||||
{
|
||||
foreach ($carrier['package_list'] as $id_package)
|
||||
{
|
||||
$package = $package_list[$id_address][$id_package];
|
||||
$oos = false; // For out of stock management
|
||||
foreach ($package['product_list'] as $product)
|
||||
if (StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']) <= 0)
|
||||
{
|
||||
$oos = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$date_range = $this->_getDatesOfDelivery($id_carrier, $oos);
|
||||
if (is_null($date_from) || $date_from < $date_range[0])
|
||||
{
|
||||
$date_from = $date_range[0][1];
|
||||
$datesDelivery[$id_address][$key][0] = $date_range[0];
|
||||
}
|
||||
if (is_null($date_to) || $date_to < $date_range[1])
|
||||
{
|
||||
$date_to = $date_range[1][1];
|
||||
$datesDelivery[$id_address][$key][1] = $date_range[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->smarty->assign(array(
|
||||
'nbPackages' => $params['cart']->getNbOfPackages(),
|
||||
'datesDelivery' => $datesDelivery,
|
||||
'id_carrier' => ($params['cart']->id_carrier ? (int)($params['cart']->id_carrier) : (int)(Configuration::get('PS_CARRIER_DEFAULT')))
|
||||
'delivery_option' => $params['delivery_option']
|
||||
));
|
||||
|
||||
return $this->display(__FILE__, 'beforeCarrier.tpl');
|
||||
@@ -141,33 +174,33 @@ class DateOfDelivery extends Module
|
||||
return $this->display(__FILE__, 'orderDetail.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the delivery dates on the invoice
|
||||
*
|
||||
* @param $params contains an instance of OrderInvoice
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function hookDisplayPDFInvoice($params)
|
||||
{
|
||||
$order_invoice = $params['object'];
|
||||
if (!($order_invoice instanceof OrderInvoice))
|
||||
return;
|
||||
/**
|
||||
* Displays the delivery dates on the invoice
|
||||
*
|
||||
* @param $params contains an instance of OrderInvoice
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function hookDisplayPDFInvoice($params)
|
||||
{
|
||||
$order_invoice = $params['object'];
|
||||
if (!($order_invoice instanceof OrderInvoice))
|
||||
return;
|
||||
|
||||
$order = new Order((int)$order_invoice->id_order);
|
||||
$order = new Order((int)$order_invoice->id_order);
|
||||
|
||||
$oos = false; // For out of stock management
|
||||
foreach ($order->getProducts() as $product)
|
||||
if ($product['product_quantity_in_stock'] < 1)
|
||||
$oos = true;
|
||||
$oos = false; // For out of stock management
|
||||
foreach ($order->getProducts() as $product)
|
||||
if ($product['product_quantity_in_stock'] < 1)
|
||||
$oos = true;
|
||||
|
||||
$id_carrier = (int)OrderInvoice::getCarrierId($order_invoice->id);
|
||||
$return = '';
|
||||
if ($datesDelivery = $this->_getDatesOfDelivery($id_carrier, $oos, $order_invoice->date_add))
|
||||
$return = $this->l('Approximate date of delivery is between').' '.$datesDelivery[0].' '.$this->l('and').' '.$datesDelivery[1];
|
||||
$id_carrier = (int)OrderInvoice::getCarrierId($order_invoice->id);
|
||||
$return = '';
|
||||
if ($datesDelivery = $this->_getDatesOfDelivery($id_carrier, $oos, $order_invoice->date_add))
|
||||
$return = $this->l('Approximate date of delivery is between').' '.$datesDelivery[0].' '.$this->l('and').' '.$datesDelivery[1];
|
||||
|
||||
return $return;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function _postProcess()
|
||||
{
|
||||
@@ -460,13 +493,13 @@ class DateOfDelivery extends Module
|
||||
'.((int)$id_carrier_rule != 0 ? 'AND `id_carrier_rule` != '.(int)($id_carrier_rule) : ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id_carrier
|
||||
* @param bool $product_oos
|
||||
* @param null $date
|
||||
*
|
||||
* @return array|bool returns the min & max delivery date
|
||||
*/
|
||||
/**
|
||||
* @param $id_carrier
|
||||
* @param bool $product_oos
|
||||
* @param null $date
|
||||
*
|
||||
* @return array|bool returns the min & max delivery date
|
||||
*/
|
||||
private function _getDatesOfDelivery($id_carrier, $product_oos = false, $date = null)
|
||||
{
|
||||
if (!(int)($id_carrier))
|
||||
@@ -506,6 +539,9 @@ class DateOfDelivery extends Module
|
||||
$date_maximal_time += 24 * 3600;
|
||||
|
||||
/*
|
||||
|
||||
// Do not remove this commentary, it's usefull to allow translations of months and days in the translator tool
|
||||
|
||||
$this->l('Sunday');
|
||||
$this->l('Monday');
|
||||
$this->l('Tuesday');
|
||||
@@ -550,8 +586,14 @@ class DateOfDelivery extends Module
|
||||
}
|
||||
}
|
||||
return array(
|
||||
$date_minimal_string,
|
||||
$date_maximal_string
|
||||
array(
|
||||
$date_minimal_string,
|
||||
$date_minimal_time
|
||||
),
|
||||
array(
|
||||
$date_maximal_string,
|
||||
$date_maximal_time
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['<{dateofdelivery}prestashop>beforecarrier_75261aaef97717dda0ca98743b24f8f3'] = 'La date approximative de livraison avec ce transporteur se situe entre le';
|
||||
$_MODULE['<{dateofdelivery}prestashop>beforecarrier_c31e7bcb78c69bd37e6e77be0183567f'] = 'Il y\'a %s paquets, qui seront livré approximativement entre le ';
|
||||
$_MODULE['<{dateofdelivery}prestashop>beforecarrier_be5d5d37542d75f93a87094459f76678'] = 'et le ';
|
||||
$_MODULE['<{dateofdelivery}prestashop>beforecarrier_c9ed8c0b07828727ca6653924b0498d3'] = 'avec un moyen de paiement direct (ex. : carte bancaire)';
|
||||
$_MODULE['<{dateofdelivery}prestashop>dateofdelivery_b0f76e26cffaf27784d901a64f39593e'] = 'Date de livraison';
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
<div class="delivery_options">
|
||||
{foreach $option_list as $key => $option}
|
||||
<div class="delivery_option {if ($option@index % 2)}alternate_{/if}item">
|
||||
<input class="delivery_option_radio" type="radio" name="delivery_option[{$id_address}]" onchange="{if $opc}updateCarrierSelectionAndGift();{else}updateExtraCarrier('{$key}', {$id_address});{/if}" id="delivery_option_{$id_address}_{$option@index}" value="{$key}" {if $delivery_option[$id_address] == $key}checked="checked"{/if} />
|
||||
<input class="delivery_option_radio" type="radio" name="delivery_option[{$id_address}]" onchange="{if $opc}updateCarrierSelectionAndGift();{else}updateExtraCarrier('{$key}', {$id_address});{/if}" id="delivery_option_{$id_address}_{$option@index}" value="{$key}" {if isset($delivery_option[$id_address]) && $delivery_option[$id_address] == $key}checked="checked"{/if} />
|
||||
<label for="delivery_option_{$id_address}_{$option@index}">
|
||||
<table class="resume">
|
||||
<tr>
|
||||
|
||||
Reference in New Issue
Block a user