privilegedemarque/override/classes/order/OrderDeliveryDates.php

111 lines
2.8 KiB
PHP

<?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();
}
}
}
}