Merge branch 'ticket-deliveryDelay_product' into develop

This commit is contained in:
Marion Muszynski 2016-07-25 12:06:23 +02:00
commit c809342939
4 changed files with 40 additions and 13 deletions

View File

@ -46,6 +46,17 @@ if(!class_exists('BusinessDaysCalculator')) {
}
}
public function addDaysWithCheckLastDay($howManyDays) {
$i = 0;
while ($i < $howManyDays) {
$this->date->modify("+1 day");
$i++;
}
if (!$this->isBusinessDay($this->date)) {
$this->date->modify("+1 day");
}
}
public function getDate() {
return $this->date;
}

View File

@ -45,7 +45,7 @@ if (!class_exists('SaleDelay')) {
return $products_final;
}
public static function getDeliveryDate(array $delays, $id_lang = null, $date_calcul = null)
public static function getDeliveryDate(array $delays, $id_lang = null, $date_calcul = null, $include_we =false)
{
global $cookie;
if (!$date_calcul) {
@ -62,28 +62,38 @@ if (!class_exists('SaleDelay')) {
foreach ($delays as $key => $delay) {
if (!in_array($delay, array_keys($delivery_date))) {
$delivery_date[$delay] = self::getDayDelay($delay, $cookie->id_lang);
$delivery_date[$delay]['date_start'] = self::getDateWithDelay((int)$delivery_date[$delay]['value'], $date_calcul);
$delivery_date[$delay]['date_start'] = self::getDateWithDelay((int)$delivery_date[$delay]['value'], $date_calcul, $include_we);
// exception noel
if ($delay == 5) {
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value'], $date_calcul);
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value'], $date_calcul, $include_we);
} else {
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value_max'], $date_calcul);
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value_max'], $date_calcul, $include_we);
}
}
}
return $delivery_date;
}
public static function getDateWithDelay($nb_day, $date)
public static function getDateWithDelay($nb_day, $date, $include_we = false)
{
$calculator = new BusinessDaysCalculator(
new DateTime($date->format('Y-m-d H:i:s')),
array(),
[BusinessDaysCalculator::SATURDAY, BusinessDaysCalculator::SUNDAY]
);
$calculator->addBusinessDays($nb_day);
if ($include_we) {
$calculator = new BusinessDaysCalculator(
new DateTime($date->format('Y-m-d H:i:s')),
array(),
[BusinessDaysCalculator::SUNDAY]
);
$calculator->addDaysWithCheckLastDay($nb_day);
} else {
$calculator = new BusinessDaysCalculator(
new DateTime($date->format('Y-m-d H:i:s')),
array(),
[BusinessDaysCalculator::SATURDAY, BusinessDaysCalculator::SUNDAY]
);
$calculator->addBusinessDays($nb_day);
}
return $calculator->getDate();
}

View File

@ -19,7 +19,7 @@ class ProductController extends ProductControllerCore {
require_once _PS_ROOT_DIR_.'/modules/privatesales_delay/saledelay.php';
}
$date = new DateTime();
$delivery_date = SaleDelay::getDeliveryDate(array($sale->delivery_delay), null, $date);
$delivery_date = SaleDelay::getDeliveryDate(array($sale->delivery_delay), null, $date, true);
}
}

View File

@ -488,10 +488,16 @@ var oneQuantityAvailableSentence = '{l s='Warning: 1 item in stock!' js=1}';
</div>
{if isset($delivery_date)}
<div class="delivery-delay-estimation">
{foreach from=$delivery_date item=date}
{foreach from=$delivery_date key=key item=date}
{if $key == 1}
<p>
<b>{$date.name}</b> : {l s='Date de réception prévue entre le'} <strong>{$date.date_start|date_format:'%d/%m/%Y'}</strong> {l s='et le'} <strong>{$date.date_end|date_format:'%d/%m/%Y'}</strong>
</p>
{elseif $key == 5}
<p>
<b>{$date.name}</b> : {l s='Livraison prévue avant le'} <strong>{l s='24/12'}</strong>
</p>
{/if}
{/foreach}
</div>
{/if}