first commit

This commit is contained in:
2024-11-05 12:22:50 +01:00
commit e5682a3912
19641 changed files with 2948548 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
namespace InPost\Shipping\Install;
use Carrier;
use InPostShipping;
use PrestaShopCollection;
class Carriers implements InstallerInterface
{
/**
* @var InPostShipping
*/
protected $module;
public function __construct(InPostShipping $module)
{
$this->module = $module;
}
public function install()
{
return true;
}
public function uninstall()
{
$result = true;
$collection = (new PrestaShopCollection(Carrier::class))
->where('is_module', '=', true)
->where('deleted', '=', false)
->where('external_module_name', 'LIKE', $this->module->name);
/** @var Carrier $carrier */
foreach ($collection as $carrier) {
$carrier->deleted = true;
$carrier->is_module = false;
$carrier->external_module_name = null;
$carrier->active = false;
$result &= $carrier->update();
}
return $result;
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
namespace InPost\Shipping\Install;
use InPost\Shipping\Configuration\AbstractConfiguration;
class Configuration implements InstallerInterface
{
/**
* @var AbstractConfiguration[]
*/
protected $configurations;
/**
* @param AbstractConfiguration[] $configurations
*/
public function __construct(array $configurations)
{
$this->configurations = array_filter($configurations, function ($configuration) {
return $configuration instanceof AbstractConfiguration;
});
}
public function install()
{
$result = true;
foreach ($this->configurations as $configuration) {
$result &= $configuration->setDefaults();
}
return $result;
}
public function uninstall()
{
$result = true;
foreach ($this->configurations as $configuration) {
$result &= $configuration->reset();
}
return $result;
}
}

View File

@@ -0,0 +1,277 @@
<?php
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
namespace InPost\Shipping\Install;
use Db;
use InPost\Shipping\PrestaShopContext;
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
use InPost\Shipping\ShipX\Resource\SendingMethod;
use InPost\Shipping\ShipX\Resource\Service;
use InPost\Shipping\ShipX\Resource\Status;
use InPostShipmentStatusModel;
use Language;
class Database implements InstallerInterface
{
const ID_LANG_DEF_16 = 'INT(10) UNSIGNED NOT NULL';
const ID_LANG_DEF_17 = 'INT(11) NOT NULL';
protected $shopContext;
protected $db;
public function __construct(PrestaShopContext $shopContext)
{
$this->shopContext = $shopContext;
$this->db = Db::getInstance();
}
public function install()
{
return $this->createTables()
&& $this->addStatuses();
}
public function createTables()
{
$result = true;
$services = '"' . implode('","', Service::SERVICES) . '"';
$templates = '"' . implode('","', Shipment::DIMENSION_TEMPLATES) . '"';
$idLangDef = $this->shopContext->is17()
? self::ID_LANG_DEF_17
: self::ID_LANG_DEF_16;
$result &= $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'inpost_shipment_status` (
`id_status` INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
`name` VARCHAR(64) NOT NULL,
PRIMARY KEY (`id_status`),
UNIQUE (`name`)
)
ENGINE = ' . _MYSQL_ENGINE_ . '
CHARSET = utf8
COLLATE = utf8_general_ci
');
$result &= $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'inpost_shipment_status_lang` (
`id_status` INT(10) UNSIGNED NOT NULL,
`id_lang` ' . $idLangDef . ',
`title` VARCHAR(128) NOT NULL,
`description` VARCHAR(512) NOT NULL,
PRIMARY KEY (`id_status`, `id_lang`),
FOREIGN KEY (`id_status`)
REFERENCES `' . _DB_PREFIX_ . 'inpost_shipment_status` (`id_status`)
ON DELETE CASCADE,
FOREIGN KEY (`id_lang`)
REFERENCES `' . _DB_PREFIX_ . 'lang` (`id_lang`)
ON DELETE CASCADE
)
ENGINE = ' . _MYSQL_ENGINE_ . '
CHARSET = utf8
COLLATE = utf8_general_ci
');
$result &= $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'inpost_carrier` (
`id_reference` INT(10) UNSIGNED NOT NULL,
`service` ENUM(' . $services . ') NOT NULL,
`cod` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
`weekend_delivery` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
`use_product_dimensions` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`id_reference`),
FOREIGN KEY (`id_reference`)
REFERENCES `' . _DB_PREFIX_ . 'carrier` (`id_reference`)
ON DELETE CASCADE
)
ENGINE = ' . _MYSQL_ENGINE_ . '
CHARSET = utf8
COLLATE = utf8_general_ci
');
$result &= $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'inpost_cart_choice` (
`id_cart` INT(10) UNSIGNED NOT NULL,
`service` ENUM(' . $services . ') NOT NULL,
`email` VARCHAR(255),
`phone` VARCHAR(255),
`point` VARCHAR(32),
PRIMARY KEY (`id_cart`)
)
ENGINE = ' . _MYSQL_ENGINE_ . '
CHARSET = utf8
COLLATE = utf8_general_ci
');
$result &= $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'inpost_dispatch_point` (
`id_dispatch_point` INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`office_hours` VARCHAR(255),
`email` VARCHAR(255),
`phone` VARCHAR(255),
`street` VARCHAR(255) NOT NULL,
`building_number` VARCHAR(255) NOT NULL,
`post_code` CHAR(6) NOT NULL,
`city` VARCHAR(255) NOT NULL,
`deleted` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`id_dispatch_point`)
)
ENGINE = ' . _MYSQL_ENGINE_ . '
CHARSET = utf8
COLLATE = utf8_general_ci
');
$result &= $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'inpost_dispatch_order` (
`id_dispatch_order` INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
`id_dispatch_point` INT(10) UNSIGNED,
`shipx_dispatch_order_id` INT(10) UNSIGNED NOT NULL,
`number` INT(10) UNSIGNED,
`status` VARCHAR(64),
`price` DECIMAL(20,6),
`date_add` DATETIME NOT NULL,
PRIMARY KEY (`id_dispatch_order`),
FOREIGN KEY (`id_dispatch_point`)
REFERENCES `' . _DB_PREFIX_ . 'inpost_dispatch_point` (`id_dispatch_point`)
ON DELETE SET NULL
)
ENGINE = ' . _MYSQL_ENGINE_ . '
CHARSET = utf8
COLLATE = utf8_general_ci
');
$result &= $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'inpost_shipment` (
`id_shipment` INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
`organization_id` INT(10) UNSIGNED NOT NULL,
`id_order` INT(10) UNSIGNED NOT NULL,
`sandbox` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
`shipx_shipment_id` INT(10) UNSIGNED NOT NULL,
`reference` VARCHAR(100),
`email` varchar(255) NOT NULL,
`phone` varchar(255) NOT NULL,
`service` ENUM(' . $services . ') NOT NULL,
`sending_method` ENUM("' . implode('","', SendingMethod::SENDING_METHODS) . '"),
`sending_point` VARCHAR(32),
`weekend_delivery` TINYINT(1) UNSIGNED,
`template` ENUM(' . $templates . '),
`dimensions` VARCHAR(255),
`id_dispatch_order` INT(10) UNSIGNED,
`target_point` VARCHAR(32),
`cod_amount` DECIMAL(20,6),
`insurance_amount` DECIMAL(20,6),
`tracking_number` CHAR(24),
`status` VARCHAR(64),
`price` DECIMAL(20,6),
`label_printed` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
`date_add` DATETIME NOT NULL,
PRIMARY KEY (`id_shipment`),
FOREIGN KEY (`id_order`)
REFERENCES `' . _DB_PREFIX_ . 'orders` (`id_order`)
ON DELETE CASCADE,
FOREIGN KEY (`id_dispatch_order`)
REFERENCES `' . _DB_PREFIX_ . 'inpost_dispatch_order` (`id_dispatch_order`)
ON DELETE SET NULL
)
ENGINE = ' . _MYSQL_ENGINE_ . '
CHARSET = utf8
COLLATE = utf8_general_ci
');
$result &= $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'inpost_product_template` (
`id_product` INT(10) UNSIGNED NOT NULL,
`template` ENUM(' . $templates . ') NOT NULL,
PRIMARY KEY (`id_product`),
FOREIGN KEY (`id_product`)
REFERENCES `' . _DB_PREFIX_ . 'product` (`id_product`)
ON DELETE CASCADE
)
ENGINE = ' . _MYSQL_ENGINE_ . '
CHARSET = utf8
COLLATE = utf8_general_ci
');
return $result;
}
protected function addStatuses()
{
$languageIds = Language::getIDs(false);
$indexPl = [];
if ($id_lang_pl = Language::getIdByIso('PL')) {
$statuses = Status::getAll([
'query' => ['lang' => 'pl_PL'],
]);
foreach ($statuses as $status) {
$indexPl[$status->name] = [
'title' => $status->title,
'description' => $status->description,
];
}
}
$statuses = Status::getAll([
'query' => ['lang' => 'en_GB'],
]);
foreach ($statuses as $status) {
if (!InPostShipmentStatusModel::getStatusByName($status->name)) {
$statusModel = new InPostShipmentStatusModel();
$statusModel->name = $status->name;
foreach ($languageIds as $id_lang) {
if ($id_lang == $id_lang_pl) {
$statusModel->title[$id_lang] = $indexPl[$status->name]['title'];
$statusModel->description[$id_lang] = $indexPl[$status->name]['description'];
} else {
$statusModel->title[$id_lang] = $status->title;
$statusModel->description[$id_lang] = $status->description;
}
}
$statusModel->add();
}
}
return true;
}
public function uninstall()
{
$result = true;
$result &= $this->db->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'inpost_carrier`');
$result &= $this->db->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'inpost_shipment_status_lang`');
$result &= $this->db->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'inpost_shipment_status`');
$result &= $this->db->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'inpost_product_template`');
return $result;
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
namespace InPost\Shipping\Install;
use InPost\Shipping\HookDispatcher;
use InPostShipping;
class Hooks implements InstallerInterface
{
protected $module;
protected $hookDispatcher;
public function __construct(InPostShipping $module, HookDispatcher $hookDispatcher)
{
$this->module = $module;
$this->hookDispatcher = $hookDispatcher;
}
public function install()
{
return $this->module->registerHook(
$this->hookDispatcher->getAvailableHooks()
);
}
public function uninstall()
{
foreach ($this->hookDispatcher->getAvailableHooks() as $hookName) {
$this->module->unregisterHook($hookName);
}
return true;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
namespace InPost\Shipping\Install;
class Installer implements InstallerInterface
{
/** @var InstallerInterface[] */
protected $subInstallers;
public function __construct(array $subInstallers)
{
$this->subInstallers = array_filter($subInstallers, function ($installer) {
return $installer instanceof InstallerInterface;
});
}
public function install()
{
$result = true;
foreach ($this->subInstallers as $installer) {
$result &= $installer->install();
}
return $result;
}
public function uninstall()
{
$result = true;
foreach ($this->subInstallers as $installer) {
$result &= $installer->uninstall();
}
return $result;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
namespace InPost\Shipping\Install;
interface InstallerInterface
{
/** @return bool */
public function install();
/** @return bool */
public function uninstall();
}

View File

@@ -0,0 +1,149 @@
<?php
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
namespace InPost\Shipping\Install;
use InPost\Shipping\DataProvider\LanguageDataProvider;
use InPost\Shipping\PrestaShopContext;
use InPostShipping;
use Tab;
class Tabs implements InstallerInterface
{
const TRANSLATION_SOURCE = 'Tabs';
const AJAX_CONTROLLER_NAME = 'AdminInPostAjax';
const DISPATCH_POINT_CONTROLLER_NAME = 'AdminInPostDispatchPoints';
const SHIPMENTS_CONTROLLER_NAME = 'AdminInPostConfirmedShipments';
const DISPATCH_ORDERS_CONTROLLER_NAME = 'AdminInPostDispatchOrders';
const SENT_SHIPMENTS_CONTROLLER_NAME = 'AdminInPostSentShipments';
const PARENT_SHIPMENTS_TAB_NAME = 'AdminParentInPostShipments';
const SHIPMENTS_TAB_NAMES = [
self::SHIPMENTS_CONTROLLER_NAME,
self::DISPATCH_ORDERS_CONTROLLER_NAME,
self::SENT_SHIPMENTS_CONTROLLER_NAME,
];
protected $module;
protected $shopContext;
protected $languageDataProvider;
public function __construct(
InPostShipping $module,
PrestaShopContext $shopContext,
LanguageDataProvider $languageDataProvider
) {
$this->module = $module;
$this->shopContext = $shopContext;
$this->languageDataProvider = $languageDataProvider;
}
public function install()
{
$result = true;
$parentTab = $this->shopContext->is17()
? self::PARENT_SHIPMENTS_TAB_NAME
: self::SHIPMENTS_CONTROLLER_NAME;
if ($id_parent = $this->installTab($parentTab, Tab::getIdFromClassName('AdminParentShipping'))) {
foreach (self::SHIPMENTS_TAB_NAMES as $className) {
$result &= (bool) $this->installTab($className, $id_parent);
}
} else {
$result = false;
}
$result &= (bool) $this->installTab(self::AJAX_CONTROLLER_NAME, -1);
$result &= (bool) $this->installTab(self::DISPATCH_POINT_CONTROLLER_NAME, -1);
return $result;
}
public function uninstall()
{
$result = true;
/** @var Tab $tab */
foreach (Tab::getCollectionFromModule($this->module->name) as $tab) {
$result &= $tab->delete();
}
return $result;
}
protected function installTab($className, $id_parent)
{
if ($id_tab = Tab::getIdFromClassName($className)) {
return $id_tab;
}
$tab = new Tab();
$tab->module = $this->module->name;
$tab->class_name = $className;
$tab->id_parent = $id_parent;
$tab->name = $this->getTabName($className);
if ($tab->add()) {
return $tab->id;
}
return false;
}
protected function getTabName($className = null)
{
$name = [];
foreach ($this->languageDataProvider->getLanguages() as $id_lang => $language) {
switch ($className) {
case self::PARENT_SHIPMENTS_TAB_NAME:
$name[$id_lang] = $this->module->l('InPost shipments', self::TRANSLATION_SOURCE, $language['locale']);
break;
case self::SHIPMENTS_CONTROLLER_NAME:
$name[$id_lang] = $this->shopContext->is17()
? $this->module->l('Confirmed shipments', self::TRANSLATION_SOURCE, $language['locale'])
: $this->module->l('InPost shipments', self::TRANSLATION_SOURCE, $language['locale']);
break;
case self::DISPATCH_ORDERS_CONTROLLER_NAME:
$name[$id_lang] = $this->module->l('Dispatch orders', self::TRANSLATION_SOURCE, $language['locale']);
break;
case self::SENT_SHIPMENTS_CONTROLLER_NAME:
$name[$id_lang] = $this->module->l('Sent shipments', self::TRANSLATION_SOURCE, $language['locale']);
break;
case self::DISPATCH_POINT_CONTROLLER_NAME:
$name[$id_lang] = $this->module->l('InPost Dispatch Points', self::TRANSLATION_SOURCE, $language['locale']);
break;
default:
$name[$id_lang] = $this->module->name;
break;
}
}
return $name;
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
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;