168 lines
5.1 KiB
PHP
168 lines
5.1 KiB
PHP
<?php
|
|
/**
|
|
* TNT OFFICIAL MODULE FOR PRESTASHOP
|
|
*
|
|
* @author GFI Informatique <www.gfi.fr>
|
|
* @copyright 2016-2017 GFI Informatique, 2016-2017 TNT
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
|
*/
|
|
|
|
require_once _PS_MODULE_DIR_.'tntofficiel/libraries/TNTOfficiel_Debug.php';
|
|
|
|
/**
|
|
* Class TNTOfficielCart
|
|
*/
|
|
class TNTOfficielCart extends ObjectModel
|
|
{
|
|
// id_tntofficiel_cart
|
|
public $id;
|
|
|
|
public $id_cart;
|
|
public $carrier_code;
|
|
public $carrier_label;
|
|
public $delivery_point;
|
|
public $delivery_price;
|
|
public $customer_email;
|
|
public $customer_mobile;
|
|
public $address_building;
|
|
public $address_accesscode;
|
|
public $address_floor;
|
|
|
|
public static $definition = array(
|
|
'table' => 'tntofficiel_cart',
|
|
'primary' => 'id_tntofficiel_cart',
|
|
'fields' => array(
|
|
'id_cart' => array(
|
|
'type' => ObjectModel::TYPE_INT,
|
|
'validate' => 'isUnsignedId',
|
|
'required' => true
|
|
),
|
|
'carrier_code' => array(
|
|
'type' => ObjectModel::TYPE_STRING,
|
|
'size' => 64
|
|
),
|
|
'carrier_label' => array(
|
|
'type' => ObjectModel::TYPE_STRING,
|
|
'size' => 255
|
|
),
|
|
'delivery_point' => array(
|
|
'type' => ObjectModel::TYPE_STRING
|
|
/*, 'validate' => 'isSerializedArray', 'size' => 65000*/
|
|
),
|
|
'delivery_price' => array(
|
|
'type' => ObjectModel::TYPE_FLOAT,
|
|
'validate' => 'isPrice'
|
|
),
|
|
'customer_email' => array(
|
|
'type' => ObjectModel::TYPE_STRING,
|
|
'validate' => 'isEmail',
|
|
'size' => 128
|
|
),
|
|
'customer_mobile' => array(
|
|
'type' => ObjectModel::TYPE_STRING,
|
|
'validate' => 'isPhoneNumber',
|
|
'size' => 32
|
|
),
|
|
'address_building' => array(
|
|
'type' => ObjectModel::TYPE_STRING,
|
|
'size' => 16
|
|
),
|
|
'address_accesscode' => array(
|
|
'type' => ObjectModel::TYPE_STRING,
|
|
'size' => 16
|
|
),
|
|
'address_floor' => array(
|
|
'type' => ObjectModel::TYPE_STRING,
|
|
'size' => 16
|
|
),
|
|
),
|
|
);
|
|
|
|
/**
|
|
* Constructor.
|
|
*/
|
|
public function __construct($intArgId = null)
|
|
{
|
|
TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__));
|
|
|
|
parent::__construct($intArgId);
|
|
}
|
|
|
|
public static function loadCartID($intArgCartId)
|
|
{
|
|
TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__));
|
|
|
|
$intCartId = (int)$intArgCartId;
|
|
|
|
// No new cart ID.
|
|
if (!($intCartId > 0)) {
|
|
return false;
|
|
}
|
|
|
|
// Search row for cart ID.
|
|
$objDbQuery = new DbQuery();
|
|
$objDbQuery->select('*');
|
|
$objDbQuery->from(TNTOfficielCart::$definition['table']);
|
|
$objDbQuery->where('id_cart = '.$intCartId);
|
|
|
|
$objDB = Db::getInstance();
|
|
$arrResult = $objDB->executeS($objDbQuery);
|
|
// If row found and match cart ID.
|
|
if (count($arrResult)===1 && $intCartId===(int)$arrResult[0]['id_cart']) {
|
|
// Load existing TNT cart entry.
|
|
$objTNTCartModel = new TNTOfficielCart((int)$arrResult[0]['id_tntofficiel_cart']);
|
|
} else {
|
|
// Create a new TNT cart entry.
|
|
$objTNTCartModel = new TNTOfficielCart();
|
|
$objTNTCartModel->id_cart = $intCartId;
|
|
$objTNTCartModel->save();
|
|
}
|
|
|
|
// Check.
|
|
if ((int)$objTNTCartModel->id_cart !== $intCartId) {
|
|
return false;
|
|
}
|
|
|
|
return $objTNTCartModel;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getDeliveryPoint()
|
|
{
|
|
TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__));
|
|
|
|
$arrDeliveryPoint = Tools::unSerialize($this->delivery_point);
|
|
if (!is_array($arrDeliveryPoint)) {
|
|
$arrDeliveryPoint = array();
|
|
}
|
|
|
|
return $arrDeliveryPoint;
|
|
}
|
|
|
|
/**
|
|
* @param $arrArgDeliveryPoint
|
|
* @return mixed
|
|
*/
|
|
public function setDeliveryPoint($arrArgDeliveryPoint)
|
|
{
|
|
TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__));
|
|
|
|
if (!is_array($arrArgDeliveryPoint)) {
|
|
return false;
|
|
}
|
|
|
|
if (isset($arrArgDeliveryPoint['xett'])) {
|
|
unset($arrArgDeliveryPoint['pex']);
|
|
} elseif (isset($arrArgDeliveryPoint['pex'])) {
|
|
unset($arrArgDeliveryPoint['xett']);
|
|
} else {
|
|
$arrArgDeliveryPoint = array();
|
|
}
|
|
|
|
$this->delivery_point = serialize($arrArgDeliveryPoint);
|
|
return $this->save();
|
|
}
|
|
}
|