Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

View File

@@ -0,0 +1,148 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoACE
*/
class ColissimoACE extends ObjectModel
{
/** @var int $id_colissimo_ace */
public $id_colissimo_ace;
/** @var int $ref_order */
public $ref_order;
/** @var string $shipping_number */
public $shipping_number;
/** @var array $definition */
public static $definition = array(
'table' => 'colissimo_ace',
'primary' => 'id_colissimo_ace',
'fields' => array(
'ref_order' => array('type' => self::TYPE_INT, 'required' => false),
'shipping_number' => array('type' => self::TYPE_STRING, 'required' => false, 'size' => 64),
),
);
/**
* @var array $webserviceParameters
*/
protected $webserviceParameters = array(
'objectMethods' => array('add' => 'addWs'),
'objectNodeName' => 'colissimo_ace',
'fields' => array(
'id_order' => array(),
'shipping_number' => array(),
),
);
/**
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function addWs()
{
/** @var Colissimo $module */
$module = Module::getInstanceByName('colissimo');
$module->logger->setChannel('ACE');
if (ColissimoOrder::exists($this->ref_order)) {
$order = new Order((int) $this->ref_order);
$colissimoLabel = new ColissimoLabel();
$colissimoLabel->id_colissimo_order = (int) ColissimoOrder::getIdByOrderId($this->ref_order);
$colissimoLabel->id_colissimo_deposit_slip = 0;
$colissimoLabel->shipping_number = pSQL($this->shipping_number);
$colissimoLabel->label_format = 'pdf';
$colissimoLabel->return_label = 0;
$colissimoLabel->cn23 = 0;
$colissimoLabel->coliship = 1;
$colissimoLabel->migration = 0;
$colissimoLabel->insurance = null;
$colissimoLabel->file_deleted = 0;
$colissimoLabel->save(true);
$orderCarrier = ColissimoOrderCarrier::getByIdOrder($this->ref_order);
if (Validate::isLoadedObject($orderCarrier) && !$orderCarrier->tracking_number) {
$orderCarrier->tracking_number = pSQL($colissimoLabel->shipping_number);
$orderCarrier->save();
$hash = md5($order->reference.$order->secure_key);
$link = Context::getContext()->link->getModuleLink(
'colissimo',
'tracking',
array('order_reference' => $order->reference, 'hash' => $hash)
);
$isoLangOrder = Language::getIsoById($order->id_lang);
if (isset($this->module->PNAMailObject[$isoLangOrder])) {
$object = $module->PNAMailObject[$isoLangOrder];
} else {
$object = $module->PNAMailObject['en'];
}
ColissimoTools::sendHandlingShipmentMail(
$order,
sprintf($object, $order->reference),
$link
);
$module->logger->info('Send tracking mail for shipment '.$colissimoLabel->shipping_number);
}
if (Configuration::get('COLISSIMO_USE_SHIPPING_IN_PROGRESS')) {
$idShippingInProgressOS = Configuration::get('COLISSIMO_OS_SHIPPING_IN_PROGRESS');
$shippingInProgressOS = new OrderState((int) $idShippingInProgressOS);
if (Validate::isLoadedObject($shippingInProgressOS)) {
if (!$order->getHistory(Context::getContext()->language->id, (int) $idShippingInProgressOS)) {
$history = new OrderHistory();
$history->id_order = (int) $order->id;
$history->changeIdOrderState($idShippingInProgressOS, (int) $order->id);
try {
$history->add();
} catch (Exception $e) {
$module->logger->error(sprintf('Cannot change status of order #%d', $order->id));
}
}
} else {
$module->logger->error('Shipping in Progress order state is not valid');
}
}
$module->logger->info('Label imported successfully.');
return true;
}
return false;
}
/**
* @param bool $die
* @param bool $error_return
* @return bool|string
*/
public function validateFields($die = true, $error_return = false)
{
if (($id = ColissimoLabel::getLabelIdByShippingNumber($this->shipping_number)) !== 0) {
return sprintf('Colissimo label already exists (label ID #%d)', (int) $id);
}
return true;
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class DhlCarrier
*/
class ColissimoCarrier extends Carrier
{
/**
* @param array $zones
* @param bool|true $delete
* @return bool
*/
public function setZones($zones, $delete = true)
{
if ($delete) {
Db::getInstance()->delete('carrier_zone', 'id_carrier = '.(int) $this->id);
}
if (!is_array($zones) || !count($zones)) {
return true;
}
$return = true;
foreach ($zones as $zone) {
$this->addZone((int) $zone['id_zone']);
}
return $return;
}
/**
* @param array $groups
* @param bool|true $delete
* @return bool
* @throws PrestaShopDatabaseException
*/
public function setGroups($groups, $delete = true)
{
if ($delete) {
Db::getInstance()->delete('carrier_group', 'id_carrier = '.(int) $this->id);
}
if (!is_array($groups) || !count($groups)) {
return true;
}
$return = true;
foreach ($groups as $group) {
Db::getInstance()->insert(
'carrier_group',
array('id_carrier' => (int) $this->id, 'id_group' => (int) $group['id_group'])
);
}
return $return;
}
/**
* @return bool
*/
public function setRanges()
{
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = (int) $this->id;
$rangeWeight->delimiter1 = 0;
$rangeWeight->delimiter2 = 99999;
return $rangeWeight->add();
}
/**
* @param string $logoPath
* @param int $idLang
*/
public function setLogo($logoPath, $idLang)
{
ColissimoTools::copyLogo($logoPath, _PS_SHIP_IMG_DIR_.(int) $this->id.'.jpg');
ColissimoTools::copyLogo($logoPath, _PS_TMP_IMG_DIR_.'carrier_mini_'.(int) $this->id.'_'.$idLang.'.png');
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoCartPickupPoint
*/
class ColissimoCartPickupPoint
{
/**
* @param int $idCart
* @return int
*/
public static function getByCartId($idCart)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_pickup_point')
->from('colissimo_cart_pickup_point')
->where('id_cart = '.(int) $idCart);
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
/**
* @param int $idCart
* @param int $idPickupPoint
* @param string $mobilePhone
* @throws PrestaShopDatabaseException
*/
public static function updateCartPickupPoint($idCart, $idPickupPoint, $mobilePhone)
{
Db::getInstance()
->insert(
'colissimo_cart_pickup_point',
array(
'id_cart' => (int) $idCart,
'id_colissimo_pickup_point' => (int) $idPickupPoint,
'mobile_phone' => pSQL($mobilePhone),
),
false,
false,
Db::REPLACE
);
}
/**
* @param int $idCart
* @param string $mobilePhone
*/
public static function updateMobilePhoneByCartId($idCart, $mobilePhone)
{
Db::getInstance()
->update(
'colissimo_cart_pickup_point',
array('mobile_phone' => pSQL($mobilePhone)),
'id_cart = '.(int) $idCart
);
}
/**
* @param int $idCart
* @return false|null|string
*/
public static function getMobilePhoneByCartId($idCart)
{
$dbQuery = new DbQuery();
$dbQuery->select('mobile_phone')
->from('colissimo_cart_pickup_point')
->where('id_cart = '.(int) $idCart);
return Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoCustomCategory
*/
class ColissimoCustomCategory extends ObjectModel
{
/** @var int $id_category */
public $id_category;
/** @var string $short_desc */
public $short_desc;
/** @var int $id_country_origin */
public $id_country_origin;
/** @var string $hs_code */
public $hs_code;
/** @var array $definition */
public static $definition = array(
'table' => 'colissimo_custom_category',
'primary' => 'id_colissimo_custom_category',
'fields' => array(
'id_category' => array('type' => self::TYPE_INT, 'required' => false),
'short_desc' => array('type' => self::TYPE_STRING, 'required' => false, 'size' => 64),
'id_country_origin' => array('type' => self::TYPE_INT, 'required' => false),
'hs_code' => array('type' => self::TYPE_STRING, 'required' => false, 'size' => 8),
),
);
/**
* @var array $webserviceParameters
*/
protected $webserviceParameters = array(
'objectsNodeName' => 'colissimo_custom_categories',
'fields' => array(
'id_category' => array('xlink_resource' => 'categories'),
'id_country_origin' => array('xlink_resource' => 'countries'),
),
);
/**
* @param int $idCategory
* @return ColissimoCustomCategory
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public static function getByIdCategory($idCategory)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_custom_category')
->from('colissimo_custom_category')
->where('id_category = '.(int) $idCategory);
$id = Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
return new self((int) $id);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoCustomProduct
*/
class ColissimoCustomProduct extends ObjectModel
{
/** @var int $id_product */
public $id_product;
/** @var string $short_desc */
public $short_desc;
/** @var int $id_country_origin */
public $id_country_origin;
/** @var string $hs_code */
public $hs_code;
/** @var array $definition */
public static $definition = array(
'table' => 'colissimo_custom_product',
'primary' => 'id_colissimo_custom_product',
'fields' => array(
'id_product' => array('type' => self::TYPE_INT, 'required' => false),
'short_desc' => array('type' => self::TYPE_STRING, 'required' => false, 'size' => 64),
'id_country_origin' => array('type' => self::TYPE_INT, 'required' => false),
'hs_code' => array('type' => self::TYPE_STRING, 'required' => false, 'size' => 8),
),
);
/**
* @var array $webserviceParameters
*/
protected $webserviceParameters = array(
'fields' => array(
'id_product' => array('xlink_resource' => 'products'),
'id_country_origin' => array('xlink_resource' => 'countries'),
),
);
/**
* @param int $idProduct
* @return ColissimoCustomProduct
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public static function getByIdProduct($idProduct)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_custom_product')
->from('colissimo_custom_product')
->where('id_product = '.(int) $idProduct);
$id = Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
return new self((int) $id);
}
}

View File

@@ -0,0 +1,166 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoDepositSlip
*/
class ColissimoDepositSlip extends ObjectModel
{
/** @var int $id_colissimo_deposit_slip */
public $id_colissimo_deposit_slip;
/** @var string $filename */
public $filename;
/** @var int $number Deposit slip number */
public $number;
/** @var int $nb_parcel Number of parcels included in the deposit slip */
public $nb_parcel;
/** @var bool $file_deleted Flag to indicate if the file is deleted */
public $file_deleted;
/** @var string $date_add */
public $date_add;
/** @var array $definition */
public static $definition = array(
'table' => 'colissimo_deposit_slip',
'primary' => 'id_colissimo_deposit_slip',
'fields' => array(
'filename' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 45),
'number' => array('type' => self::TYPE_INT, 'required' => true, 'size' => 10),
'nb_parcel' => array('type' => self::TYPE_INT, 'required' => true, 'size' => 11),
'file_deleted' => array(
'type' => self::TYPE_BOOL,
'validate' => 'isBool',
'required' => true,
'default' => 0,
),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
),
);
/**
* @return bool
* @throws Exception
*/
public function download()
{
$file = $this->getFilePath();
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile($file);
exit;
} else {
return false;
}
}
/**
* @param string $content Base64 encoded string
* @return bool|int
* @throws Exception
*/
public function writeDepositSlip($content)
{
$depositSlipPath = $this->getFilePath(false);
return file_put_contents($depositSlipPath, $content);
}
/**
* @return bool
* @throws Exception
*/
public function deleteFile()
{
$depositSlipPath = $this->getFilePath();
if (file_exists($depositSlipPath)) {
return unlink($depositSlipPath);
}
return false;
}
/**
* @param bool $fileExistsCheck
* @return bool|string
* @throws Exception
*/
public function getFilePath($fileExistsCheck = true)
{
if (Tools::substr($this->filename, -4) !== '.pdf') {
throw new Exception('Deposit slip filename has an incorrect extension.');
}
$basename = Tools::substr($this->filename, 0, -4);
if (strpos($basename, '.') === false) {
if (!ctype_digit($basename)) {
throw new Exception('Deposit slip filename has an incorrect format.');
}
} elseif (!preg_match('/^[0-9]{8}\.[0-9]{14}$/', $basename)) {
throw new Exception('Deposit slip filename has an incorrect format.');
}
$safePath = realpath(_PS_MODULE_DIR_.'colissimo/documents/deposit_slip/');
if ($safePath === false) {
throw new Exception('Invalid pathname.');
}
if (!$fileExistsCheck) {
return $safePath.DIRECTORY_SEPARATOR.$this->filename;
}
$path = dirname(__FILE__).'/../documents/deposit_slip/'.$this->filename;
$realpath = realpath($path);
if ($realpath === false) {
throw new Exception('The path of deposit slip file is incorrect.');
}
if (Tools::substr($realpath, 0, Tools::strlen($safePath)) != $safePath) {
throw new Exception('Possible directory traversal attempt.');
}
return $realpath;
}
/**
* @return array
* @throws PrestaShopDatabaseException
*/
public function getLabelIds()
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_label')
->from('colissimo_label')
->where('id_colissimo_deposit_slip = '.(int) $this->id);
return (array) Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($dbQuery);
}
}

View File

@@ -0,0 +1,472 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoLabel
*/
class ColissimoLabel extends ObjectModel
{
const FRANCE_RETURN_PREFIX = '8R';
const INTER_RETURN_PREFIX = '7R';
/** @var int $id_colissimo_label */
public $id_colissimo_label;
/** @var int $id_colissimo_order */
public $id_colissimo_order;
/** @var int $id_colissimo_deposit_slip */
public $id_colissimo_deposit_slip;
/** @var string $shipping_number */
public $shipping_number;
/** @var string $label_format Format of the label (PDF/ZPL...) */
public $label_format;
/** @var int $return_label Flag to indicate if the label is a return label */
public $return_label;
/** @var bool $cn23 Flag to indicate if the label has a CN23 file associated */
public $cn23;
/** @var bool $coliship Flag to indicate if the label comes from Coliship */
public $coliship;
/** @var bool $migration Flag to indicate if the label has been migrated from other module */
public $migration;
/** @var int $insurance NULL = no indication, 0 = shipment not insured, 1 = shipment insured */
public $insurance;
/** @var bool $file_deleted Flag to indicate if the file is deleted */
public $file_deleted;
/** @var string $date_add */
public $date_add;
/** @var array $validFormats Valid file extensions for labels */
private $validFormats = array('pdf', 'dpl', 'zpl');
/** @var array $definition */
public static $definition = array(
'table' => 'colissimo_label',
'primary' => 'id_colissimo_label',
'fields' => array(
'id_colissimo_order' => array(
'type' => self::TYPE_INT,
'validate' => 'isNullOrUnsignedId',
'required' => true,
),
'id_colissimo_deposit_slip' => array(
'type' => self::TYPE_INT,
'validate' => 'isNullOrUnsignedId',
'required' => false,
),
'shipping_number' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 45),
'label_format' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 3),
'return_label' => array(
'type' => self::TYPE_INT,
'validate' => 'isNullOrUnsignedId',
'required' => true,
),
'cn23' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
'coliship' => array(
'type' => self::TYPE_BOOL,
'validate' => 'isBool',
'required' => true,
'default' => 0,
),
'migration' => array(
'type' => self::TYPE_BOOL,
'validate' => 'isBool',
'required' => true,
'default' => 0,
),
'insurance' => array(
'type' => self::TYPE_NOTHING,
'validate' => 'isUnsignedId',
'required' => false,
'default' => null,
),
'file_deleted' => array(
'type' => self::TYPE_BOOL,
'validate' => 'isBool',
'required' => true,
'default' => 0,
),
'date_add' => array(
'type' => self::TYPE_DATE,
'validate' => 'isDate',
'copy_post' => false,
),
),
);
/**
* @return bool
* @throws Exception
*/
public function download()
{
$file = $this->getFilePath();
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile($file);
exit;
} else {
return false;
}
}
/**
* @return bool
* @throws Exception
*/
public function view()
{
$file = $this->getFilePath();
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: inline; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile($file);
exit;
} else {
return false;
}
}
/**
* @param string $content Base64 encoded string
* @return bool|int
* @throws Exception
*/
public function writeLabel($content)
{
$labelPath = $this->getFilePath(false);
return file_put_contents($labelPath, $content);
}
/**
* @return bool
* @throws Exception
*/
public function deleteFile()
{
$labelPath = $this->getFilePath();
if (file_exists($labelPath)) {
return unlink($labelPath);
}
return false;
}
/**
* @param bool $fileExistsCheck
* @return bool|string
* @throws Exception
*/
public function getFilePath($fileExistsCheck = true)
{
if ((!$this->return_label && !in_array($this->label_format, $this->validFormats)) ||
($this->return_label && $this->label_format != 'pdf') ||
!ctype_alnum($this->shipping_number)
) {
throw new Exception('Label filename has an incorrect extension or format.');
}
$safePath = realpath(_PS_MODULE_DIR_.'colissimo/documents/labels/');
$returnLabel = $this->return_label ? 'RET-' : '';
$fileExtension = $this->return_label ? 'pdf' : $this->label_format;
$filename = sprintf('%s%d-%s.%s', $returnLabel, (int) $this->id, $this->shipping_number, $fileExtension);
if ($safePath === false) {
throw new Exception('Invalid pathname.');
}
if (!$fileExistsCheck) {
return $safePath.DIRECTORY_SEPARATOR.$filename;
}
$path = dirname(__FILE__).'/../documents/labels/'.$filename;
$realpath = realpath($path);
if ($realpath === false) {
throw new Exception('The path of label file is incorrect. '.$path);
}
if (Tools::substr($realpath, 0, Tools::strlen($safePath)) != $safePath) {
throw new Exception('Possible directory traversal attempt.');
}
return $realpath;
}
/**
* @return bool
* @throws Exception
*/
public function downloadCN23()
{
$file = $this->getCN23Path();
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile($file);
exit;
} else {
return false;
}
}
/**
* @return bool
* @throws Exception
*/
public function viewCN23()
{
$file = $this->getCN23Path();
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: inline; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile($file);
exit;
} else {
return false;
}
}
/**
* @return bool
* @throws Exception
*/
public function deleteCN23()
{
$file = $this->getCN23Path();
if (file_exists($file)) {
return unlink($file);
} else {
return false;
}
}
/**
* @param string $content Base64 encoded string
* @return bool|int
* @throws Exception
*/
public function writeCN23File($content)
{
$cn23Path = $this->getCN23Path(false);
return file_put_contents($cn23Path, $content);
}
/**
* @param bool $fileExistsCheck
* @return string
* @throws Exception
*/
public function getCN23Path($fileExistsCheck = true)
{
if (!ctype_alnum($this->shipping_number)) {
throw new Exception('CN23 filename has an incorrect format.');
}
$safePath = realpath(_PS_MODULE_DIR_.'colissimo/documents/cn23/');
$filename = sprintf('%d-CN23-%s.pdf', (int) $this->id, $this->shipping_number);
if ($safePath === false) {
throw new Exception('Invalid pathname.');
}
if (!$fileExistsCheck) {
return $safePath.DIRECTORY_SEPARATOR.$filename;
}
$path = dirname(__FILE__).'/../documents/cn23/'.$filename;
$realpath = realpath($path);
if ($realpath === false) {
throw new Exception('The path of CN23 file is incorrect.');
}
if (Tools::substr($realpath, 0, Tools::strlen($safePath)) != $safePath) {
throw new Exception('Possible directory traversal attempt.');
}
return $realpath;
}
/**
* @return array|false|mysqli_result|null|PDOStatement|resource
* @throws PrestaShopDatabaseException
*/
public function getLastTrackingDetailsKnown()
{
$dbQuery = new DbQuery();
$dbQuery->select('*')
->from('colissimo_shipment_tracking')
->where('id_colissimo_label = '.(int) $this->id);
return Db::getInstance(_PS_USE_SQL_SLAVE_)
->getRow($dbQuery);
}
/**
* @param string $shippingNumber
* @return int
*/
public static function getLabelIdByShippingNumber($shippingNumber)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_label')
->from('colissimo_label')
->where('shipping_number = "'.pSQL($shippingNumber).'"');
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
/**
* @return bool
*/
public function hasMailboxPickup()
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_label')
->from('colissimo_mailbox_return')
->where('id_colissimo_label = '.(int) $this->id);
return (bool) Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
/**
* @return array|bool|null|object
*/
public function getMailboxPickupDetails()
{
$dbQuery = new DbQuery();
$dbQuery->select('*')
->from('colissimo_mailbox_return')
->where('id_colissimo_label = '.(int) $this->id);
return Db::getInstance(_PS_USE_SQL_SLAVE_)
->getRow($dbQuery);
}
/**
* @return int
*/
public function getReturnLabelId()
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_label')
->from('colissimo_label')
->where('return_label = '.(int) $this->id);
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
/**
* Determine if a label is downloadable. We cannot download label that are:
* - deleted physically on the server
* - created from Coliship
* - created from another Colissimo module and migrated
*
* @return bool
*/
public function isDownloadable()
{
if ($this->file_deleted) {
return false;
}
if ($this->coliship) {
return false;
}
if ($this->migration) {
return false;
}
return true;
}
/**
* Determine if a label is deletable. We cannot delete label that are:
* - linked to a deposit slip
*
* @return bool
*/
public function isDeletable()
{
if ($this->id_colissimo_deposit_slip) {
return false;
}
return true;
}
/**
* @return bool
*/
public function isFranceReturnLabel()
{
if (!$this->shipping_number) {
return false;
}
return (Tools::substr($this->shipping_number, 0, 2) == self::FRANCE_RETURN_PREFIX) ? true : false;
}
/**
* @return string
* @throws PrestaShopDatabaseException
*/
public function getNextShippingNumber()
{
$dbQuery = new DbQuery();
$dbQuery->select('shipping_number')
->from('colissimo_label')
->where('id_colissimo_order = '.(int) $this->id_colissimo_order)
->where('shipping_number != "'.pSQL($this->shipping_number).'"')
->where('return_label = 0');
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($dbQuery);
if (!$result) {
return '';
} else {
return $result[0]['shipping_number'];
}
}
}

View File

@@ -0,0 +1,594 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoLabelGenerator
*/
class ColissimoLabelGenerator
{
const CATEGORY_GIFT = 1;
const CATEGORY_SAMPLES = 2;
const CATEGORY_COMMERCIAL = 3;
const CATEGORY_DOC = 4;
const CATEGORY_OTHER = 5;
const CATEGORY_MERCHANDISE_RETURN = 6;
const COLISHIP_CATEGORY_GIFT = 2;
const COLISHIP_CATEGORY_SAMPLES = 0;
const COLISHIP_CATEGORY_COMMERCIAL = 4;
const COLISHIP_CATEGORY_DOC = 1;
const COLISHIP_CATEGORY_OTHER = 5;
const COLISHIP_CATEGORY_MERCHANDISE_RETURN = 3;
/** @var array $data */
private $data;
/** @var ColissimoLogger $logger */
private $logger;
/** @var ColissimoGenerateLabelRequest $request */
private $request;
/**
* ColissimoLabelGenerator constructor.
* @param ColissimoLogger $logger
*/
public function __construct($logger)
{
$this->logger = $logger;
$this->logger->setChannel('GenerateLabel');
}
/**
* @param array $data
*/
public function setData($data)
{
$this->data = $data;
}
/**
* @return array
* @throws Exception
*/
public function getProductsForCustomsDeclaration()
{
/** @var Order $order */
$order = $this->data['order'];
$currency = new Currency((int) $order->id_currency);
$products = $order->getProducts();
$originCountry = 'FR';
$hsCode = Configuration::get('COLISSIMO_DEFAULT_HS_CODE');
$articles = array();
foreach ($products as $product) {
$productCustomDetails = ColissimoCustomProduct::getByIdProduct((int) $product['product_id']);
$categoryCustomDetails = ColissimoCustomCategory::getByIdCategory((int) $product['id_category_default']);
$shortDescription = $product['product_name'];
if ($productCustomDetails->short_desc) {
$shortDescription = $productCustomDetails->short_desc;
} elseif ($categoryCustomDetails->short_desc) {
$shortDescription = $categoryCustomDetails->short_desc;
}
if ($productCustomDetails->hs_code) {
$hsCode = $productCustomDetails->hs_code;
} elseif ($categoryCustomDetails->hs_code) {
$hsCode = $categoryCustomDetails->hs_code;
}
if ($productCustomDetails->id_country_origin) {
$originCountry = Country::getIsoById((int) $productCustomDetails->id_country_origin);
} elseif ($categoryCustomDetails->id_country_origin) {
$originCountry = Country::getIsoById((int) $categoryCustomDetails->id_country_origin);
}
$weight = (float) $product['product_weight'] ? ColissimoTools::weightInKG($product['product_weight']) : 0.05;
$articles[] = array(
'description' => $shortDescription,
'quantity' => $product['product_quantity'],
'weight' => $weight,
'value' => (float) $product['unit_price_tax_excl'],
'hsCode' => $hsCode,
'originCountry' => $originCountry,
'currency' => $currency->iso_code,
'artref' => $product['product_reference'],
'originalIdent' => 'A',
);
}
return $articles;
}
/**
* @param bool $forcePdf
*/
public function setLabelOutput($forcePdf = false)
{
$output = array(
'x' => 0,
'y' => 0,
'outputPrintingType' => $forcePdf ? 'PDF_A4_300dpi' : Configuration::get('COLISSIMO_LABEL_FORMAT'),
);
$this->request->setOutput($output);
}
/**
* @throws Exception
*/
public function setLabelService()
{
$isoEUCountriesWithCN23 = ColissimoTools::$isoEUCountriesWithCN23;
$isoEUCountries = ColissimoTools::$isoEUCountries;
if (Configuration::get('COLISSIMO_ENABLE_BREXIT')) {
$isoEUCountries = array_diff($isoEUCountries, array('GB'));
}
/** @var Order $order */
$order = $this->data['order'];
/** @var ColissimoService $colissimoService */
$colissimoService = $this->data['colissimo_service'];
if ($colissimoService->type == ColissimoService::TYPE_RELAIS) {
$this->logger->info(sprintf(
'Order #%d (%s) - Shipping type: PICKUP POINT DELIVERY',
$this->data['order']->id,
$this->data['order']->reference
));
$pickupPoint = new ColissimoPickupPoint((int) $this->data['colissimo_order']->id_colissimo_pickup_point);
$services = array(
'productCode' => $pickupPoint->getProductCodeForAffranchissement(),
'depositDate' => date('Y-m-d'),
);
} else {
$this->logger->info(sprintf(
'Order #%d (%s) - Shipping type: HOME DELIVERY',
$this->data['order']->id,
$this->data['order']->reference
));
$services = array(
'productCode' => $colissimoService->product_code,
'depositDate' => date('Y-m-d'),
);
}
$shippingAmountEUR = ColissimoTools::convertInEUR(
$order->total_shipping_tax_excl,
new Currency($order->id_currency)
);
$shippingAmountEUR = (float) $shippingAmountEUR ? $shippingAmountEUR : 0.01;
$services['transportationAmount'] = (int) ($shippingAmountEUR * 100);
$merchantAddress = new ColissimoMerchantAddress('sender');
/** @var Address $customerAddress */
$customerAddress = $this->data['customer_addr'];
$isoTo = Country::getIsoById((int) $customerAddress->id_country);
$isoFrom = $merchantAddress->countryCode;
if (ColissimoTools::needCN23($isoFrom, $isoTo, $customerAddress->postcode)) {
$services['totalAmount'] = $services['transportationAmount'];
$services['returnTypeChoice'] = 3;
}
$services['orderNumber'] = $this->data['order']->reference;
if ($colissimoService->type == ColissimoService::TYPE_RELAIS) {
$services['commercialName'] = $merchantAddress->companyName;
}
$this->request->setShipmentServices($services);
}
/**
*
*/
public function setLabelCustomsDeclarations()
{
$merchantAddress = new ColissimoMerchantAddress('sender');
/** @var Address $customerAddress */
$customerAddress = $this->data['customer_addr'];
$isoTo = Country::getIsoById((int) $customerAddress->id_country);
$isoFrom = $merchantAddress->countryCode;
if (ColissimoTools::needCN23($isoFrom, $isoTo, $customerAddress->postcode)) {
$customsDeclaration = array(
'includeCustomsDeclarations' => 1,
'contents' => array(
'article' => $this->getProductsForCustomsDeclaration(),
'category' => array(
'value' => self::CATEGORY_COMMERCIAL,
),
),
);
$this->logger->info(
sprintf(
'Order #%d (%s) - Include customs declarations',
$this->data['order']->id,
$this->data['order']->reference
),
array('data', $customsDeclaration)
);
$this->request->setCustomsOptions($customsDeclaration);
}
}
/**
* @param ColissimoLabel $colissimoLabel
* @throws Exception
*/
public function setReturnLabelCustomsDeclarations($colissimoLabel)
{
$merchantAddress = new ColissimoMerchantAddress('sender');
/** @var Address $customerAddress */
$customerAddress = $this->data['customer_addr'];
$isoTo = Country::getIsoById((int) $customerAddress->id_country);
$isoFrom = $merchantAddress->countryCode;
if (ColissimoTools::needCN23($isoFrom, $isoTo, $customerAddress->postcode)) {
if (Tools::substr($this->data['order']->invoice_date, 0, 10) != '0000-00-00') {
$invoiceDate = Tools::substr($this->data['order']->invoice_date, 0, 10);
} else {
$invoiceDate = date('Y-m-d');
}
$customsDeclaration = array(
'includeCustomsDeclarations' => 1,
'contents' => array(
'article' => $this->getProductsForCustomsDeclaration(),
'category' => array(
'value' => self::CATEGORY_MERCHANDISE_RETURN,
),
'original' => array(
array(
'originalIdent' => 'A',
'originalInvoiceNumber' => 'IN'.$this->data['order']->invoice_number,
'originalInvoiceDate' => $invoiceDate,
'originalParcelNumber' => $colissimoLabel->shipping_number,
),
),
),
);
$this->logger->info(
sprintf(
'Order #%d (%s) - Include customs declarations',
$this->data['order']->id,
$this->data['order']->reference
),
array('data', $customsDeclaration)
);
$this->request->setCustomsOptions($customsDeclaration);
}
}
/**
*
*/
public function setLabelAddresses()
{
/** @var ColissimoService $colissimoService */
$colissimoService = $this->data['colissimo_service'];
/** @var ColissimoMerchantAddress $senderAddrObj */
$senderAddrObj = $this->data['merchant_addr'];
$senderAddr = array(
'senderParcelRef' => $this->data['order']->reference,
'address' => array(
'companyName' => $senderAddrObj->companyName,
'lastName' => $senderAddrObj->lastName,
'firstName' => $senderAddrObj->lastName,
'line0' => $senderAddrObj->line0,
'line1' => $senderAddrObj->line1,
'line2' => $senderAddrObj->line2,
'line3' => $senderAddrObj->line3,
'countryCode' => $senderAddrObj->countryCode,
'city' => $senderAddrObj->city,
'zipCode' => $senderAddrObj->zipCode,
'phoneNumber' => $senderAddrObj->phoneNumber,
'email' => $senderAddrObj->email,
),
);
$this->request->setSenderAddress($senderAddr);
/** @var Address $customerAddrDb */
if ($colissimoService->type == ColissimoService::TYPE_RELAIS) {
$customerAddrDb = $this->data['customer_addr_inv'];
} else {
$customerAddrDb = $this->data['customer_addr'];
}
$customerAddr = array(
'addresseeParcelRef' => $this->data['order']->reference,
'codeBarForReference' => true,
'address' => array(
'companyName' => $customerAddrDb->company,
'lastName' => $customerAddrDb->lastname,
'firstName' => $customerAddrDb->firstname,
'line2' => $customerAddrDb->address1,
'line3' => $customerAddrDb->address2,
'countryCode' => Country::getIsoById($customerAddrDb->id_country),
'city' => $customerAddrDb->city,
'zipCode' => $customerAddrDb->postcode,
'phoneNumber' => $customerAddrDb->phone,
),
);
if ($colissimoService->type == ColissimoService::TYPE_RELAIS) {
$customerAddr['address']['mobileNumber'] = $this->data['form_options']['mobile_phone'];
} else {
$customerAddr['address']['mobileNumber'] = $customerAddrDb->phone_mobile;
}
$customerAddr['address']['email'] = $this->data['customer']->email;
$this->request->setAddresseeAddress($customerAddr);
}
/**
*
*/
public function setReturnLabelAddresses()
{
/** @var ColissimoMerchantAddress $merchantAddrObj */
$merchantAddrObj = $this->data['merchant_addr'];
if ($this->data['colissimo_service_initial']->type == ColissimoService::TYPE_RELAIS) {
/** @var Address $customerAddrDb */
$customerAddrDb = new Address((int) $this->data['order']->id_address_invoice);
$mobilePhone = $this->data['form_options']['mobile_phone'];
} else {
/** @var Address $customerAddrDb */
$customerAddrDb = $this->data['customer_addr'];
$mobilePhone = $customerAddrDb->phone_mobile;
}
$customerAddr = array(
'senderParcelRef' => $this->data['order']->reference,
'address' => array(
'companyName' => $customerAddrDb->company,
'lastName' => $customerAddrDb->lastname,
'firstName' => $customerAddrDb->firstname,
'line2' => $customerAddrDb->address1,
'line3' => $customerAddrDb->address2,
'countryCode' => Country::getIsoById($customerAddrDb->id_country),
'city' => $customerAddrDb->city,
'zipCode' => $customerAddrDb->postcode,
'mobileNumber' => $mobilePhone,
'email' => $this->data['customer']->email,
),
);
$this->request->setSenderAddress($customerAddr);
$merchantAddr = array(
'addresseeParcelRef' => $this->data['order']->reference,
'codeBarForReference' => true,
'address' => array(
'companyName' => $merchantAddrObj->companyName,
'lastName' => $merchantAddrObj->lastName,
'firstName' => $merchantAddrObj->firstName,
'line0' => $merchantAddrObj->line0,
'line1' => $merchantAddrObj->line1,
'line2' => $merchantAddrObj->line2,
'line3' => $merchantAddrObj->line3,
'countryCode' => $merchantAddrObj->countryCode,
'city' => $merchantAddrObj->city,
'zipCode' => $merchantAddrObj->zipCode,
'phoneNumber' => $merchantAddrObj->phoneNumber,
'email' => $merchantAddrObj->email,
),
);
$this->request->setAddresseeAddress($merchantAddr);
}
/**
* @throws Exception
*/
public function setLabelOptions()
{
/** @var ColissimoService $colissimoService */
$colissimoService = $this->data['colissimo_service'];
$labelOptions = array();
//@formatter:off
if ($this->data['form_options']['insurance']) {
/** @var Order $order */
$order = $this->data['order'];
$insuredAmount = $order->total_products;
$insuredAmountEUR = ColissimoTools::convertInEUR($insuredAmount, new Currency($order->id_currency));
$labelOptions['insuranceValue'] = $insuredAmountEUR * 100;
$this->logger->info(sprintf(
'Order #%d (%s) - Shipment insurance : %s EUR',
$this->data['order']->id,
$this->data['order']->reference,
$insuredAmountEUR
));
}
//@formatter:on
$labelOptions['weight'] = $this->data['form_options']['weight'];
if ($this->data['form_options']['d150']) {
if ($colissimoService->isMachinableOptionAvailable()) {
$labelOptions['nonMachinable'] = 1;
$this->logger->info(sprintf(
'Order #%d (%s) - Shipment non machinable',
$this->data['order']->id,
$this->data['order']->reference
));
}
}
if ($colissimoService->type == ColissimoService::TYPE_RELAIS) {
$pickupPoint = new ColissimoPickupPoint((int) $this->data['colissimo_order']->id_colissimo_pickup_point);
$labelOptions['pickupLocationId'] = $pickupPoint->colissimo_id;
$this->logger->info(sprintf(
'Order #%d (%s) - Pickup point ID #%s',
$this->data['order']->id,
$this->data['order']->reference,
$pickupPoint->colissimo_id
));
}
if ($this->data['form_options']['ta']) {
$labelOptions['ftd'] = 1;
$this->logger->info(sprintf(
'Order #%d (%s) - Shipment free of taxes and fees',
$this->data['order']->id,
$this->data['order']->reference
));
}
$this->request->setShipmentOptions($labelOptions);
}
/**
* @throws Exception
*/
public function setReturnLabelOptions()
{
/** @var ColissimoService $colissimoService */
$colissimoService = $this->data['colissimo_service'];
$labelOptions = array();
//@formatter:off
if ($this->data['form_options']['insurance']) {
/** @var Order $order */
$order = $this->data['order'];
$insuredAmount = $order->total_products;
$insuredAmountEUR = ColissimoTools::convertInEUR($insuredAmount, new Currency($order->id_currency));
$labelOptions['insuranceValue'] = $insuredAmountEUR * 100;
$this->logger->info(sprintf(
'Order #%d (%s) - Return shipment insurance : %s EUR',
$this->data['order']->id,
$this->data['order']->reference,
$insuredAmountEUR
));
}
//@formatter:on
$labelOptions['weight'] = $this->data['form_options']['weight'];
if ($this->data['form_options']['d150']) {
if ($colissimoService->isMachinableOptionAvailable()) {
$labelOptions['nonMachinable'] = 1;
$this->logger->info(sprintf(
'Order #%d (%s) - Shipment non machinable',
$this->data['order']->id,
$this->data['order']->reference
));
}
}
if ($colissimoService->type == ColissimoService::TYPE_RELAIS) {
$pickupPoint = new ColissimoPickupPoint((int) $this->data['colissimo_order']->id_colissimo_pickup_point);
$labelOptions['pickupLocationId'] = $pickupPoint->colissimo_id;
}
$labelOptions['ftd'] = 0;
$this->request->setShipmentOptions($labelOptions);
}
/**
*
*/
public function setCustomFields()
{
$infoText = array(
'key' => 'CUSER_INFO_TEXT',
'value' => sprintf('PS%s;%s', _PS_VERSION_, $this->data['version']),
);
$infoEori = array(
'key' => 'EORI',
'value' => Configuration::get('COLISSIMO_EORI_NUMBER'),
);
$fields = array($infoText, $infoEori);
$this->request->addCustomField($fields);
}
/**
* @param bool|int $returnLabel
* @return ColissimoLabel
* @throws Exception
* @throws PrestaShopException
*/
private function generateLabel($returnLabel = false)
{
$this->request->buildRequest();
$client = new ColissimoClient();
$client->setRequest($this->request);
/** @var ColissimoGenerateLabelResponse $response */
$response = $client->request();
$this->logger->info(
sprintf('Order #%d (%s) - Response', $this->data['order']->id, $this->data['order']->reference),
array('response' => $response->response)
);
if (!$response->messages[0]['id']) {
$label = new ColissimoLabel();
$label->id_colissimo_order = (int) $this->data['colissimo_order']->id;
$label->id_colissimo_deposit_slip = 0;
$extension = (int) $returnLabel ? 'pdf' : Tools::substr(Configuration::get('COLISSIMO_LABEL_FORMAT'), 0, 3);
$label->label_format = pSQL(Tools::strtolower($extension));
$label->return_label = (int) $returnLabel;
$label->cn23 = $response->cn23 ? 1 : 0;
$label->shipping_number = pSQL($response->parcelNumber);
$label->coliship = 0;
$label->migration = 0;
$label->insurance = $this->data['form_options']['insurance'] ? '1' : '0';
$label->file_deleted = 0;
$label->save();
$label->writeLabel(base64_decode($response->label));
if (null !== $response->cn23) {
$label->writeCN23File(base64_decode($response->cn23));
$this->logger->info(sprintf(
'Order #%d (%s) - CN23 generated',
$this->data['order']->id,
$this->data['order']->reference
));
}
return $label;
} else {
$message = $response->messages[0];
$this->logger->error(
'Exception thrown: '.$message['messageContent'],
array('details' => $response->messages)
);
throw new Exception(sprintf('%s (%s) - %s', $message['id'], $message['type'], $message['messageContent']));
}
}
/**
* @param ColissimoLabel $colissimoLabel
* @return ColissimoLabel
* @throws Exception
* @throws PrestaShopException
*/
public function generateReturn($colissimoLabel)
{
$this->logger->info(
sprintf('Order #%d (%s) - Generate return label', $this->data['order']->id, $this->data['order']->reference)
);
$this->request = new ColissimoGenerateLabelRequest(
ColissimoTools::getCredentials($this->data['order']->id_shop)
);
$this->setLabelOutput(true);
$this->setLabelService();
$this->setReturnLabelCustomsDeclarations($colissimoLabel);
$this->setReturnLabelAddresses();
$this->setReturnLabelOptions();
$this->setCustomFields();
return $this->generateLabel($colissimoLabel->id);
}
/**
* @return ColissimoLabel
* @throws Exception
* @throws PrestaShopException
*/
public function generate()
{
$this->logger->info(
sprintf('Order #%d (%s) - Generate label', $this->data['order']->id, $this->data['order']->reference)
);
$this->request = new ColissimoGenerateLabelRequest(
ColissimoTools::getCredentials($this->data['order']->id_shop)
);
$this->setLabelOutput();
$this->setLabelService();
$this->setLabelCustomsDeclarations();
$this->setLabelAddresses();
$this->setLabelOptions();
$this->setCustomFields();
return $this->generateLabel();
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoLink
*/
class ColissimoLink extends Link
{
/**
* getBaseLink() is public only since 1.6.1.15 (protected before)
* This method allows us to call it from outside of Link
*
* @param null $id_shop
* @param null $ssl
* @param bool $relative_protocol
* @return string
*/
public function getBaseLink($id_shop = null, $ssl = null, $relative_protocol = false)
{
return parent::getBaseLink($id_shop, $ssl, $relative_protocol);
}
}

View File

@@ -0,0 +1,155 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoMerchantAddress
*/
class ColissimoMerchantAddress
{
/** @var array $types */
private static $types = array('sender', 'return');
/** @var string $type */
public $type;
/** @var string $companyName */
public $companyName;
/** @var string $lastName */
public $lastName;
/** @var string $firstName */
public $firstName;
/** @var string $line0 */
public $line0;
/** @var string $line1 */
public $line1;
/** @var string $line2 */
public $line2;
/** @var string $line3 */
public $line3;
/** @var string $countryCode */
public $countryCode;
/** @var string $city */
public $city;
/** @var string $zipCode */
public $zipCode;
/** @var string $phoneNumber */
public $phoneNumber;
/** @var string $email */
public $email;
/**
* ColissimoMerchantAddress constructor.
* @param string $type
* @param array $addressArray
*/
public function __construct($type = 'sender', $addressArray = array())
{
if (!in_array($type, self::$types)) {
$this->type = 'sender';
} else {
$this->type = $type;
}
if (!$addressArray) {
$addressString = Configuration::get('COLISSIMO_'.Tools::strtoupper($this->type).'_ADDRESS');
$addressArray = (array) json_decode($addressString, true);
}
$this->hydrate($addressArray);
}
/**
* @param array $array
*/
private function hydrate($array)
{
$this->companyName = isset($array[$this->type.'_company']) ? $array[$this->type.'_company'] : null;
$this->lastName = isset($array[$this->type.'_lastname']) ? $array[$this->type.'_lastname'] : null;
$this->firstName = isset($array[$this->type.'_firstname']) ? $array[$this->type.'_firstname'] : null;
$this->line0 = isset($array[$this->type.'_address3']) ? $array[$this->type.'_address3'] : null;
$this->line1 = isset($array[$this->type.'_address4']) ? $array[$this->type.'_address4'] : null;
$this->line2 = isset($array[$this->type.'_address1']) ? $array[$this->type.'_address1'] : null;
$this->line3 = isset($array[$this->type.'_address2']) ? $array[$this->type.'_address2'] : null;
$this->countryCode = isset($array[$this->type.'_country']) ? $array[$this->type.'_country'] : null;
$this->city = isset($array[$this->type.'_city']) ? $array[$this->type.'_city'] : null;
$this->zipCode = isset($array[$this->type.'_zipcode']) ? $array[$this->type.'_zipcode'] : null;
$this->phoneNumber = isset($array[$this->type.'_phone']) ? $array[$this->type.'_phone'] : null;
$this->email = isset($array[$this->type.'_email']) ? $array[$this->type.'_email'] : null;
}
/**
* @return ColissimoMerchantAddress
*/
public static function getMerchantReturnAddress()
{
$useReturnAddress = Configuration::get('COLISSIMO_USE_RETURN_ADDRESS');
if ($useReturnAddress) {
return new self('return');
} else {
return new self('sender');
}
}
/**
* @return array
*/
public function toArray()
{
return array(
$this->type.'_company' => $this->companyName,
$this->type.'_lastname' => $this->lastName,
$this->type.'_firstname' => $this->firstName,
$this->type.'_address1' => $this->line2,
$this->type.'_address2' => $this->line3,
$this->type.'_address3' => $this->line0,
$this->type.'_address4' => $this->line1,
$this->type.'_country' => $this->countryCode,
$this->type.'_city' => $this->city,
$this->type.'_zipcode' => $this->zipCode,
$this->type.'_phone' => $this->phoneNumber,
$this->type.'_email' => $this->email,
);
}
/**
* @return false|string
*/
public function toJSON()
{
$array = (array) $this->toArray();
return json_encode($array);
}
}

View File

@@ -0,0 +1,300 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoModuleConfiguration
*/
class ColissimoModuleConfiguration
{
/** @var Context $context */
private $context;
/** @var string $localPath */
private $localPath;
/** @var string $pathUri */
private $pathUri;
/** @var string $version */
private $version;
/** @var array $migrateModuleFromList */
private $migrateModuleFromList = array(
'colissimo_simplicite',
'socolissimo',
'sonice_etiquetage',
'soflexibilite',
);
/** @var array $modulesToMigrate */
public $modulesToMigrate = array();
/** @var array $senderAddressFields */
public $senderAddressFields = array(
'sender_company',
'sender_lastname',
'sender_firstname',
'sender_address1',
'sender_address2',
'sender_address3',
'sender_address4',
'sender_city',
'sender_zipcode',
'sender_country',
'sender_phone',
'sender_email',
);
/** @var array $returnAddressFields */
public $returnAddressFields = array(
'return_company',
'return_lastname',
'return_firstname',
'return_address1',
'return_address2',
'return_address3',
'return_address4',
'return_city',
'return_zipcode',
'return_country',
'return_phone',
'return_email',
);
/** @var array $accountFields */
public $accountFields = array(
'COLISSIMO_LOGS',
'COLISSIMO_ACCOUNT_LOGIN',
'COLISSIMO_ACCOUNT_PASSWORD',
);
/** @var array $widgetFields */
public $widgetFields = array(
'COLISSIMO_WIDGET_REMOTE',
'COLISSIMO_WIDGET_ENDPOINT',
'COLISSIMO_WIDGET_COLOR_1',
'COLISSIMO_WIDGET_COLOR_2',
'COLISSIMO_WIDGET_FONT',
);
/** @var array $backFields */
public $backFields = array(
'COLISSIMO_ORDER_PREPARATION_TIME',
'COLISSIMO_USE_SHIPPING_IN_PROGRESS',
'COLISSIMO_USE_HANDLED_BY_CARRIER',
'COLISSIMO_ENABLE_PNA_MAIL',
'COLISSIMO_GENERATE_LABEL_PRESTASHOP',
'COLISSIMO_POSTAGE_MODE_MANUAL',
'COLISSIMO_USE_THERMAL_PRINTER',
'COLISSIMO_USE_ETHERNET',
'COLISSIMO_USB_PROTOCOLE',
'COLISSIMO_PRINTER_IP_ADDR',
'COLISSIMO_LABEL_FORMAT',
'COLISSIMO_DEFAULT_HS_CODE',
'COLISSIMO_EORI_NUMBER',
'COLISSIMO_ENABLE_BREXIT',
'COLISSIMO_USE_RETURN_ADDRESS',
);
/** @var array $defaultShipmentsFields */
public $defaultShipmentsFields = array(
'COLISSIMO_INSURE_SHIPMENTS',
'COLISSIMO_ENABLE_RETURN',
'COLISSIMO_AUTO_PRINT_RETURN_LABEL',
'COLISSIMO_DISPLAY_RETURN_LABEL_CUSTOMER',
'COLISSIMO_GENERATE_RETURN_LABEL_CUSTOMER',
'COLISSIMO_ENABLE_MAILBOX_RETURN',
);
/** @var array $defaultShipmentsFields */
public $filesFields = array(
'COLISSIMO_FILES_LIMIT',
'COLISSIMO_FILES_LIFETIME',
);
/** @var array $widgetFonts */
public static $widgetFonts = array(
'Arial',
'Arial Black',
'Comic Sans MS',
'Courrier New',
'Georgia',
'Impact',
'Lucida Console',
'Lucida Sans Unicode',
'Tahoma',
'Times New Roman',
'Trebuchet MS',
'Verdana',
'MS Sans Serif',
'MS Serif',
);
/** @var array $labelFormats */
public $labelFormats = array(
'PDF_A4_300dpi' => 'PDF A4 300dpi',
'PDF_10x15_300dpi' => 'PDF 10x15 300dpi',
'ZPL_10x15_203dpi' => 'ZPL 10x15 203dpi',
'ZPL_10x15_300dpi' => 'ZPL 10x15 300dpi',
'DPL_10x15_203dpi' => 'DPL 10x15 203dpi',
'DPL_10x15_300dpi' => 'DPL 10x15 300dpi',
);
/**
* @var array $usbPrinterProtocoles
*/
public $usbPrinterProtocoles = array(
'DATAMAX' => 'DATAMAX',
'INTERMEC' => 'INTERMEC',
'ZEBRA' => 'ZEBRA',
);
/** @var array $colissimoLinks */
public $colissimoLinks = array(
'en' => array(
'delivery_details' => 'https://www.colissimo.entreprise.laposte.fr/en/possibilites',
'subscribe' => 'https://www.colissimo.entreprise.laposte.fr/en/souscrire',
),
'fr' => array(
'delivery_details' => 'https://www.colissimo.entreprise.laposte.fr/fr/possibilites',
'subscribe' => 'https://www.colissimo.entreprise.laposte.fr/fr/souscrire',
),
);
/**
* ColissimoModuleConfiguration constructor.
* @param Context $context
* @param string $localPath
* @param string $pathUri
* @param string $version
*/
public function __construct(Context $context, $localPath, $pathUri, $version = '')
{
$this->context = $context;
$this->localPath = $localPath;
$this->pathUri = $pathUri;
$this->version = $version;
}
/**
* @throws Exception
* @throws SmartyException
*/
public function getContent()
{
$this->context->controller->addJS($this->localPath.'views/js/intlTelInput.min.js');
$this->context->controller->addCSS($this->localPath.'views/css/intlTelInput.css');
$this->context->smarty->assign('link', $this->context->link);
$merchantSenderAddress = new ColissimoMerchantAddress('sender');
$senderAddress = array_merge(
array_fill_keys($this->senderAddressFields, ''),
$merchantSenderAddress->toArray()
);
$merchantReturnAddress = new ColissimoMerchantAddress('return');
$returnAddress = array_merge(
array_fill_keys($this->returnAddressFields, ''),
$merchantReturnAddress->toArray()
);
$orderStatuses = OrderState::getOrderStates($this->context->language->id);
$states = array();
foreach ($orderStatuses as $orderStatus) {
$states[(int) $orderStatus['id_order_state']] = $orderStatus['name'];
}
$accountFieldsValue = Configuration::getMultiple($this->accountFields);
$accountFieldsValue['COLISSIMO_ACCOUNT_TYPE'] = json_decode(Configuration::get('COLISSIMO_ACCOUNT_TYPE'), true);
$widgetFieldsValue = Configuration::getMultiple($this->widgetFields);
$backFieldsValue = Configuration::getMultiple($this->backFields);
$backFieldsValue['COLISSIMO_GENERATE_LABEL_STATUSES'] = json_decode(
Configuration::get('COLISSIMO_GENERATE_LABEL_STATUSES'),
true
);
$defaultShipmentsFieldsValue = Configuration::getMultiple($this->defaultShipmentsFields);
$filesFieldsValue = ColissimoTools::getMultipleGlobal($this->filesFields);
$formData = array_merge(
$senderAddress,
$returnAddress,
$accountFieldsValue,
$widgetFieldsValue,
$backFieldsValue,
$defaultShipmentsFieldsValue,
$filesFieldsValue
);
$isoLang = Language::getIsoById($this->context->language->id);
//@formatter:off
$colissimoLinks = isset($this->colissimoLinks[$isoLang]) ? $this->colissimoLinks[$isoLang] : $this->colissimoLinks['en'];
//@formatter:on
$showMigration = $this->mustShowMigration();
if ($showMigration) {
$this->context->controller->addJS($this->localPath.'views/js/colissimo.migration.js');
if (Shop::getContext() != Shop::CONTEXT_ALL) {
Shop::setContext(Shop::CONTEXT_ALL);
}
}
$documentsDirData = ColissimoTools::getDocumentsDirDetails(dirname(__FILE__).'/../documents/');
$formData['documents_dir_size'] = ColissimoTools::formatDirectorySize($documentsDirData['total_size']);
$formData['documents_dir_count'] = $documentsDirData['count'];
$countriesList = array();
$isoSender = array_merge(ColissimoTools::$isoSender, ColissimoTools::$isoOutreMer);
foreach ($isoSender as $iso) {
$countriesList[$iso] = Country::getNameById($this->context->language->id, Country::getByIso($iso));
}
$this->context->smarty->assign(
array(
'form_data' => $formData,
'address_countries' => $countriesList,
'widget_fonts' => self::$widgetFonts,
'label_formats' => $this->labelFormats,
'usb_protocoles' => $this->usbPrinterProtocoles,
'order_states' => $states,
'colissimo_img_path' => $this->pathUri.'views/img/',
'colissimo_links' => $colissimoLinks,
'show_migration' => $showMigration,
'modules_to_migrate' => array_reverse($this->modulesToMigrate),
'module_version' => $this->version,
)
);
$tpl = $this->context->smarty->fetch($this->localPath.'views/templates/admin/configuration/layout.config.tpl');
return $tpl;
}
/**
* @return bool
*/
public function mustShowMigration()
{
if ((int) Configuration::getGlobalValue('COLISSIMO_SHOW_MIGRATION') === -1) {
return false;
}
foreach ($this->migrateModuleFromList as $module) {
if (Module::isInstalled($module) && Module::isEnabled($module)) {
$this->modulesToMigrate[] = $module;
}
}
return !empty($this->modulesToMigrate);
}
}

View File

@@ -0,0 +1,262 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoOrder
*/
class ColissimoOrder extends ObjectModel
{
/** @var int $id_colissimo_order */
public $id_colissimo_order;
/** @var int $id_order */
public $id_order;
/** @var int $id_colissimo_service */
public $id_colissimo_service;
/** @var int $id_colissimo_pickup_point */
public $id_colissimo_pickup_point;
/** @var bool $migration Flag to indicate if the label has been migrated from other module */
public $migration;
/** @var bool $hidden */
public $hidden;
/** @var array $definition */
public static $definition = array(
'table' => 'colissimo_order',
'primary' => 'id_colissimo_order',
'fields' => array(
'id_order' => array(
'type' => self::TYPE_INT,
'validate' => 'isNullOrUnsignedId',
'required' => true,
),
'id_colissimo_service' => array(
'type' => self::TYPE_INT,
'validate' => 'isNullOrUnsignedId',
'required' => false,
'default' => 0,
),
'id_colissimo_pickup_point' => array(
'type' => self::TYPE_INT,
'validate' => 'isNullOrUnsignedId',
'required' => false,
'default' => 0,
),
'migration' => array(
'type' => self::TYPE_BOOL,
'validate' => 'isBool',
'required' => true,
'default' => 0,
),
'hidden' => array(
'type' => self::TYPE_BOOL,
'validate' => 'isBool',
'required' => true,
'default' => 0,
),
),
);
/**
* @param int $idLang
* @return array|bool
* @throws PrestaShopDatabaseException
*/
public function getShipments($idLang)
{
return self::getShipmentsByColissimoOrderId($this->id, $idLang);
}
/**
* @param int $idColissimoOrder
* @param int $idLang
* @return array
* @throws PrestaShopDatabaseException
*/
public static function getShipmentsByColissimoOrderId($idColissimoOrder, $idLang)
{
$shipments = array();
$colissimoOrder = new self((int) $idColissimoOrder);
$labelIds = $colissimoOrder->getLabelIds(true);
if (!$labelIds) {
return array();
}
foreach ($labelIds as $labelId) {
$label = new ColissimoLabel((int) $labelId);
$tracking = $label->getLastTrackingDetailsKnown();
if (!$label->return_label) {
$shipments[$label->id]['id_label'] = $label->id;
$shipments[$label->id]['shipping_number'] = $label->shipping_number;
$shipments[$label->id]['cn23'] = $label->cn23;
$shipments[$label->id]['id_deposit_slip'] = $label->id_colissimo_deposit_slip;
$shipments[$label->id]['status_text'] = $tracking['status_text'];
$shipments[$label->id]['status_upd'] = $tracking['date_upd'];
$shipments[$label->id]['coliship'] = $label->coliship;
$shipments[$label->id]['insurance'] = $label->insurance;
$shipments[$label->id]['migration'] = $label->migration;
$shipments[$label->id]['file_deleted'] = $label->file_deleted;
try {
$base64 = base64_encode(Tools::file_get_contents($label->getFilePath()));
$shipments[$label->id]['base64'] = $base64;
} catch (Exception $e) {
$shipments[$label->id]['base64'] = '';
}
try {
$base64 = $label->cn23 ? base64_encode(Tools::file_get_contents($label->getCN23Path())) : '';
$shipments[$label->id]['cn23_base64'] = $base64;
} catch (Exception $e) {
$shipments[$label->id]['cn23_base64'] = '';
}
$colissimoService = new ColissimoService((int) $colissimoOrder->id_colissimo_service);
$order = new Order((int) $colissimoOrder->id_order);
if ($colissimoService->is_pickup) {
$deliveryAddr = new Address((int) $order->id_address_invoice);
} else {
$deliveryAddr = new Address((int) $order->id_address_delivery);
}
$isoCountry = Country::getIsoById($deliveryAddr->id_country);
$shipments[$label->id]['return_available'] = (bool) ColissimoTools::getReturnDestinationTypeByIsoCountry(
$isoCountry
);
$shipments[$label->id]['is_printable_pdf'] = $label->label_format == 'pdf' ? true : false;
$shipments[$label->id]['is_deletable'] = $label->isDeletable();
$shipments[$label->id]['is_downloadable'] = $label->isDownloadable();
} else {
$shipments[$label->return_label]['id_return_label'] = $label->id;
$shipments[$label->return_label]['return_shipping_number'] = $label->shipping_number;
$shipments[$label->return_label]['return_cn23'] = $label->cn23;
$shipments[$label->return_label]['return_coliship'] = $label->coliship;
$shipments[$label->return_label]['return_insurance'] = $label->insurance;
$shipments[$label->return_label]['return_migration'] = $label->migration;
$shipments[$label->return_label]['return_file_deleted'] = $label->file_deleted;
$shipments[$label->return_label]['return_is_deletable'] = $label->isDeletable();
$shipments[$label->return_label]['return_is_downloadable'] = $label->isDownloadable();
try {
$base64 = base64_encode(Tools::file_get_contents($label->getFilePath()));
$shipments[$label->return_label]['return_base64'] = $base64;
} catch (Exception $e) {
$shipments[$label->return_label]['return_base64'] = '';
}
try {
$base64 = $label->cn23 ? base64_encode(Tools::file_get_contents($label->getCN23Path())) : '';
$shipments[$label->return_label]['return_cn23_base64'] = $base64;
} catch (Exception $e) {
$shipments[$label->return_label]['return_cn23_base64'] = '';
}
}
}
return $shipments;
}
/**
* @param int $idOrder
* @return int
*/
public static function exists($idOrder)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_order')
->from('colissimo_order')
->where('id_order = '.(int) $idOrder);
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
/**
* @param bool $includeReturns
* @return array|false|mysqli_result|null|PDOStatement|resource
* @throws PrestaShopDatabaseException
*/
public function getLabelIds($includeReturns = false)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_label')
->from('colissimo_label')
->where('id_colissimo_order = '.(int) $this->id);
if (!$includeReturns) {
$dbQuery->where('return_label = 0');
}
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($dbQuery);
if ($result && is_array($result)) {
return array_map(
function ($element) {
return $element['id_colissimo_label'];
},
$result
);
}
return $result;
}
/**
* @param int $idOrder
* @return int
*/
public static function getIdByOrderId($idOrder)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_order')
->from('colissimo_order')
->where('id_order = '.(int) $idOrder);
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
/**
* @param int $idCustomer
* @param int $idShop
* @return array
* @throws PrestaShopDatabaseException
*/
public static function getCustomerColissimoOrderIds($idCustomer, $idShop)
{
$dbQuery = new DbQuery();
$dbQuery->select('co.id_colissimo_order')
->from('colissimo_order', 'co')
->leftJoin('orders', 'o', 'o.id_order = co.id_order')
->where('o.id_customer = '.(int) $idCustomer.' AND o.id_shop = '.$idShop)
->orderBy('o.date_add DESC');
$ids = array_map(
function ($element) {
return $element['id_colissimo_order'];
},
Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($dbQuery)
);
return $ids;
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoOrderCarrier
*/
class ColissimoOrderCarrier extends OrderCarrier
{
/**
* @param int $idOrder
* @return ColissimoOrderCarrier
*/
public static function getByIdOrder($idOrder)
{
$dbQuery = new DbQuery();
$dbQuery->select(self::$definition['primary'])
->from(self::$definition['table'])
->where('id_order = '.(int) $idOrder);
$id = Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
return new self((int) $id);
}
/**
* @param int $idOrder
* @return array|false|mysqli_result|null|PDOStatement|resource
*/
public static function getAllByIdOrder($idOrder)
{
$dbQuery = new DbQuery();
$dbQuery->select('*')
->from(self::$definition['table'])
->where('id_order = '.(int) $idOrder);
try {
$orderCarriers = Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($dbQuery);
} catch (PrestaShopException $e) {
return array();
}
return $orderCarriers;
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoPickupPoint
*/
class ColissimoPickupPoint extends ObjectModel
{
/** @var int $id_colissimo_pickup_point */
public $id_colissimo_pickup_point;
/** @var string $colissimo_id */
public $colissimo_id;
/** @var string $company_name */
public $company_name;
/** @var string $address1 */
public $address1;
/** @var string $address2 */
public $address2;
/** @var string $address3 */
public $address3;
/** @var string $city */
public $city;
/** @var string $zipcode */
public $zipcode;
/** @var string $country */
public $country;
/** @var string $iso_country */
public $iso_country;
/** @var string $product_code */
public $product_code;
/** @var string $network */
public $network;
/** @var string $date_add */
public $date_add;
/** @var string $date_upd */
public $date_upd;
//@formatter:off
/** @var array $definition */
public static $definition = array(
'table' => 'colissimo_pickup_point',
'primary' => 'id_colissimo_pickup_point',
'fields' => array(
'colissimo_id' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 8),
'company_name' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 64),
'address1' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 120),
'address2' => array('type' => self::TYPE_STRING, 'required' => false, 'size' => 120),
'address3' => array('type' => self::TYPE_STRING, 'required' => false, 'size' => 120),
'city' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 80),
'zipcode' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 10),
'country' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 64),
'iso_country' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 2),
'product_code' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 3),
'network' => array('type' => self::TYPE_STRING, 'required' => false, 'size' => 10),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
),
);
/** @var array $availableIso Countries that allow pickup point (22 ISO) */
public static $availableIso = array('AD', 'AT', 'BE', 'DE', 'ES', 'FR', 'EE', 'GB', 'HU', 'LT', 'LU', 'LV', 'MC', 'NL', 'PL', 'PT', 'SE', 'DK', 'FI', 'CZ', 'SK', 'SI');
/** @var array $availableLanguages Available languages in the popup (7 languages) */
public static $availableLanguages = array('fr', 'en', 'es', 'it', 'pt', 'nl', 'de');
/** @var array $BPRAliases Product codes NOT TO USE -- Instead use BPR */
public static $BPRAliases = array('ACP', 'CDI');
//formatter:on
/**
* @param string $colissimoId
* @return ColissimoPickupPoint
*/
public static function getPickupPointByIdColissimo($colissimoId)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_pickup_point')
->from('colissimo_pickup_point')
->where('colissimo_id = "'.pSQL($colissimoId).'"');
$id = Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
return new self((int) $id);
}
/**
* @return string
*/
public function getProductCodeForAffranchissement()
{
if (in_array($this->product_code, self::$BPRAliases)) {
return 'BPR';
}
return $this->product_code;
}
}

View File

@@ -0,0 +1,260 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoService
*/
class ColissimoService extends ObjectModel
{
const TYPE_RELAIS = 'RELAIS';
const TYPE_RETOUR = 'RETOUR';
const TYPE_SIGN = 'AVEC_SIGNATURE';
const TYPE_NOSIGN = 'SANS_SIGNATURE';
/** @var int $id_carrier */
public $id_carrier;
/** @var string $product_code */
public $product_code;
/** @var string $commercial_name */
public $commercial_name;
/** @var string $destination_type Destination of the service (FRANCE, EUROPE, OM, WORLDWIDE) */
public $destination_type;
/** @var bool $is_signature Flag to indicate if the service requires signature at the delivery */
public $is_signature;
/** @var bool $is_pickup Flag to indicate if the delivery is in Pickup-point */
public $is_pickup;
/** @var bool $return Flag to indicate if the service is related to return shipments */
public $is_return;
/** @var string $type */
public $type;
/** @var array $definition */
public static $definition = array(
'table' => 'colissimo_service',
'primary' => 'id_colissimo_service',
'fields' => array(
'id_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'),
'product_code' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 5),
'commercial_name' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 50),
'destination_type' => array('type' => self::TYPE_STRING, 'required' => true, 'size' => 10),
'is_signature' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
'is_pickup' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
'is_return' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
'type' => array('type' => self::TYPE_STRING, 'required' => true),
),
);
/** @var array $insurableProducts */
public static $insurableProducts = array('COL', 'BPR', 'A2P', 'CDS', 'CORE', 'CORI', 'COLI');
/** @var array $unavailableMachinableProductCodes */
public static $unavailableMachinableProductCodes = array('BPR', 'A2P', 'CMT');
/**
* @param string $isoCode
* @return bool
*/
public function isInsurable($isoCode)
{
//@formatter:off
if (in_array($this->product_code, self::$insurableProducts) || ($this->product_code == 'DOS' && $isoCode == 'FR')) {
return true;
}
//@formatter:off
return false;
}
/**
* @return bool
*/
public function isMachinableOptionAvailable()
{
return !in_array($this->product_code, self::$unavailableMachinableProductCodes);
}
/**
* @param bool $excludeReturn
* @return array|false|mysqli_result|null|PDOStatement|resource
* @throws PrestaShopDatabaseException
*/
public static function getAll($excludeReturn = true)
{
$dbQuery = new DbQuery();
$dbQuery->select('*')
->from('colissimo_service');
if ($excludeReturn) {
$dbQuery->where('is_return = 0');
}
return Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($dbQuery);
}
/**
* @param int $idCarrierReference
* @param string $destinationType
* @return int
*/
public static function getServiceIdByIdCarrierDestinationType($idCarrierReference, $destinationType)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_service')
->from('colissimo_service')
->where(
'id_carrier = '.(int) $idCarrierReference.' AND destination_type = "'.pSQL($destinationType).'"'
);
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
/**
* @param string $productCode
* @param string $destinationType
* @return int
*/
public static function getServiceIdByProductCodeDestinationType($productCode, $destinationType)
{
//@formatter:off
if (in_array($productCode, ColissimoPickupPoint::$BPRAliases)) {
$productCode = 'BPR';
}
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_service')
->from('colissimo_service')
->where('product_code = "'.pSQL($productCode).'" AND destination_type = "'.pSQL($destinationType).'"');
//@formatter:on
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
/**
* @param int $idCarrier
* @return false|null|string
*/
public static function getServiceTypeByIdCarrier($idCarrier)
{
$dbQuery = new DbQuery();
$dbQuery->select('type')
->from('colissimo_service')
->where('id_carrier = '.(int) $idCarrier);
return Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
/**
* @param string $destinationType
* @param bool $includeReturn
* @return array|false|string|null
* @throws PrestaShopDatabaseException
*/
public static function getServiceIdsByDestinationType($destinationType, $includeReturn = false)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_service')
->from('colissimo_service')
->where('destination_type = "'.pSQL($destinationType).'"');
if (!$includeReturn) {
$dbQuery->where('is_return = 0');
}
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($dbQuery);
if ($result && is_array($result)) {
return array_map(
function ($element) {
return $element['id_colissimo_service'];
},
$result
);
}
return $result;
}
/**
* @param string $isoCountryCustomer
* @param array $accountType
* @return bool
*/
public function isEligibleToAccount($isoCountryCustomer, $accountType)
{
$availableIso = ColissimoPickupPoint::$availableIso;
if (Configuration::get('COLISSIMO_ENABLE_BREXIT')) {
$availableIso = array_diff($availableIso, array('GB'));
}
//@formatter:off
$destinationWorldWideEU = array(ColissimoTools::DEST_EU, ColissimoTools::DEST_WORLD);
if (in_array($this->destination_type, $destinationWorldWideEU) && !isset($accountType[$this->destination_type])) {
return false;
}
//@formatter:on
if ($this->type == ColissimoService::TYPE_RELAIS) {
if (!in_array($isoCountryCustomer, $availableIso)) {
return false;
}
}
if ($this->destination_type == ColissimoTools::DEST_EU &&
$this->is_signature == 0 &&
$this->type != ColissimoService::TYPE_RELAIS
) {
if (!in_array($isoCountryCustomer, ColissimoTools::$isoEUCountriesZone1Zone3)) {
return false;
}
}
if ($this->destination_type == ColissimoTools::DEST_OM &&
!isset($accountType[$this->destination_type])
) {
return false;
}
return true;
}
/**
* @param int $id
* @return false|string|null
*/
public static function getServiceTypeById($id)
{
$dbQuery = new DbQuery();
$dbQuery->select('type')
->from('colissimo_service')
->where('id_colissimo_service = '.(int) $id);
return Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,115 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoTrackingCode
*/
class ColissimoTrackingCode extends ObjectModel
{
const TYPO_DELIVERED = 'LIV';
const TYPO_SHIPPED = 'SHI';
const TYPO_ANOMALY = 'ANO';
const EVENT_WAITING_SHIPMENT_HANDLING = 'COMCFM';
/** @var int $id_colissimo_tracking_code */
public $id_colissimo_tracking_code;
/** @var string $clp_code */
public $clp_code;
/** @var string $inovert_code */
public $inovert_code;
/** @var string $typology Typology of the event ("LIV" / "ANO"...) */
public $typology;
/** @var string $internal_text */
public $internal_text;
/** @var array $definition */
public static $definition = array(
'table' => 'colissimo_tracking_code',
'primary' => 'id_colissimo_tracking_code',
'fields' => array(
'clp_code' => array(
'type' => self::TYPE_STRING,
'validate' => 'isGenericName',
'required' => true,
'size' => 10,
),
'inovert_code' => array(
'type' => self::TYPE_STRING,
'validate' => 'isGenericName',
'required' => false,
'size' => 10,
),
'typology' => array(
'type' => self::TYPE_STRING,
'validate' => 'isGenericName',
'required' => false,
'size' => 10,
),
'internal_text' => array(
'type' => self::TYPE_STRING,
'validate' => 'isGenericName',
'required' => true,
'size' => 255,
),
),
);
/**
* @param string $inovertCode
* @return mixed
*/
public static function getTypologyByInovertCode($inovertCode)
{
$dbQuery = new DbQuery();
$dbQuery->select('typology')
->from('colissimo_tracking_code')
->where('inovert_code = "'.pSQL($inovertCode).'"');
return Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
}
/**
* @param string $clpCode
* @return ColissimoTrackingCode
*/
public static function getByClpCode($clpCode)
{
$dbQuery = new DbQuery();
$dbQuery->select('id_colissimo_tracking_code')
->from('colissimo_tracking_code')
->where('clp_code = "'.pSQL($clpCode).'"');
$id = Db::getInstance(_PS_USE_SQL_SLAVE_)
->getValue($dbQuery);
return new self((int) $id);
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,63 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class AbstractColissimoHandler
*/
abstract class AbstractColissimoHandler
{
/**
*
*/
public function __destruct()
{
$this->close();
}
/**
* @param string $level
* @param string $message
* @param string $channel
* @param array $details
* @return mixed
*/
abstract public function log($level, $message, $channel, $details);
/**
* @param string $level
* @param string $message
* @param string $channel
* @param string $xmlString
* @return mixed
*/
abstract public function logXml($level, $message, $channel, $xmlString);
/**
* @return bool
*/
abstract public function close();
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoFileHandler
*/
class ColissimoFileHandler extends AbstractColissimoHandler
{
/** @var bool|resource $fd */
protected $fd;
/**
* ColissimoFileHandler constructor.
* @param string $file
*/
public function __construct($file)
{
$this->fd = @fopen($file, 'a+');
}
/**
* @param string $level
* @param string $message
* @param string $channel
* @param array $details
* @return bool
*/
public function log($level, $message, $channel, $details)
{
if (is_resource($this->fd)) {
$string =
sprintf('[%s] %s.%s: %s %s', date('Y-m-d H:i:s'), $channel, $level, $message, json_encode($details));
@fwrite($this->fd, $string." []\r\n");
}
return true;
}
/**
* @param string $level
* @param string $message
* @param string $channel
* @param string $requestArray
* @return bool
*/
public function logXml($level, $message, $channel, $requestArray)
{
return $this->log($level, $message, $channel, array('xml' => json_decode($requestArray, true)));
}
/**
* @return bool
*/
public function close()
{
if (is_resource($this->fd)) {
return fclose($this->fd);
}
return true;
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoLogger
*/
class ColissimoLogger
{
const LEVEL_INFO = 'INFO';
const LEVEL_WARNING = 'WARNING';
const LEVEL_ERROR = 'ERROR';
/** @var AbstractColissimoHandler $handler */
protected $handler;
/** @var string $channel */
protected $channel;
/** @var string $version */
protected $version;
/**
* DhlLogger constructor.
* @param AbstractColissimoHandler $handler
* @param string $version
*/
public function __construct($handler, $version)
{
$this->handler = $handler;
$this->channel = 'Unknown';
$this->version = str_replace('.', '_', $version);
}
/**
* @param string $channel
*/
public function setChannel($channel)
{
$this->channel = 'Colissimo_'.$this->version.'_'.$channel;
}
/**
* @param string $message
* @param array $details
*/
public function info($message, $details = array())
{
$this->handler->log(self::LEVEL_INFO, $message, $this->channel, $details);
}
/**
* @param string $message
* @param string $xmlString
*/
public function infoXml($message, $xmlString)
{
$this->handler->logXml(self::LEVEL_INFO, $message, $this->channel, $xmlString);
}
/**
* @param string $message
* @param array $details
*/
public function warning($message, $details = array())
{
$this->handler->log(self::LEVEL_WARNING, $message, $this->channel, $details);
}
/**
* @param string $message
* @param array $details
*/
public function error($message, $details = array())
{
$this->handler->log(self::LEVEL_ERROR, $message, $this->channel, $details);
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoNullHandler
*/
class ColissimoNullHandler extends AbstractColissimoHandler
{
/**
* @param string $level
* @param string $message
* @param string $channel
* @param array $details
* @return bool
*/
public function log($level, $message, $channel, $details)
{
return true;
}
/**
* @param string $level
* @param string $message
* @param string $channel
* @param string $xmlString
* @return bool
*/
public function logXml($level, $message, $channel, $xmlString)
{
return true;
}
/**
* @return bool
*/
public function close()
{
return true;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,256 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoColissimoSimpliciteMigration
*/
class ColissimoColissimoSimpliciteMigration implements ColissimoOtherModuleInterface
{
/** @var ColissimoLogger $logger */
protected $logger;
/**
* ColissimoColissimoSimpliciteMigration constructor.
* @param ColissimoLogger $logger
*/
public function __construct(ColissimoLogger $logger)
{
$this->logger = $logger;
}
/**
* @return bool
*/
public function migrateCredentials()
{
if (Configuration::getGlobalValue('COLISSIMO_MIGRATION_CREDENTIALS') == 1) {
return true;
}
$login = Configuration::getMultiShopValues('COLISSIMO_LOGIN');
$passwd = Configuration::getMultiShopValues('COLISSIMO_PASSWORD');
$shops = Shop::getShops();
foreach ($shops as $shop) {
if ($login[$shop['id_shop']] && $passwd[$shop['id_shop']]) {
Configuration::updateValue(
'COLISSIMO_ACCOUNT_LOGIN',
$login[$shop['id_shop']],
false,
null,
$shop['id_shop']
);
Configuration::updateValue(
'COLISSIMO_ACCOUNT_PASSWORD',
$passwd[$shop['id_shop']],
false,
null,
$shop['id_shop']
);
}
}
return true;
}
/**
* @return bool
*/
public function migrateCarriers()
{
$idCarrier = Configuration::getGlobalValue('COLISSIMO_CARRIER_ID');
Db::getInstance()
->update('carrier', array('active' => 0), 'id_carrier = '.(int) $idCarrier);
return true;
}
/**
* @return bool
*/
public function migrateConfiguration()
{
$preparationTime = Configuration::getMultiShopValues('COLISSIMO_PREPARATION_TIME');
$shops = Shop::getShops();
foreach ($shops as $shop) {
Configuration::updateValue(
'COLISSIMO_ORDER_PREPARATION_TIME',
$preparationTime[$shop['id_shop']],
false,
null,
$shop['id_shop']
);
}
return true;
}
/**
* @return bool
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function migrateData()
{
$tableExists = Db::getInstance()
->executeS('SHOW TABLES LIKE "'._DB_PREFIX_.'colissimo_delivery_point"');
if (!empty($tableExists)) {
$oldThirdPatyOrdersQuery = new DbQuery();
$oldThirdPatyOrdersQuery->select('*')
->from('colissimo_delivery_point');
$oldThirdPartyOrders = Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($oldThirdPatyOrdersQuery);
foreach ($oldThirdPartyOrders as $oldThirdPartyOrder) {
$pickupPointReference = $oldThirdPartyOrder['identifiant'];
$order = ColissimoTools::getOrderByCartId((int) $oldThirdPartyOrder['id_cart']);
if (!Validate::isLoadedObject($order)) {
continue;
}
$deliveryAddr = new Address((int) $order->id_address_delivery);
$deliveryMode = $oldThirdPartyOrder['typeDePoint'];
$destinationType = ColissimoTools::getDestinationTypeByIsoCountry(
Country::getIsoById($deliveryAddr->id_country)
);
$idService = ColissimoService::getServiceIdByProductCodeDestinationType(
$deliveryMode,
$destinationType
);
$idColissimoOrder = ColissimoOrder::getIdByOrderId((int) $order->id);
$colissimoOrder = new ColissimoOrder((int) $idColissimoOrder);
$colissimoOrder->id_colissimo_pickup_point = 0;
if ($pickupPointReference) {
$colissimoPickupPoint = ColissimoPickupPoint::getPickupPointByIdColissimo($pickupPointReference);
if (!Validate::isLoadedObject($colissimoPickupPoint)) {
$colissimoPickupPoint->colissimo_id = pSQL($pickupPointReference);
$colissimoPickupPoint->company_name = pSQL($oldThirdPartyOrder['nom']);
$colissimoPickupPoint->address1 = pSQL($deliveryAddr->address1);
$colissimoPickupPoint->address2 = pSQL($deliveryAddr->address2);
$colissimoPickupPoint->address3 = '';
$colissimoPickupPoint->city = pSQL($deliveryAddr->city);
$colissimoPickupPoint->zipcode = pSQL($deliveryAddr->postcode);
$colissimoPickupPoint->country = pSQL(
Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), $deliveryAddr->id_country)
);
$colissimoPickupPoint->iso_country = pSQL(Country::getIsoById($deliveryAddr->id_country));
$colissimoPickupPoint->product_code = pSQL($deliveryMode);
$colissimoPickupPoint->network = pSQL($oldThirdPartyOrder['reseau']);
try {
$colissimoPickupPoint->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
$colissimoOrder->id_colissimo_pickup_point = (int) $colissimoPickupPoint->id;
}
$colissimoOrder->id_order = (int) $order->id;
$colissimoOrder->id_colissimo_service = (int) $idService;
$colissimoOrder->migration = 1;
$colissimoOrder->hidden = 0;
try {
$colissimoOrder->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
}
$tableExists = Db::getInstance()
->executeS('SHOW TABLES LIKE "'._DB_PREFIX_.'colissimo_delivery_info"');
if (!empty($tableExists)) {
$oldColissimoOrdersQuery = new DbQuery();
$oldColissimoOrdersQuery->select('*')
->from('colissimo_delivery_info');
$oldColissimoOrders = Db::getInstance()
->executeS($oldColissimoOrdersQuery);
foreach ($oldColissimoOrders as $oldOrder) {
$pickupPointReference = $oldOrder['prid'];
$order = ColissimoTools::getOrderByCartId((int) $oldOrder['id_cart']);
if (!Validate::isLoadedObject($order)) {
continue;
}
$deliveryAddr = new Address((int) $order->id_address_delivery);
$deliveryMode = $oldOrder['delivery_mode'];
$destinationType = ColissimoTools::getDestinationTypeByIsoCountry(
Country::getIsoById($deliveryAddr->id_country)
);
$idService = ColissimoService::getServiceIdByProductCodeDestinationType(
$deliveryMode,
$destinationType
);
$idColissimoOrder = ColissimoOrder::getIdByOrderId((int) $order->id);
$colissimoOrder = new ColissimoOrder((int) $idColissimoOrder);
$colissimoOrder->id_colissimo_pickup_point = 0;
if ($pickupPointReference) {
$colissimoPickupPoint = ColissimoPickupPoint::getPickupPointByIdColissimo($pickupPointReference);
if (!Validate::isLoadedObject($colissimoPickupPoint)) {
$colissimoPickupPoint->colissimo_id = pSQL($pickupPointReference);
$colissimoPickupPoint->company_name = pSQL($oldOrder['prname']);
$colissimoPickupPoint->address1 = pSQL($deliveryAddr->address1);
$colissimoPickupPoint->address2 = pSQL($deliveryAddr->address2);
$colissimoPickupPoint->address3 = '';
$colissimoPickupPoint->city = pSQL($deliveryAddr->city);
$colissimoPickupPoint->zipcode = pSQL($deliveryAddr->postcode);
$colissimoPickupPoint->country = pSQL(
Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), $deliveryAddr->id_country)
);
$colissimoPickupPoint->iso_country = pSQL(Country::getIsoById($deliveryAddr->id_country));
$colissimoPickupPoint->product_code = pSQL($oldOrder['delivery_mode']);
$colissimoPickupPoint->network = pSQL($oldOrder['codereseau']);
try {
$colissimoPickupPoint->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
$colissimoOrder->id_colissimo_pickup_point = (int) $colissimoPickupPoint->id;
}
$colissimoOrder->id_order = (int) $order->id;
$colissimoOrder->id_colissimo_service = (int) $idService;
$colissimoOrder->migration = 1;
$colissimoOrder->hidden = 0;
try {
$colissimoOrder->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
}
return true;
}
/**
* @return bool
*/
public function migrateDocuments()
{
return true;
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoMigration
*/
class ColissimoMigration
{
/** @var ColissimoOtherModuleInterface[] $otherModules */
private $otherModules;
/**
* @param ColissimoOtherModuleInterface $module
*/
public function addModule(ColissimoOtherModuleInterface $module)
{
$this->otherModules[] = $module;
}
/**
* @param string $step
* @throws Exception
*/
public function migrate($step)
{
$methodCall = Tools::toCamelCase('migrate_'.$step);
foreach ($this->otherModules as $otherModule) {
if (method_exists($otherModule, $methodCall)) {
$otherModule->$methodCall();
} else {
throw new Exception('Cannot call migration step.');
}
}
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Interface ColissimoOtherModuleInterface
*/
interface ColissimoOtherModuleInterface
{
/**
* ColissimoOtherModuleInterface constructor.
* @param ColissimoLogger $logger
*/
public function __construct(ColissimoLogger $logger);
/**
* @return bool
*/
public function migrateCredentials();
/**
* @return bool
*/
public function migrateCarriers();
/**
* @return bool
*/
public function migrateDocuments();
/**
* @return bool
*/
public function migrateConfiguration();
/**
* @return bool
*/
public function migrateData();
}

View File

@@ -0,0 +1,254 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoSocolissimoMigration
*/
class ColissimoSocolissimoMigration implements ColissimoOtherModuleInterface
{
/** @var ColissimoLogger $logger */
protected $logger;
/**
* ColissimoColissimoSimpliciteMigration constructor.
* @param ColissimoLogger $logger
*/
public function __construct(ColissimoLogger $logger)
{
$this->logger = $logger;
}
/**
* @return bool
*/
public function migrateCredentials()
{
if (Configuration::getGlobalValue('COLISSIMO_MIGRATION_CREDENTIALS') == 1) {
return true;
}
$login = Configuration::getMultiShopValues('SOCOLISSIMO_LOGIN');
$passwd = Configuration::getMultiShopValues('SOCOLISSIMO_PASSWORD');
$shops = Shop::getShops();
foreach ($shops as $shop) {
if ($login[$shop['id_shop']] && $passwd[$shop['id_shop']]) {
Configuration::updateValue(
'COLISSIMO_ACCOUNT_LOGIN',
$login[$shop['id_shop']],
false,
null,
$shop['id_shop']
);
Configuration::updateValue(
'COLISSIMO_ACCOUNT_PASSWORD',
$passwd[$shop['id_shop']],
false,
null,
$shop['id_shop']
);
}
}
return true;
}
/**
* @return bool
*/
public function migrateConfiguration()
{
$preparationTime = Configuration::getMultiShopValues('SOCOLISSIMO_PREPARATION_TIME');
$shops = Shop::getShops();
foreach ($shops as $shop) {
Configuration::updateValue(
'COLISSIMO_ORDER_PREPARATION_TIME',
$preparationTime[$shop['id_shop']],
false,
null,
$shop['id_shop']
);
}
return true;
}
/**
* @return bool
*/
public function migrateCarriers()
{
$idCarrier = Configuration::getGlobalValue('SOCOLISSIMO_CARRIER_ID');
Db::getInstance()
->update('carrier', array('active' => 0), 'id_carrier = '.(int) $idCarrier);
return true;
}
/**
* @return bool
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function migrateData()
{
$tableExists = Db::getInstance()
->executeS('SHOW TABLES LIKE "'._DB_PREFIX_.'socolissimo_delivery_point"');
if (!empty($tableExists)) {
$oldThirdPatyOrdersQuery = new DbQuery();
$oldThirdPatyOrdersQuery->select('*')
->from('socolissimo_delivery_point');
$oldThirdPartyOrders = Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($oldThirdPatyOrdersQuery);
foreach ($oldThirdPartyOrders as $oldThirdPartyOrder) {
$pickupPointReference = $oldThirdPartyOrder['identifiant'];
$order = ColissimoTools::getOrderByCartId((int) $oldThirdPartyOrder['id_cart']);
if (!Validate::isLoadedObject($order)) {
continue;
}
$deliveryAddr = new Address((int) $order->id_address_delivery);
$deliveryMode = $oldThirdPartyOrder['typeDePoint'];
$destinationType = ColissimoTools::getDestinationTypeByIsoCountry(
Country::getIsoById($deliveryAddr->id_country)
);
$idService = ColissimoService::getServiceIdByProductCodeDestinationType(
$deliveryMode,
$destinationType
);
$idColissimoOrder = ColissimoOrder::getIdByOrderId((int) $order->id);
$colissimoOrder = new ColissimoOrder((int) $idColissimoOrder);
$colissimoOrder->id_colissimo_pickup_point = 0;
if ($pickupPointReference) {
$colissimoPickupPoint = ColissimoPickupPoint::getPickupPointByIdColissimo($pickupPointReference);
if (!Validate::isLoadedObject($colissimoPickupPoint)) {
$colissimoPickupPoint->colissimo_id = pSQL($pickupPointReference);
$colissimoPickupPoint->company_name =
pSQL($oldThirdPartyOrder['nom']) ? pSQL($oldThirdPartyOrder['nom']) : ' ';
$colissimoPickupPoint->address1 = pSQL($deliveryAddr->address1);
$colissimoPickupPoint->address2 = pSQL($deliveryAddr->address2);
$colissimoPickupPoint->address3 = '';
$colissimoPickupPoint->city = pSQL($deliveryAddr->city);
$colissimoPickupPoint->zipcode = pSQL($deliveryAddr->postcode);
$colissimoPickupPoint->country = pSQL(
Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), $deliveryAddr->id_country)
);
$colissimoPickupPoint->iso_country = pSQL(Country::getIsoById($deliveryAddr->id_country));
$colissimoPickupPoint->product_code = pSQL($deliveryMode);
$colissimoPickupPoint->network = pSQL($oldThirdPartyOrder['reseau']);
try {
$colissimoPickupPoint->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
$colissimoOrder->id_colissimo_pickup_point = (int) $colissimoPickupPoint->id;
}
$colissimoOrder->id_order = (int) $order->id;
$colissimoOrder->id_colissimo_service = (int) $idService;
$colissimoOrder->migration = 1;
$colissimoOrder->hidden = 0;
try {
$colissimoOrder->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
}
$tableExists = Db::getInstance()
->executeS('SHOW TABLES LIKE "'._DB_PREFIX_.'socolissimo_delivery_info"');
if (!empty($tableExists)) {
$oldColissimoOrdersQuery = new DbQuery();
$oldColissimoOrdersQuery->select('*')
->from('socolissimo_delivery_info');
$oldColissimoOrders = Db::getInstance()
->executeS($oldColissimoOrdersQuery);
foreach ($oldColissimoOrders as $oldOrder) {
$pickupPointReference = $oldOrder['prid'];
$order = ColissimoTools::getOrderByCartId((int) $oldOrder['id_cart']);
if (!Validate::isLoadedObject($order)) {
continue;
}
$deliveryAddr = new Address((int) $order->id_address_delivery);
$deliveryMode = $oldOrder['delivery_mode'];
$destinationType = ColissimoTools::getDestinationTypeByIsoCountry(
Country::getIsoById($deliveryAddr->id_country)
);
$idService = ColissimoService::getServiceIdByProductCodeDestinationType(
$deliveryMode,
$destinationType
);
$idColissimoOrder = ColissimoOrder::getIdByOrderId((int) $order->id);
$colissimoOrder = new ColissimoOrder((int) $idColissimoOrder);
$colissimoOrder->id_colissimo_pickup_point = 0;
if ($pickupPointReference) {
$colissimoPickupPoint = ColissimoPickupPoint::getPickupPointByIdColissimo($pickupPointReference);
if (!Validate::isLoadedObject($colissimoPickupPoint)) {
$colissimoPickupPoint->colissimo_id = pSQL($pickupPointReference);
$colissimoPickupPoint->company_name =
pSQL($oldOrder['prname']) ? pSQL($oldOrder['prname']) : ' ';
$colissimoPickupPoint->address1 = pSQL($deliveryAddr->address1);
$colissimoPickupPoint->address2 = pSQL($deliveryAddr->address2);
$colissimoPickupPoint->address3 = '';
$colissimoPickupPoint->city = pSQL($deliveryAddr->city);
$colissimoPickupPoint->zipcode = pSQL($deliveryAddr->postcode);
$colissimoPickupPoint->country = pSQL(
Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), $deliveryAddr->id_country)
);
$colissimoPickupPoint->iso_country = pSQL(Country::getIsoById($deliveryAddr->id_country));
$colissimoPickupPoint->product_code = pSQL($oldOrder['delivery_mode']);
$colissimoPickupPoint->network = pSQL($oldOrder['codereseau']);
try {
$colissimoPickupPoint->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
$colissimoOrder->id_colissimo_pickup_point = (int) $colissimoPickupPoint->id;
}
$colissimoOrder->id_order = (int) $order->id;
$colissimoOrder->id_colissimo_service = (int) $idService;
$colissimoOrder->migration = 1;
try {
$colissimoOrder->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
}
return true;
}
public function migrateDocuments()
{
return true;
}
}

View File

@@ -0,0 +1,262 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoSoflexibiliteMigration
*/
class ColissimoSoflexibiliteMigration implements ColissimoOtherModuleInterface
{
const MODULE_NAME = 'soflexibilite';
/** @var ColissimoLogger $logger */
private $logger;
/**
* ColissimoSoflexibiliteMigration constructor.
* @param ColissimoLogger $logger
*/
public function __construct(ColissimoLogger $logger)
{
$this->logger = $logger;
}
/**
* @return bool
*/
public function migrateCredentials()
{
$login = Configuration::getMultiShopValues('SOFLEXIBILITE_LOGIN');
$passwd = Configuration::getMultiShopValues('SOFLEXIBILITE_PASSWORD');
$shops = Shop::getShops();
foreach ($shops as $shop) {
if ($login[$shop['id_shop']] && $passwd[$shop['id_shop']]) {
Configuration::updateValue(
'COLISSIMO_ACCOUNT_LOGIN',
$login[$shop['id_shop']],
false,
null,
$shop['id_shop']
);
Configuration::updateValue(
'COLISSIMO_ACCOUNT_PASSWORD',
$passwd[$shop['id_shop']],
false,
null,
$shop['id_shop']
);
// If Colissimo Simplicite has at least one login/pass configured, we considered that these credentials
// are the correct one. We won't try to migrate credentials from other modules.
Configuration::updateGlobalValue('COLISSIMO_MIGRATION_CREDENTIALS', 1);
}
}
return true;
}
/**
* @return bool
* @throws PrestaShopException
*/
public function migrateCarriers()
{
$correspondance = array(
'SOFLEXIBILITE_DOM_ID' => 'COLISSIMO_CARRIER_SANS_SIGNATURE',
'SOFLEXIBILITE_DOS_ID' => 'COLISSIMO_CARRIER_AVEC_SIGNATURE',
'SOFLEXIBILITE_A2P_ID' => 'COLISSIMO_CARRIER_RELAIS',
);
$flexibiliteCarrierIds = Configuration::getMultiple(
array(
'SOFLEXIBILITE_DOM_ID',
'SOFLEXIBILITE_DOS_ID',
'SOFLEXIBILITE_A2P_ID',
)
);
foreach ($flexibiliteCarrierIds as $key => $flexibiliteCarrierId) {
ColissimoTools::migrateCarrierData($flexibiliteCarrierId, $correspondance, $key);
}
Db::getInstance()
->update('carrier', array('active' => 0), 'external_module_name = "'.pSQL(self::MODULE_NAME).'"');
return true;
}
/**
* @return bool
*/
public function migrateConfiguration()
{
return true;
}
/**
* @return bool
*/
public function migrateDocuments()
{
return true;
}
/**
* @return bool
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function migrateData()
{
$tableExists = Db::getInstance()
->executeS('SHOW TABLES LIKE "'._DB_PREFIX_.'so_delivery"');
if (!empty($tableExists)) {
$oldThirdPatyOrdersQuery = new DbQuery();
$oldThirdPatyOrdersQuery->select('*')
->from('so_delivery');
$oldThirdPartyOrders = Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($oldThirdPatyOrdersQuery);
foreach ($oldThirdPartyOrders as $oldThirdPartyOrder) {
$pickupPointReference = $oldThirdPartyOrder['point_id'];
$order = ColissimoTools::getOrderByCartId((int) $oldThirdPartyOrder['cart_id']);
if (!Validate::isLoadedObject($order)) {
continue;
}
$deliveryAddr = new Address((int) $order->id_address_delivery);
$deliveryMode = $oldThirdPartyOrder['type'];
$destinationType = ColissimoTools::getDestinationTypeByIsoCountry(
Country::getIsoById($deliveryAddr->id_country)
);
$idService = ColissimoService::getServiceIdByProductCodeDestinationType(
$deliveryMode,
$destinationType
);
$idColissimoOrder = ColissimoOrder::getIdByOrderId((int) $order->id);
$colissimoOrder = new ColissimoOrder((int) $idColissimoOrder);
$colissimoOrder->id_colissimo_pickup_point = 0;
if ($pickupPointReference) {
$colissimoPickupPoint = ColissimoPickupPoint::getPickupPointByIdColissimo($pickupPointReference);
if (!Validate::isLoadedObject($colissimoPickupPoint)) {
$colissimoPickupPoint->colissimo_id = pSQL($pickupPointReference);
$colissimoPickupPoint->company_name = pSQL($deliveryAddr->company);
$colissimoPickupPoint->address1 = pSQL($deliveryAddr->address1);
$colissimoPickupPoint->address2 = pSQL($deliveryAddr->address2);
$colissimoPickupPoint->address3 = '';
$colissimoPickupPoint->city = pSQL($deliveryAddr->city);
$colissimoPickupPoint->zipcode = pSQL($deliveryAddr->postcode);
$colissimoPickupPoint->country = pSQL(
Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), $deliveryAddr->id_country)
);
$colissimoPickupPoint->iso_country = pSQL(Country::getIsoById($deliveryAddr->id_country));
$colissimoPickupPoint->product_code = pSQL($oldThirdPartyOrder['type']);
$colissimoPickupPoint->network = pSQL($oldThirdPartyOrder['codereseau']);
try {
$colissimoPickupPoint->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
$colissimoOrder->id_colissimo_pickup_point = (int) $colissimoPickupPoint->id;
}
$colissimoOrder->id_order = (int) $order->id;
$colissimoOrder->id_colissimo_service = (int) $idService;
$colissimoOrder->migration = 1;
$colissimoOrder->hidden = 0;
try {
$colissimoOrder->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
}
$tableExists = Db::getInstance()
->executeS('SHOW TABLES LIKE "'._DB_PREFIX_.'socolissimo_delivery_info"');
if (!empty($tableExists)) {
$oldColissimoOrdersQuery = new DbQuery();
$oldColissimoOrdersQuery->select('*')
->from('socolissimo_delivery_info');
$oldColissimoOrders = Db::getInstance()
->executeS($oldColissimoOrdersQuery);
foreach ($oldColissimoOrders as $oldOrder) {
$pickupPointReference = $oldOrder['prid'];
$order = ColissimoTools::getOrderByCartId((int) $oldOrder['id_cart']);
if (!Validate::isLoadedObject($order)) {
continue;
}
$deliveryAddr = new Address((int) $order->id_address_delivery);
$deliveryMode = $oldOrder['delivery_mode'];
$destinationType = ColissimoTools::getDestinationTypeByIsoCountry(
Country::getIsoById($deliveryAddr->id_country)
);
$idService = ColissimoService::getServiceIdByProductCodeDestinationType(
$deliveryMode,
$destinationType
);
$idColissimoOrder = ColissimoOrder::getIdByOrderId((int) $order->id);
$colissimoOrder = new ColissimoOrder((int) $idColissimoOrder);
$colissimoOrder->id_colissimo_pickup_point = 0;
if ($pickupPointReference) {
$colissimoPickupPoint = ColissimoPickupPoint::getPickupPointByIdColissimo($pickupPointReference);
if (!Validate::isLoadedObject($colissimoPickupPoint)) {
$colissimoPickupPoint->colissimo_id = pSQL($pickupPointReference);
$colissimoPickupPoint->company_name = pSQL($deliveryAddr->company);
$colissimoPickupPoint->address1 = pSQL($deliveryAddr->address1);
$colissimoPickupPoint->address2 = pSQL($deliveryAddr->address2);
$colissimoPickupPoint->address3 = '';
$colissimoPickupPoint->city = pSQL($deliveryAddr->city);
$colissimoPickupPoint->zipcode = pSQL($deliveryAddr->postcode);
$colissimoPickupPoint->country = pSQL(
Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), $deliveryAddr->id_country)
);
$colissimoPickupPoint->iso_country = pSQL(Country::getIsoById($deliveryAddr->id_country));
$colissimoPickupPoint->product_code = pSQL($oldOrder['delivery_mode']);
$colissimoPickupPoint->network = pSQL($oldOrder['codereseau']);
try {
$colissimoPickupPoint->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
$colissimoOrder->id_colissimo_pickup_point = (int) $colissimoPickupPoint->id;
}
$colissimoOrder->id_order = (int) $order->id;
$colissimoOrder->id_colissimo_service = (int) $idService;
$colissimoOrder->migration = 1;
$colissimoOrder->hidden = 0;
try {
$colissimoOrder->save();
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,187 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ColissimoSoniceEtiquetageMigration
*/
class ColissimoSoniceEtiquetageMigration implements ColissimoOtherModuleInterface
{
/** @var ColissimoLogger $logger */
private $logger;
/**
* ColissimoSoflexibiliteMigration constructor.
* @param ColissimoLogger $logger
*/
public function __construct(ColissimoLogger $logger)
{
$this->logger = $logger;
}
/**
* @return bool
*/
public function migrateCredentials()
{
if (Configuration::getGlobalValue('COLISSIMO_MIGRATION_CREDENTIALS') == 1) {
return true;
}
$configs = Configuration::getMultiShopValues('SONICE_ETQ_CONF');
$shops = Shop::getShops();
foreach ($shops as $shop) {
$config = unserialize($configs[$shop['id_shop']]);
if ($config['ContractNumber'] && $config['Password']) {
Configuration::updateValue(
'COLISSIMO_ACCOUNT_LOGIN',
$config['ContractNumber'],
false,
null,
$shop['id_shop']
);
Configuration::updateValue(
'COLISSIMO_ACCOUNT_PASSWORD',
$config['Password'],
false,
null,
$shop['id_shop']
);
}
}
return true;
}
/**
* @return bool
*/
public function migrateCarriers()
{
return true;
}
/**
* @return bool
*/
public function migrateConfiguration()
{
$configs = Configuration::getMultiShopValues('SONICE_ETQ_CONF');
$statuses = Configuration::getMultiShopValues('SONICE_ETQ_STATUS');
$shops = Shop::getShops();
foreach ($shops as $shop) {
$config = unserialize($configs[$shop['id_shop']]);
$selectedStatuses = unserialize($statuses[$shop['id_shop']]);
$address = array(
'sender_company' => $config['companyName'],
'sender_lastname' => $config['Surname'],
'sender_firstname' => $config['Name'],
'sender_address1' => $config['Line2'],
'sender_address2' => $config['Line0'],
'sender_address3' => '',
'sender_address4' => '',
'sender_city' => $config['City'],
'sender_zipcode' => $config['PostalCode'],
'sender_country' => 'FR',
'sender_phone' => '+33'.Tools::substr($config['phoneNumber'], -9),
'sender_email' => $config['Mail'],
);
Configuration::updateValue(
'COLISSIMO_SENDER_ADDRESS',
json_encode($address),
false,
null,
$shop['id_shop']
);
Configuration::updateValue(
'COLISSIMO_LABEL_FORMAT',
$config['output_print_type'],
false,
null,
$shop['id_shop']
);
if (is_array($selectedStatuses)) {
Configuration::updateValue(
'COLISSIMO_GENERATE_LABEL_STATUSES',
json_encode(array_fill_keys(array_values($selectedStatuses), 1)),
false,
null,
$shop['id_shop']
);
}
}
return true;
}
/**
* @return bool
*/
public function migrateData()
{
return true;
}
/**
* @return bool
* @throws PrestaShopDatabaseException
*/
public function migrateDocuments()
{
$oldLabelsQuery = new DbQuery();
$oldLabelsQuery->select('*')
->from('sonice_etq_label');
$oldLabels = Db::getInstance(_PS_USE_SQL_SLAVE_)
->executeS($oldLabelsQuery);
foreach ($oldLabels as $oldLabel) {
$idColissimoOrder = ColissimoOrder::getIdByOrderId((int) $oldLabel['id_order']);
$colissimoOrder = new ColissimoOrder((int) $idColissimoOrder);
if (!Validate::isLoadedObject($colissimoOrder)) {
$this->logger->error('Invalid ColissimoOrder object', array('id' => $idColissimoOrder));
continue;
}
$colissimoLabel = new ColissimoLabel();
$colissimoLabel->id_colissimo_order = (int) $colissimoOrder->id;
$colissimoLabel->id_colissimo_deposit_slip = 0;
$colissimoLabel->shipping_number = pSQL($oldLabel['parcel_number']);
$colissimoLabel->label_format = 'pdf';
$colissimoLabel->coliship = 0;
$colissimoLabel->return_label = 0;
$colissimoLabel->cn23 = 0;
$colissimoLabel->date_add = pSQL($oldLabel['date_add']);
$colissimoLabel->migration = 1;
$colissimoLabel->insurance = null;
$colissimoLabel->file_deleted = 0;
try {
$colissimoLabel->save(true);
} catch (Exception $e) {
$this->logger->error($e->getMessage());
continue;
}
}
return true;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,53 @@
<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
require_once(dirname(__FILE__).'/ColissimoTools.php');
require_once(dirname(__FILE__).'/ColissimoLink.php');
require_once(dirname(__FILE__).'/ColissimoModuleConfiguration.php');
require_once(dirname(__FILE__).'/ColissimoCarrier.php');
require_once(dirname(__FILE__).'/ColissimoService.php');
require_once(dirname(__FILE__).'/ColissimoOrder.php');
require_once(dirname(__FILE__).'/ColissimoLabel.php');
require_once(dirname(__FILE__).'/ColissimoDepositSlip.php');
require_once(dirname(__FILE__).'/ColissimoLabelGenerator.php');
require_once(dirname(__FILE__).'/ColissimoPickupPoint.php');
require_once(dirname(__FILE__).'/ColissimoCartPickupPoint.php');
require_once(dirname(__FILE__).'/ColissimoTrackingCode.php');
require_once(dirname(__FILE__).'/ColissimoOrderCarrier.php');
require_once(dirname(__FILE__).'/ColissimoCustomCategory.php');
require_once(dirname(__FILE__).'/ColissimoCustomProduct.php');
require_once(dirname(__FILE__).'/ColissimoMerchantAddress.php');
require_once(dirname(__FILE__).'/ColissimoACE.php');
require_once(dirname(__FILE__).'/migration/ColissimoOtherModuleInterface.php');
require_once(dirname(__FILE__).'/migration/ColissimoMigration.php');
require_once(dirname(__FILE__).'/migration/ColissimoSoflexibiliteMigration.php');
require_once(dirname(__FILE__).'/migration/ColissimoSoniceEtiquetageMigration.php');
require_once(dirname(__FILE__).'/migration/ColissimoColissimoSimpliciteMigration.php');
require_once(dirname(__FILE__).'/migration/ColissimoSocolissimoMigration.php');
require_once(dirname(__FILE__).'/logger/AbstractColissimoHandler.php');
require_once(dirname(__FILE__).'/logger/ColissimoFileHandler.php');
require_once(dirname(__FILE__).'/logger/ColissimoNullHandler.php');
require_once(dirname(__FILE__).'/logger/ColissimoLogger.php');