first commit
This commit is contained in:
135
modules/inpostshipping/classes/InPostCarrierModel.php
Normal file
135
modules/inpostshipping/classes/InPostCarrierModel.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* 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 https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
|
||||
class InPostCarrierModel extends ObjectModel
|
||||
{
|
||||
public $force_id = true;
|
||||
|
||||
public $service;
|
||||
public $cod = false;
|
||||
public $weekend_delivery = false;
|
||||
public $use_product_dimensions = false;
|
||||
|
||||
public static $definition = [
|
||||
'table' => 'inpost_carrier',
|
||||
'primary' => 'id_reference',
|
||||
'fields' => [
|
||||
'service' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'values' => Service::SERVICES,
|
||||
],
|
||||
'cod' => [
|
||||
'type' => self::TYPE_BOOL,
|
||||
'validate' => 'isBool',
|
||||
],
|
||||
'weekend_delivery' => [
|
||||
'type' => self::TYPE_BOOL,
|
||||
'validate' => 'isBool',
|
||||
],
|
||||
'use_product_dimensions' => [
|
||||
'type' => self::TYPE_BOOL,
|
||||
'validate' => 'isBool',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public function add($auto_date = true, $null_values = false)
|
||||
{
|
||||
$id_reference = $this->id;
|
||||
|
||||
if ($result = parent::add($auto_date, $null_values)) {
|
||||
$this->id = $id_reference;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if ($carrier = $this->getCarrier()) {
|
||||
$carrier->active = false;
|
||||
$carrier->is_module = false;
|
||||
$carrier->external_module_name = null;
|
||||
|
||||
if (!$carrier->update()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
public function getCarrier()
|
||||
{
|
||||
return Carrier::getCarrierByReference($this->id) ?: null;
|
||||
}
|
||||
|
||||
public static function getDataByCarrierId($id_carrier)
|
||||
{
|
||||
static $carriers;
|
||||
|
||||
if (!isset($carriers)) {
|
||||
$query = (new DbQuery())
|
||||
->select('ic.*, c.id_carrier')
|
||||
->from('inpost_carrier', 'ic')
|
||||
->innerJoin('carrier', 'c', 'c.id_reference = ic.id_reference')
|
||||
->where('c.deleted = 0')
|
||||
->where('c.active = 1');
|
||||
|
||||
foreach (Db::getInstance()->executeS($query) as $row) {
|
||||
$carriers[$row['id_carrier']] = [
|
||||
'id_carrier' => $row['id_carrier'],
|
||||
'cashOnDelivery' => $row['cod'],
|
||||
'service' => $row['service'],
|
||||
'lockerService' => $row['service'] === Service::INPOST_LOCKER_STANDARD,
|
||||
'weekendDelivery' => $row['weekend_delivery'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return isset($carriers[$id_carrier]) ? $carriers[$id_carrier] : null;
|
||||
}
|
||||
|
||||
/** @return self[] */
|
||||
public static function getNonDeletedCarriers()
|
||||
{
|
||||
$subQuery = (new DbQuery())
|
||||
->from('carrier')
|
||||
->where('id_reference = ic.id_reference')
|
||||
->where('deleted = 0');
|
||||
|
||||
$query = (new DbQuery())
|
||||
->from('inpost_carrier', 'ic')
|
||||
->where('EXISTS (' . $subQuery . ')');
|
||||
|
||||
return self::hydrateCollection(
|
||||
self::class,
|
||||
Db::getInstance()->executeS($query)
|
||||
);
|
||||
}
|
||||
}
|
||||
85
modules/inpostshipping/classes/InPostCartChoiceModel.php
Normal file
85
modules/inpostshipping/classes/InPostCartChoiceModel.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
|
||||
class InPostCartChoiceModel extends ObjectModel
|
||||
{
|
||||
public $force_id = true;
|
||||
|
||||
public $service;
|
||||
public $email;
|
||||
public $phone;
|
||||
public $point;
|
||||
|
||||
public static $definition = [
|
||||
'table' => 'inpost_cart_choice',
|
||||
'primary' => 'id_cart',
|
||||
'fields' => [
|
||||
'service' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'values' => Service::SERVICES,
|
||||
],
|
||||
'email' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isEmail',
|
||||
'size' => 255,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'phone' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isPhoneNumber',
|
||||
'size' => 255,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'point' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isGenericName',
|
||||
'size' => 32,
|
||||
'allow_null' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public function add($auto_date = true, $null_values = true)
|
||||
{
|
||||
$id_cart = $this->id;
|
||||
|
||||
if ($result = parent::add($auto_date, $null_values)) {
|
||||
$this->id = $id_cart;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function update($null_values = true)
|
||||
{
|
||||
return parent::update($null_values);
|
||||
}
|
||||
|
||||
public static function formatPhone($phone)
|
||||
{
|
||||
return preg_replace('/\s+/', '', $phone);
|
||||
}
|
||||
}
|
||||
107
modules/inpostshipping/classes/InPostDispatchOrderModel.php
Normal file
107
modules/inpostshipping/classes/InPostDispatchOrderModel.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
class InPostDispatchOrderModel extends ObjectModel
|
||||
{
|
||||
public $id_dispatch_point;
|
||||
public $shipx_dispatch_order_id;
|
||||
public $number;
|
||||
public $price;
|
||||
public $status;
|
||||
public $date_add;
|
||||
|
||||
public static $definition = [
|
||||
'table' => 'inpost_dispatch_order',
|
||||
'primary' => 'id_dispatch_order',
|
||||
'fields' => [
|
||||
'id_dispatch_point' => [
|
||||
'type' => self::TYPE_INT,
|
||||
'validate' => 'isUnsignedId',
|
||||
'allow_null' => true,
|
||||
],
|
||||
'shipx_dispatch_order_id' => [
|
||||
'type' => self::TYPE_INT,
|
||||
'validate' => 'isUnsignedId',
|
||||
'allow_null' => true,
|
||||
],
|
||||
'number' => [
|
||||
'type' => self::TYPE_INT,
|
||||
'validate' => 'isNullOrUnsignedId',
|
||||
'allow_null' => true,
|
||||
],
|
||||
'price' => [
|
||||
'type' => self::TYPE_FLOAT,
|
||||
'validate' => 'isPrice',
|
||||
'allow_null' => true,
|
||||
],
|
||||
'status' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isString',
|
||||
'size' => 64,
|
||||
],
|
||||
'date_add' => [
|
||||
'type' => self::TYPE_DATE,
|
||||
'validate' => 'isDate',
|
||||
],
|
||||
],
|
||||
'associations' => [
|
||||
'shipments' => [
|
||||
'type' => self::HAS_MANY,
|
||||
'field' => 'id_dispatch_order',
|
||||
'foreign_field' => 'id_dispatch_order',
|
||||
'object' => 'InPostShipmentModel',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public function add($auto_date = true, $null_values = true)
|
||||
{
|
||||
return parent::add($auto_date, $null_values);
|
||||
}
|
||||
|
||||
public function update($null_values = true)
|
||||
{
|
||||
return parent::update($null_values);
|
||||
}
|
||||
|
||||
/** @return self[] */
|
||||
public static function getDispatchOrders($sandbox, $organizationId, array $ids = [])
|
||||
{
|
||||
$query = (new DbQuery())
|
||||
->select('do.*')
|
||||
->from('inpost_dispatch_order', 'do')
|
||||
->innerJoin('inpost_shipment', 's', 's.id_dispatch_order = do.id_dispatch_order')
|
||||
->where('s.sandbox = ' . ($sandbox ? 1 : 0))
|
||||
->where('s.organization_id = ' . (int) $organizationId);
|
||||
|
||||
if (!empty($ids)) {
|
||||
$query->where('id_dispatch_order IN (' . implode(',', array_map('intval', $ids)) . ')');
|
||||
}
|
||||
|
||||
return self::hydrateCollection(
|
||||
self::class,
|
||||
Db::getInstance()->executeS($query)
|
||||
);
|
||||
}
|
||||
}
|
||||
125
modules/inpostshipping/classes/InPostDispatchPointModel.php
Normal file
125
modules/inpostshipping/classes/InPostDispatchPointModel.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
class InPostDispatchPointModel extends ObjectModel
|
||||
{
|
||||
public $name;
|
||||
public $office_hours;
|
||||
public $phone;
|
||||
public $email;
|
||||
public $street;
|
||||
public $building_number;
|
||||
public $post_code;
|
||||
public $city;
|
||||
public $deleted = false;
|
||||
|
||||
public static $definition = [
|
||||
'table' => 'inpost_dispatch_point',
|
||||
'primary' => 'id_dispatch_point',
|
||||
'fields' => [
|
||||
'name' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'required' => true,
|
||||
'validate' => 'isGenericName',
|
||||
'size' => 255,
|
||||
],
|
||||
'office_hours' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isCleanHtml',
|
||||
'size' => 255,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'email' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isEmail',
|
||||
'size' => 255,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'phone' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isPhoneNumber',
|
||||
'size' => 255,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'street' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'required' => true,
|
||||
'validate' => 'isAddress',
|
||||
'size' => 255,
|
||||
],
|
||||
'building_number' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'required' => true,
|
||||
'validate' => 'isAddress',
|
||||
'size' => 255,
|
||||
],
|
||||
'post_code' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'required' => true,
|
||||
'validate' => 'isPostCode',
|
||||
'size' => 6,
|
||||
],
|
||||
'city' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'required' => true,
|
||||
'validate' => 'isCityName',
|
||||
'size' => 255,
|
||||
],
|
||||
'deleted' => [
|
||||
'type' => self::TYPE_BOOL,
|
||||
'validate' => 'isBool',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public function add($auto_date = true, $null_values = true)
|
||||
{
|
||||
return parent::add($auto_date, $null_values);
|
||||
}
|
||||
|
||||
public function update($null_values = true)
|
||||
{
|
||||
return parent::update($null_values);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if ($this->isUsed()) {
|
||||
$this->deleted = true;
|
||||
|
||||
return $this->update();
|
||||
}
|
||||
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
protected function isUsed()
|
||||
{
|
||||
$query = (new DbQuery())
|
||||
->from('inpost_dispatch_order')
|
||||
->where('id_dispatch_point = ' . (int) $this->id);
|
||||
|
||||
return Db::getInstance()->getValue('SELECT EXISTS (' . $query . ')');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* 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 https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
|
||||
|
||||
class InPostProductTemplateModel extends ObjectModel
|
||||
{
|
||||
public $force_id = true;
|
||||
|
||||
public $template;
|
||||
|
||||
public static $definition = [
|
||||
'table' => 'inpost_product_template',
|
||||
'primary' => 'id_product',
|
||||
'fields' => [
|
||||
'template' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'values' => Shipment::DIMENSION_TEMPLATES,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public static function getTemplatesByOrderId($id_order)
|
||||
{
|
||||
$query = (new DbQuery())
|
||||
->select('DISTINCT ipt.template')
|
||||
->from('order_detail', 'od')
|
||||
->innerJoin('inpost_product_template', 'ipt', 'ipt.id_product = od.product_id')
|
||||
->where('od.id_order = ' . (int) $id_order);
|
||||
|
||||
return array_column(
|
||||
Db::getInstance()->executeS($query),
|
||||
'template'
|
||||
);
|
||||
}
|
||||
}
|
||||
320
modules/inpostshipping/classes/InPostShipmentModel.php
Normal file
320
modules/inpostshipping/classes/InPostShipmentModel.php
Normal file
@@ -0,0 +1,320 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
|
||||
use InPost\Shipping\ShipX\Resource\SendingMethod;
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
|
||||
class InPostShipmentModel extends ObjectModel
|
||||
{
|
||||
public $id_order;
|
||||
public $organization_id;
|
||||
public $sandbox = false;
|
||||
public $shipx_shipment_id;
|
||||
public $reference;
|
||||
public $email;
|
||||
public $phone;
|
||||
public $service;
|
||||
public $sending_method;
|
||||
public $sending_point;
|
||||
public $weekend_delivery;
|
||||
public $template;
|
||||
public $dimensions;
|
||||
public $id_dispatch_order;
|
||||
public $target_point;
|
||||
public $cod_amount;
|
||||
public $insurance_amount;
|
||||
public $tracking_number;
|
||||
public $status;
|
||||
public $price;
|
||||
public $label_printed = false;
|
||||
public $date_add;
|
||||
|
||||
/** @var Order */
|
||||
protected $order;
|
||||
|
||||
public static $definition = [
|
||||
'table' => 'inpost_shipment',
|
||||
'primary' => 'id_shipment',
|
||||
'fields' => [
|
||||
'id_order' => [
|
||||
'type' => self::TYPE_INT,
|
||||
'validate' => 'isUnsignedId',
|
||||
],
|
||||
'organization_id' => [
|
||||
'type' => self::TYPE_INT,
|
||||
'validate' => 'isUnsignedId',
|
||||
],
|
||||
'sandbox' => [
|
||||
'type' => self::TYPE_BOOL,
|
||||
'validate' => 'isBool',
|
||||
],
|
||||
'shipx_shipment_id' => [
|
||||
'type' => self::TYPE_INT,
|
||||
'validate' => 'isUnsignedId',
|
||||
],
|
||||
'reference' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isString',
|
||||
'size' => 100,
|
||||
],
|
||||
'email' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isEmail',
|
||||
'size' => 255,
|
||||
'required' => true,
|
||||
],
|
||||
'phone' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isPhoneNumber',
|
||||
'size' => 255,
|
||||
'required' => true,
|
||||
],
|
||||
'service' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'values' => Service::SERVICES,
|
||||
],
|
||||
'sending_method' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'values' => SendingMethod::SENDING_METHODS,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'sending_point' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isString',
|
||||
'size' => 32,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'weekend_delivery' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isBool',
|
||||
'allow_null' => true,
|
||||
],
|
||||
'template' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'values' => Shipment::DIMENSION_TEMPLATES,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'dimensions' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isString',
|
||||
'size' => 255,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'id_dispatch_order' => [
|
||||
'type' => self::TYPE_INT,
|
||||
'validate' => 'isNullOrUnsignedId',
|
||||
'allow_null' => true,
|
||||
],
|
||||
'target_point' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isString',
|
||||
'size' => 32,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'cod_amount' => [
|
||||
'type' => self::TYPE_FLOAT,
|
||||
'validate' => 'isPrice',
|
||||
'allow_null' => true,
|
||||
],
|
||||
'insurance_amount' => [
|
||||
'type' => self::TYPE_FLOAT,
|
||||
'validate' => 'isPrice',
|
||||
'allow_null' => true,
|
||||
],
|
||||
'tracking_number' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isString',
|
||||
'size' => 24,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'status' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isString',
|
||||
'size' => 64,
|
||||
'allow_null' => true,
|
||||
],
|
||||
'price' => [
|
||||
'type' => self::TYPE_FLOAT,
|
||||
'validate' => 'isPrice',
|
||||
'allow_null' => true,
|
||||
],
|
||||
'date_add' => [
|
||||
'type' => self::TYPE_DATE,
|
||||
'validate' => 'isDate',
|
||||
],
|
||||
'label_printed' => [
|
||||
'type' => self::TYPE_BOOL,
|
||||
'validate' => 'isBool',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public function add($auto_date = true, $null_values = true)
|
||||
{
|
||||
return parent::add($auto_date, $null_values);
|
||||
}
|
||||
|
||||
public function update($null_values = true)
|
||||
{
|
||||
return parent::update($null_values);
|
||||
}
|
||||
|
||||
public function setOrder(Order $order)
|
||||
{
|
||||
if (!isset($this->id_order) ||
|
||||
$this->id_order == $order->id && Validate::isLoadedObject($order)
|
||||
) {
|
||||
$this->order = $order;
|
||||
$this->id_order = $this->order->id;
|
||||
}
|
||||
}
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
if (!isset($this->order) && Validate::isLoadedObject($this)) {
|
||||
$this->order = new Order($this->id_order);
|
||||
}
|
||||
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
public function updateOrderTrackingNumber()
|
||||
{
|
||||
if (!empty($this->tracking_number) && $order = $this->getOrder()) {
|
||||
$order->shipping_number = $this->tracking_number;
|
||||
$order->update();
|
||||
|
||||
$orderCarrier = new OrderCarrier($order->getIdOrderCarrier());
|
||||
$orderCarrier->tracking_number = $this->tracking_number;
|
||||
$orderCarrier->update();
|
||||
|
||||
if (method_exists($orderCarrier, 'sendInTransitEmail')) {
|
||||
$orderCarrier->sendInTransitEmail($order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getSkipPrintDispatchOrderList($organizationId, $sandbox)
|
||||
{
|
||||
$query = self::getQuery($sandbox, $organizationId)
|
||||
->select('id_shipment')
|
||||
->where('id_dispatch_order IS NULL OR id_dispatch_order = 0');
|
||||
|
||||
return self::getSkipList($query);
|
||||
}
|
||||
|
||||
public static function getSkipCreateDispatchOrderList($organizationId, $sandbox)
|
||||
{
|
||||
$query = self::getQuery($sandbox, $organizationId)
|
||||
->select('id_shipment')
|
||||
->where(implode(' OR ', [
|
||||
'sending_method <> "' . SendingMethod::DISPATCH_ORDER . '"',
|
||||
'id_dispatch_order IS NOT NULL AND id_dispatch_order <> 0',
|
||||
]));
|
||||
|
||||
return self::getSkipList($query);
|
||||
}
|
||||
|
||||
protected static function getSkipList(DbQuery $query)
|
||||
{
|
||||
$ids = [];
|
||||
|
||||
foreach (Db::getInstance()->executeS($query) as $row) {
|
||||
$ids[$row['id_shipment']] = $row['id_shipment'];
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/** @return self[] */
|
||||
public static function getByIds(array $ids, $sandbox, $organizationId)
|
||||
{
|
||||
return (new PrestaShopCollection(self::class))
|
||||
->where('id_shipment', '=', $ids)
|
||||
->where('sandbox', '=', $sandbox)
|
||||
->where('organization_id', '=', $organizationId)
|
||||
->getResults();
|
||||
}
|
||||
|
||||
public static function getShipXShipmentIds(array $ids, $sandbox, $noLocker = false, $dispatchOrders = false)
|
||||
{
|
||||
if (!empty($ids)) {
|
||||
$query = self::getQuery($sandbox)
|
||||
->select('shipx_shipment_id')
|
||||
->where('id_shipment IN (' . implode(',', array_map('intval', $ids)) . ')');
|
||||
|
||||
if ($noLocker) {
|
||||
$query->where('service NOT IN ("' . implode('","', Service::LOCKER_SERVICES) . '")');
|
||||
}
|
||||
|
||||
if ($dispatchOrders) {
|
||||
$query->where('id_dispatch_order IS NOT NULL')
|
||||
->where('id_dispatch_order <> 0');
|
||||
}
|
||||
|
||||
return array_column(Db::getInstance()->executeS($query), 'shipx_shipment_id');
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function getShipmentIdsByOrderIds(array $ids, $sandbox, $organizationId)
|
||||
{
|
||||
if (!empty($ids)) {
|
||||
$query = self::getQuery($sandbox, $organizationId)
|
||||
->select('id_shipment')
|
||||
->where('id_order IN (' . implode(',', array_map('intval', $ids)) . ')');
|
||||
|
||||
return array_column(Db::getInstance()->executeS($query), 'id_shipment');
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected static function getQuery($sandbox, $organizationId = null)
|
||||
{
|
||||
$query = (new DbQuery())
|
||||
->from('inpost_shipment')
|
||||
->where('sandbox = ' . ($sandbox ? 1 : 0));
|
||||
|
||||
if ($organizationId) {
|
||||
$query->where('organization_id = ' . (int) $organizationId);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function validateField($field, $value, $id_lang = null, $skip = [], $human_errors = false)
|
||||
{
|
||||
if ($value === null &&
|
||||
isset($this->def['fields'][$field]['allow_null']) &&
|
||||
$this->def['fields'][$field]['allow_null']
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::validateField($field, $value, $id_lang, $skip, $human_errors);
|
||||
}
|
||||
}
|
||||
63
modules/inpostshipping/classes/InPostShipmentStatusModel.php
Normal file
63
modules/inpostshipping/classes/InPostShipmentStatusModel.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
class InPostShipmentStatusModel extends ObjectModel
|
||||
{
|
||||
public $name;
|
||||
public $title;
|
||||
public $description;
|
||||
|
||||
public static $definition = [
|
||||
'table' => 'inpost_shipment_status',
|
||||
'primary' => 'id_status',
|
||||
'multilang' => true,
|
||||
'fields' => [
|
||||
'name' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'validate' => 'isTableOrIdentifier',
|
||||
'size' => 64,
|
||||
],
|
||||
'title' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isGenericName',
|
||||
'size' => 128,
|
||||
],
|
||||
'description' => [
|
||||
'type' => self::TYPE_STRING,
|
||||
'lang' => true,
|
||||
'validate' => 'isCleanHtml',
|
||||
'size' => 512,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public static function getStatusByName($name)
|
||||
{
|
||||
$collection = (new PrestaShopCollection(self::class))
|
||||
->where('name', 'LIKE', $name);
|
||||
|
||||
return $collection->getFirst();
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/classes/index.php
Normal file
32
modules/inpostshipping/classes/index.php
Normal 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;
|
||||
Reference in New Issue
Block a user