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,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;