Merge branch 'ticket/r12792-delivery-dates' into dev

This commit is contained in:
Rodney Figaro 2017-04-10 18:06:46 +02:00
commit 6825c72301
4 changed files with 180 additions and 36 deletions

View File

@ -675,7 +675,7 @@ abstract class PaymentModule extends PaymentModuleCore
PrestaShopLogger::addLog('PaymentModule::validateOrder - Mail is about to be sent', 1, null, 'Cart', (int)$id_cart, true);
// antadis 12792
$str = $this->getFormatDeliveryDates($order->id_lang);
$str = $this->getFormatDeliveryDates($order->id, $order->id_lang);
$data['{delivery_dates_block_html}'] = $str['html'];
$data['{delivery_dates_block_txt}'] = $str['txt'];
@ -734,35 +734,34 @@ abstract class PaymentModule extends PaymentModuleCore
}
}
private function getFormatDeliveryDates($id_lang)
private function getFormatDeliveryDates($id_order, $id_lang)
{
$str = array('html' => '-', 'txt' => '-');
// antadis 12792
if ($this->context->cart) {
$delivery_dates = SaleCore::getDeliveryRangeDates($this->context->cart);
if (is_array($delivery_dates)) {
if ($id_lang == '1') {
$str['html'] = 'entre le <strong>'.$delivery_dates['start']->format('d/m/Y').'</strong> et le <strong>'.$delivery_dates['end']->format('d/m/Y').'</strong>';
$str['txt'] = 'entre le '.$delivery_dates['start']->format('d/m/Y').' et le '.$delivery_dates['end']->format('d/m/Y');
}
else {
$str['html'] = 'between <strong>'.$delivery_dates['start']->format('d/m/Y').'</strong> and <strong>'.$delivery_dates['end']->format('d/m/Y').'</strong>';
$str['txt'] = 'between '.$delivery_dates['start']->format('d/m/Y').' and '.$delivery_dates['end']->format('d/m/Y');
}
}
elseif ($delivery_dates === SaleCore::DATE_RANGE_OTHER_DELAY) {
$other_delay = $this->context->cart->checkProductOtherDeliveryDelai(true);
$delivery_dates = OrderDeliveryDates::getDeliveryRangeDates($id_order, $id_lang);
if ($id_lang == '1') {
$str['html'] = 'sous <strong>'.$other_delay.'</strong>';
$str['txt'] = 'sous '.$other_delay;
}
else {
$str['html'] = 'within <strong>'.$other_delay.'</strong>';
$str['txt'] = 'within '.$other_delay;
}
if (is_array($delivery_dates)) {
if ($id_lang == '1') {
$str['html'] = 'entre le <strong>'.$delivery_dates['start']->format('d/m/Y').'</strong> et le <strong>'.$delivery_dates['end']->format('d/m/Y').'</strong>';
$str['txt'] = 'entre le '.$delivery_dates['start']->format('d/m/Y').' et le '.$delivery_dates['end']->format('d/m/Y');
}
else {
$str['html'] = 'between <strong>'.$delivery_dates['start']->format('d/m/Y').'</strong> and <strong>'.$delivery_dates['end']->format('d/m/Y').'</strong>';
$str['txt'] = 'between '.$delivery_dates['start']->format('d/m/Y').' and '.$delivery_dates['end']->format('d/m/Y');
}
}
elseif (!empty($delivery_dates)) {
$other_delay = $delivery_dates;
if ($id_lang == '1') {
$str['html'] = 'sous <strong>'.$other_delay.'</strong>';
$str['txt'] = 'sous '.$other_delay;
}
else {
$str['html'] = 'within <strong>'.$other_delay.'</strong>';
$str['txt'] = 'within '.$other_delay;
}
}

View File

@ -0,0 +1,111 @@
<?php
/**
* Description of OrderDeliveryDates
*
* @company Antadis
*/
class OrderDeliveryDates extends ObjectModel
{
public $id_order_delivery_dates;
public $id_order;
public $date_start;
public $date_end;
public $otherdelay_title;
/**
*
* @var type
*/
public static $definition = array(
'table' => 'order_delivery_dates',
'primary' => 'id_order_delivery_dates',
'multilang' => true,
'fields' => array(
'id_order' => array(
'type' => ObjectModel::TYPE_INT,
'required' => TRUE,
'validate' => 'isInt'
),
'date_start' => array(
'type' => ObjectModel::TYPE_DATE,
'validate' => 'isDateFormat'
),
'date_end' => array(
'type' => ObjectModel::TYPE_DATE,
'validate' => 'isDateFormat'
),
'otherdelay_title' => array(
'type' => ObjectModel::TYPE_STRING,
'lang' => true,
'validate' => 'isString'
),
)
);
/**
*
*/
public function __construct($id = null, $id_lang = null, $id_shop = null)
{
parent::__construct($id, $id_lang, $id_shop);
}
/**
* Antadis 12792
* Compute and return a period of dates of delivery for the current cart.
* These dates are based on the farthest sales delivery dates of all products
* @return DatePeriod : the period of dates of delivery for this cart
* or SaleCore::DATE_RANGE_* constant
*/
public static function getDeliveryRangeDates($id_order, $id_lang)
{
$id_order_delivery_dates = Db::getInstance()->getValue(
'SELECT `id_order_delivery_dates`
FROM `'._DB_PREFIX_.'order_delivery_dates`
WHERE `id_order` = '.(int)$id_order
);
if ($id_order_delivery_dates === false || empty($id_order_delivery_dates)) {
return '';
}
$obj = new self($id_order_delivery_dates);
if (!Validate::isLoadedObject($obj)) {
return '';
}
if (empty($obj->date_start) || $obj->date_start=='0000-00-00 00:00:00' ||
empty($obj->date_end) || $obj->date_end=='0000-00-00 00:00:00') {
return isset($obj->otherdelay_title[$id_lang]) ? trim($obj->otherdelay_title[$id_lang]) : '';
}
return array(
'start'=> new DateTime($obj->date_start),
'end' => new DateTime($obj->date_end)
);
}
public static function addOnPaymentAccepted($id_order)
{
$order = new Order($id_order);
if (Validate::isLoadedObject($order)) {
$cart = new Cart($order->id_cart);
if (Validate::isLoadedObject($cart)) {
$range_dates = SaleCore::getDeliveryRangeDates($cart);
$obj = new self();
$obj->id_order = $id_order;
if (is_array($range_dates)) {
$obj->date_start = $range_dates['start']->format('Y-m-d');
$obj->date_end = $range_dates['end']->format('Y-m-d');
}
elseif ($range_dates == SaleCore::DATE_RANGE_OTHER_DELAY) {
$obj->otherdelay_title = $cart->checkProductOtherDeliveryDelai(true);
}
$ret = $obj->add();
}
}
}
}

View File

@ -0,0 +1,38 @@
<?php
/*
* 2007-2014 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2014 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class OrderHistory extends OrderHistoryCore
{
public function add($autodate = true, $null_values = false)
{
$res = parent::add($autodate, $null_values);
if (in_array($this->id_order_state, array(Configuration::get('PS_OS_PAYMENT'), Configuration::get('PS_OS_WS_PAYMENT')))) {
OrderDeliveryDates::addOnPaymentAccepted($this->id_order);
}
return $res;
}
}

View File

@ -52,17 +52,13 @@ class HistoryController extends HistoryControllerCore
}
if ($order['virtual'] == false && in_array($order['current_state'], $states_for_delivery_dates)) {
$cart = new Cart($order['id_cart']);
if (Validate::isLoadedObject($cart)) {
$delivery_dates = SaleCore::getDeliveryRangeDates($cart);
if (is_array($delivery_dates)) {
$order['delivery_date_start'] = $delivery_dates['start']->getTimestamp();
$order['delivery_date_end'] = $delivery_dates['end']->getTimestamp();
}
elseif ($delivery_dates === SaleCore::DATE_RANGE_OTHER_DELAY) {
$order['other_delay'] = $cart->checkProductOtherDeliveryDelai(true);
}
$delivery_dates = OrderDeliveryDates::getDeliveryRangeDates($order['id_order'], $this->context->language->id);
if (is_array($delivery_dates)) {
$order['delivery_date_start'] = $delivery_dates['start']->getTimestamp();
$order['delivery_date_end'] = $delivery_dates['end']->getTimestamp();
}
elseif (!empty($delivery_dates)) {
$order['other_delay'] = $delivery_dates;
}
}
}