Files
2024-10-25 14:16:28 +02:00

130 lines
7.0 KiB
PHP

<?php
class Order extends OrderCore
{
public $order_source;
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'orders',
'primary' => 'id_order',
'fields' => array(
'id_address_delivery' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_address_invoice' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_cart' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_shop_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'current_state' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5'),
'payment' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true),
'module' => array('type' => self::TYPE_STRING, 'validate' => 'isModuleName', 'required' => true),
'recyclable' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'gift' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'gift_message' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage'),
'mobile_theme' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'total_discounts' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'total_discounts_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'total_discounts_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'total_paid' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
'total_paid_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'total_paid_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'total_paid_real' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
'total_products' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
'total_products_wt' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
'total_shipping' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'total_shipping_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'total_shipping_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'carrier_tax_rate' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
'total_wrapping' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'total_wrapping_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'total_wrapping_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
'round_mode' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'round_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'shipping_number' => array('type' => self::TYPE_STRING, 'validate' => 'isTrackingNumber'),
'conversion_rate' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true),
'invoice_number' => array('type' => self::TYPE_INT),
'delivery_number' => array('type' => self::TYPE_INT),
'invoice_date' => array('type' => self::TYPE_DATE),
'delivery_date' => array('type' => self::TYPE_DATE),
'valid' => array('type' => self::TYPE_BOOL),
'reference' => array('type' => self::TYPE_STRING),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'order_source' => array('type' => self::TYPE_STRING),
),
);
/*
* module: modrefchange
* date: 2019-04-12 06:23:14
* version: 1.5.5.1
*/
public function add($autodate = true, $null_values = true)
{
$cart = new Cart($this->id_cart);
Hook::exec('actionBeforeAddOrder', array('order'=>$this,'cart'=>$cart));
if (ObjectModel::add($autodate, $null_values))
return SpecificPrice::deleteByIdCart($this->id_cart);
return false;
}
/*
* module: modrefchange
* date: 2019-04-12 06:23:14
* version: 1.5.5.1
*/
public static function setLastInvoiceNumber($order_invoice_id, $id_shop)
{
if (!$order_invoice_id)
return false;
$number = Configuration::get('PS_INVOICE_START_NUMBER', null, null, $id_shop);
if ($number)
Configuration::updateValue('PS_INVOICE_START_NUMBER', false, false, null, $id_shop);
$order_invoice = new OrderInvoice($order_invoice_id);
$order = new Order($order_invoice->id_order);
$cart = new Cart($order->id_cart);
if($ref = Hook::exec('actionBeforeAddOrderInvoice', array('order_invoice'=>$order_invoice,'order'=>$order,'cart'=>$cart)))
$number = $ref;
$sql = 'UPDATE `'._DB_PREFIX_.'order_invoice` SET number =';
if ($number)
$sql .= (int)$number;
else
$sql .= '(SELECT new_number FROM (SELECT (MAX(`number`) + 1) AS new_number
FROM `'._DB_PREFIX_.'order_invoice`) AS result)';
$sql .=' WHERE `id_order_invoice` = '.(int)$order_invoice_id;
return Db::getInstance()->execute($sql);
}
/*
* module: modrefchange
* date: 2019-04-12 06:23:14
* version: 1.5.5.1
*/
public function setDeliveryNumber($order_invoice_id, $id_shop)
{
if (!$order_invoice_id)
return false;
$id_shop = shop::getTotalShops() > 1 ? $id_shop : null;
$number = Configuration::get('PS_DELIVERY_NUMBER', null, null, $id_shop);
if ($number)
Configuration::updateValue('PS_DELIVERY_NUMBER', false, false, null, $id_shop);
$order_invoice = new OrderInvoice($order_invoice_id);
$order = new Order($order_invoice->id_order);
$cart = new Cart($order->id_cart);
if($ref = Hook::exec('actionBeforeAddDeliveryNumber', array('order'=>$order,'cart'=>$cart,'number'=>$number)))
$number = $ref;
$sql = 'UPDATE `'._DB_PREFIX_.'order_invoice` SET delivery_number =';
if ($number)
$sql .= (int)$number;
else
$sql .= '(SELECT new_number FROM (SELECT (MAX(`delivery_number`) + 1) AS new_number
FROM `'._DB_PREFIX_.'order_invoice`) AS result)';
$sql .=' WHERE `id_order_invoice` = '.(int)$order_invoice_id;
return Db::getInstance()->execute($sql);
}
}