first commit
This commit is contained in:
287
modules/inpostshipping/LICENSE.txt
Normal file
287
modules/inpostshipping/LICENSE.txt
Normal file
@@ -0,0 +1,287 @@
|
||||
EUROPEAN UNION PUBLIC LICENCE v. 1.2
|
||||
EUPL © the European Union 2007, 2016
|
||||
|
||||
This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined
|
||||
below) which is provided under the terms of this Licence. Any use of the Work,
|
||||
other than as authorised under this Licence is prohibited (to the extent such
|
||||
use is covered by a right of the copyright holder of the Work).
|
||||
|
||||
The Work is provided under the terms of this Licence when the Licensor (as
|
||||
defined below) has placed the following notice immediately following the
|
||||
copyright notice for the Work:
|
||||
|
||||
Licensed under the EUPL
|
||||
|
||||
or has expressed by any other means his willingness to license under the EUPL.
|
||||
|
||||
1. Definitions
|
||||
|
||||
In this Licence, the following terms have the following meaning:
|
||||
|
||||
- ‘The Licence’: this Licence.
|
||||
|
||||
- ‘The Original Work’: the work or software distributed or communicated by the
|
||||
Licensor under this Licence, available as Source Code and also as Executable
|
||||
Code as the case may be.
|
||||
|
||||
- ‘Derivative Works’: the works or software that could be created by the
|
||||
Licensee, based upon the Original Work or modifications thereof. This Licence
|
||||
does not define the extent of modification or dependence on the Original Work
|
||||
required in order to classify a work as a Derivative Work; this extent is
|
||||
determined by copyright law applicable in the country mentioned in Article 15.
|
||||
|
||||
- ‘The Work’: the Original Work or its Derivative Works.
|
||||
|
||||
- ‘The Source Code’: the human-readable form of the Work which is the most
|
||||
convenient for people to study and modify.
|
||||
|
||||
- ‘The Executable Code’: any code which has generally been compiled and which is
|
||||
meant to be interpreted by a computer as a program.
|
||||
|
||||
- ‘The Licensor’: the natural or legal person that distributes or communicates
|
||||
the Work under the Licence.
|
||||
|
||||
- ‘Contributor(s)’: any natural or legal person who modifies the Work under the
|
||||
Licence, or otherwise contributes to the creation of a Derivative Work.
|
||||
|
||||
- ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
|
||||
the Work under the terms of the Licence.
|
||||
|
||||
- ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
|
||||
renting, distributing, communicating, transmitting, or otherwise making
|
||||
available, online or offline, copies of the Work or providing access to its
|
||||
essential functionalities at the disposal of any other natural or legal
|
||||
person.
|
||||
|
||||
2. Scope of the rights granted by the Licence
|
||||
|
||||
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
|
||||
sublicensable licence to do the following, for the duration of copyright vested
|
||||
in the Original Work:
|
||||
|
||||
- use the Work in any circumstance and for all usage,
|
||||
- reproduce the Work,
|
||||
- modify the Work, and make Derivative Works based upon the Work,
|
||||
- communicate to the public, including the right to make available or display
|
||||
the Work or copies thereof to the public and perform publicly, as the case may
|
||||
be, the Work,
|
||||
- distribute the Work or copies thereof,
|
||||
- lend and rent the Work or copies thereof,
|
||||
- sublicense rights in the Work or copies thereof.
|
||||
|
||||
Those rights can be exercised on any media, supports and formats, whether now
|
||||
known or later invented, as far as the applicable law permits so.
|
||||
|
||||
In the countries where moral rights apply, the Licensor waives his right to
|
||||
exercise his moral right to the extent allowed by law in order to make effective
|
||||
the licence of the economic rights here above listed.
|
||||
|
||||
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to
|
||||
any patents held by the Licensor, to the extent necessary to make use of the
|
||||
rights granted on the Work under this Licence.
|
||||
|
||||
3. Communication of the Source Code
|
||||
|
||||
The Licensor may provide the Work either in its Source Code form, or as
|
||||
Executable Code. If the Work is provided as Executable Code, the Licensor
|
||||
provides in addition a machine-readable copy of the Source Code of the Work
|
||||
along with each copy of the Work that the Licensor distributes or indicates, in
|
||||
a notice following the copyright notice attached to the Work, a repository where
|
||||
the Source Code is easily and freely accessible for as long as the Licensor
|
||||
continues to distribute or communicate the Work.
|
||||
|
||||
4. Limitations on copyright
|
||||
|
||||
Nothing in this Licence is intended to deprive the Licensee of the benefits from
|
||||
any exception or limitation to the exclusive rights of the rights owners in the
|
||||
Work, of the exhaustion of those rights or of other applicable limitations
|
||||
thereto.
|
||||
|
||||
5. Obligations of the Licensee
|
||||
|
||||
The grant of the rights mentioned above is subject to some restrictions and
|
||||
obligations imposed on the Licensee. Those obligations are the following:
|
||||
|
||||
Attribution right: The Licensee shall keep intact all copyright, patent or
|
||||
trademarks notices and all notices that refer to the Licence and to the
|
||||
disclaimer of warranties. The Licensee must include a copy of such notices and a
|
||||
copy of the Licence with every copy of the Work he/she distributes or
|
||||
communicates. The Licensee must cause any Derivative Work to carry prominent
|
||||
notices stating that the Work has been modified and the date of modification.
|
||||
|
||||
Copyleft clause: If the Licensee distributes or communicates copies of the
|
||||
Original Works or Derivative Works, this Distribution or Communication will be
|
||||
done under the terms of this Licence or of a later version of this Licence
|
||||
unless the Original Work is expressly distributed only under this version of the
|
||||
Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
|
||||
(becoming Licensor) cannot offer or impose any additional terms or conditions on
|
||||
the Work or Derivative Work that alter or restrict the terms of the Licence.
|
||||
|
||||
Compatibility clause: If the Licensee Distributes or Communicates Derivative
|
||||
Works or copies thereof based upon both the Work and another work licensed under
|
||||
a Compatible Licence, this Distribution or Communication can be done under the
|
||||
terms of this Compatible Licence. For the sake of this clause, ‘Compatible
|
||||
Licence’ refers to the licences listed in the appendix attached to this Licence.
|
||||
Should the Licensee's obligations under the Compatible Licence conflict with
|
||||
his/her obligations under this Licence, the obligations of the Compatible
|
||||
Licence shall prevail.
|
||||
|
||||
Provision of Source Code: When distributing or communicating copies of the Work,
|
||||
the Licensee will provide a machine-readable copy of the Source Code or indicate
|
||||
a repository where this Source will be easily and freely available for as long
|
||||
as the Licensee continues to distribute or communicate the Work.
|
||||
|
||||
Legal Protection: This Licence does not grant permission to use the trade names,
|
||||
trademarks, service marks, or names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the copyright notice.
|
||||
|
||||
6. Chain of Authorship
|
||||
|
||||
The original Licensor warrants that the copyright in the Original Work granted
|
||||
hereunder is owned by him/her or licensed to him/her and that he/she has the
|
||||
power and authority to grant the Licence.
|
||||
|
||||
Each Contributor warrants that the copyright in the modifications he/she brings
|
||||
to the Work are owned by him/her or licensed to him/her and that he/she has the
|
||||
power and authority to grant the Licence.
|
||||
|
||||
Each time You accept the Licence, the original Licensor and subsequent
|
||||
Contributors grant You a licence to their contributions to the Work, under the
|
||||
terms of this Licence.
|
||||
|
||||
7. Disclaimer of Warranty
|
||||
|
||||
The Work is a work in progress, which is continuously improved by numerous
|
||||
Contributors. It is not a finished work and may therefore contain defects or
|
||||
‘bugs’ inherent to this type of development.
|
||||
|
||||
For the above reason, the Work is provided under the Licence on an ‘as is’ basis
|
||||
and without warranties of any kind concerning the Work, including without
|
||||
limitation merchantability, fitness for a particular purpose, absence of defects
|
||||
or errors, accuracy, non-infringement of intellectual property rights other than
|
||||
copyright as stated in Article 6 of this Licence.
|
||||
|
||||
This disclaimer of warranty is an essential part of the Licence and a condition
|
||||
for the grant of any rights to the Work.
|
||||
|
||||
8. Disclaimer of Liability
|
||||
|
||||
Except in the cases of wilful misconduct or damages directly caused to natural
|
||||
persons, the Licensor will in no event be liable for any direct or indirect,
|
||||
material or moral, damages of any kind, arising out of the Licence or of the use
|
||||
of the Work, including without limitation, damages for loss of goodwill, work
|
||||
stoppage, computer failure or malfunction, loss of data or any commercial
|
||||
damage, even if the Licensor has been advised of the possibility of such damage.
|
||||
However, the Licensor will be liable under statutory product liability laws as
|
||||
far such laws apply to the Work.
|
||||
|
||||
9. Additional agreements
|
||||
|
||||
While distributing the Work, You may choose to conclude an additional agreement,
|
||||
defining obligations or services consistent with this Licence. However, if
|
||||
accepting obligations, You may act only on your own behalf and on your sole
|
||||
responsibility, not on behalf of the original Licensor or any other Contributor,
|
||||
and only if You agree to indemnify, defend, and hold each Contributor harmless
|
||||
for any liability incurred by, or claims asserted against such Contributor by
|
||||
the fact You have accepted any warranty or additional liability.
|
||||
|
||||
10. Acceptance of the Licence
|
||||
|
||||
The provisions of this Licence can be accepted by clicking on an icon ‘I agree’
|
||||
placed under the bottom of a window displaying the text of this Licence or by
|
||||
affirming consent in any other similar way, in accordance with the rules of
|
||||
applicable law. Clicking on that icon indicates your clear and irrevocable
|
||||
acceptance of this Licence and all of its terms and conditions.
|
||||
|
||||
Similarly, you irrevocably accept this Licence and all of its terms and
|
||||
conditions by exercising any rights granted to You by Article 2 of this Licence,
|
||||
such as the use of the Work, the creation by You of a Derivative Work or the
|
||||
Distribution or Communication by You of the Work or copies thereof.
|
||||
|
||||
11. Information to the public
|
||||
|
||||
In case of any Distribution or Communication of the Work by means of electronic
|
||||
communication by You (for example, by offering to download the Work from a
|
||||
remote location) the distribution channel or media (for example, a website) must
|
||||
at least provide to the public the information requested by the applicable law
|
||||
regarding the Licensor, the Licence and the way it may be accessible, concluded,
|
||||
stored and reproduced by the Licensee.
|
||||
|
||||
12. Termination of the Licence
|
||||
|
||||
The Licence and the rights granted hereunder will terminate automatically upon
|
||||
any breach by the Licensee of the terms of the Licence.
|
||||
|
||||
Such a termination will not terminate the licences of any person who has
|
||||
received the Work from the Licensee under the Licence, provided such persons
|
||||
remain in full compliance with the Licence.
|
||||
|
||||
13. Miscellaneous
|
||||
|
||||
Without prejudice of Article 9 above, the Licence represents the complete
|
||||
agreement between the Parties as to the Work.
|
||||
|
||||
If any provision of the Licence is invalid or unenforceable under applicable
|
||||
law, this will not affect the validity or enforceability of the Licence as a
|
||||
whole. Such provision will be construed or reformed so as necessary to make it
|
||||
valid and enforceable.
|
||||
|
||||
The European Commission may publish other linguistic versions or new versions of
|
||||
this Licence or updated versions of the Appendix, so far this is required and
|
||||
reasonable, without reducing the scope of the rights granted by the Licence. New
|
||||
versions of the Licence will be published with a unique version number.
|
||||
|
||||
All linguistic versions of this Licence, approved by the European Commission,
|
||||
have identical value. Parties can take advantage of the linguistic version of
|
||||
their choice.
|
||||
|
||||
14. Jurisdiction
|
||||
|
||||
Without prejudice to specific agreement between parties,
|
||||
|
||||
- any litigation resulting from the interpretation of this License, arising
|
||||
between the European Union institutions, bodies, offices or agencies, as a
|
||||
Licensor, and any Licensee, will be subject to the jurisdiction of the Court
|
||||
of Justice of the European Union, as laid down in article 272 of the Treaty on
|
||||
the Functioning of the European Union,
|
||||
|
||||
- any litigation arising between other parties and resulting from the
|
||||
interpretation of this License, will be subject to the exclusive jurisdiction
|
||||
of the competent court where the Licensor resides or conducts its primary
|
||||
business.
|
||||
|
||||
15. Applicable Law
|
||||
|
||||
Without prejudice to specific agreement between parties,
|
||||
|
||||
- this Licence shall be governed by the law of the European Union Member State
|
||||
where the Licensor has his seat, resides or has his registered office,
|
||||
|
||||
- this licence shall be governed by Belgian law if the Licensor has no seat,
|
||||
residence or registered office inside a European Union Member State.
|
||||
|
||||
Appendix
|
||||
|
||||
‘Compatible Licences’ according to Article 5 EUPL are:
|
||||
|
||||
- GNU General Public License (GPL) v. 2, v. 3
|
||||
- GNU Affero General Public License (AGPL) v. 3
|
||||
- Open Software License (OSL) v. 2.1, v. 3.0
|
||||
- Eclipse Public License (EPL) v. 1.0
|
||||
- CeCILL v. 2.0, v. 2.1
|
||||
- Mozilla Public Licence (MPL) v. 2
|
||||
- GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
|
||||
- Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
|
||||
works other than software
|
||||
- European Union Public Licence (EUPL) v. 1.1, v. 1.2
|
||||
- Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
|
||||
Reciprocity (LiLiQ-R+).
|
||||
|
||||
The European Commission may update this Appendix to later versions of the above
|
||||
licences without producing a new version of the EUPL, as long as they provide
|
||||
the rights granted in Article 2 of this Licence and protect the covered Source
|
||||
Code from exclusive appropriation.
|
||||
|
||||
All other changes or additions to this Appendix require the production of a new
|
||||
EUPL version.
|
||||
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;
|
||||
13
modules/inpostshipping/config.xml
Normal file
13
modules/inpostshipping/config.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>inpostshipping</name>
|
||||
<displayName><![CDATA[InPost Shipping]]></displayName>
|
||||
<version><![CDATA[1.6.0]]></version>
|
||||
<description><![CDATA[Official InPost integration module for PrestaShop]]></description>
|
||||
<author><![CDATA[InPost S.A.]]></author>
|
||||
<tab><![CDATA[shipping_logistics]]></tab>
|
||||
<confirmUninstall><![CDATA[Are you sure you want to uninstall this module?]]></confirmUninstall>
|
||||
<is_configurable>1</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries>pl</limited_countries>
|
||||
</module>
|
||||
32
modules/inpostshipping/config/admin/index.php
Normal file
32
modules/inpostshipping/config/admin/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;
|
||||
386
modules/inpostshipping/config/admin/services.yml
Normal file
386
modules/inpostshipping/config/admin/services.yml
Normal file
@@ -0,0 +1,386 @@
|
||||
imports:
|
||||
- { resource: ../common.yml }
|
||||
|
||||
services:
|
||||
inpost.shipping.adapter.link:
|
||||
class: InPost\Shipping\Adapter\LinkAdapter
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Adapter\LinkAdapter: '@inpost.shipping.adapter.link'
|
||||
|
||||
inpost.shipping.configuration.sending:
|
||||
class: InPost\Shipping\Configuration\SendingConfiguration
|
||||
public: true
|
||||
|
||||
InPost\Shipping\Configuration\SendingConfiguration: '@inpost.shipping.configuration.sending'
|
||||
|
||||
inpost.shipping.store.module.configuration:
|
||||
class: InPost\Shipping\Presenter\Store\Modules\ConfigurationModule
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.store.module.context:
|
||||
class: InPost\Shipping\Presenter\Store\Modules\ContextModule
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.store.module.organization:
|
||||
class: InPost\Shipping\Presenter\Store\Modules\OrganizationModule
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.store.module.services:
|
||||
class: InPost\Shipping\Presenter\Store\Modules\ServicesModule
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.store.module.carriers:
|
||||
class: InPost\Shipping\Presenter\Store\Modules\CarriersModule
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.store.presenter:
|
||||
class: InPost\Shipping\Presenter\Store\StorePresenter
|
||||
public: true
|
||||
arguments:
|
||||
$modules:
|
||||
- '@inpost.shipping.store.module.configuration'
|
||||
- '@inpost.shipping.store.module.context'
|
||||
- '@inpost.shipping.store.module.organization'
|
||||
- '@inpost.shipping.store.module.services'
|
||||
- '@inpost.shipping.store.module.carriers'
|
||||
|
||||
InPost\Shipping\Translations\Translations:
|
||||
class: InPost\Shipping\Translations\Translations
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.translations.validation_errors:
|
||||
class: InPost\Shipping\Translations\ValidationErrorTranslator
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Translations\ValidationErrorTranslator: '@inpost.shipping.translations.validation_errors'
|
||||
|
||||
inpost.shipping.translations.sending_method:
|
||||
class: InPost\Shipping\Translations\SendingMethodTranslator
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Translations\SendingMethodTranslator: '@inpost.shipping.translations.sending_method'
|
||||
|
||||
inpost.shipping.translations.shipping_service:
|
||||
class: InPost\Shipping\Translations\ShippingServiceTranslator
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Translations\ShippingServiceTranslator: '@inpost.shipping.translations.shipping_service'
|
||||
|
||||
inpost.shipping.translations.dimension_template:
|
||||
class: InPost\Shipping\Translations\DimensionTemplateTranslator
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Translations\DimensionTemplateTranslator: '@inpost.shipping.translations.dimension_template'
|
||||
|
||||
InPost\Shipping\Translations\WeekdayTranslator:
|
||||
class: InPost\Shipping\Translations\WeekdayTranslator
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Translations\FieldTranslator:
|
||||
class: InPost\Shipping\Translations\FieldTranslator
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.presenter.carrier:
|
||||
class: InPost\Shipping\Presenter\CarrierPresenter
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Presenter\CarrierPresenter: '@inpost.shipping.presenter.carrier'
|
||||
|
||||
InPost\Shipping\Presenter\ShipmentPresenter:
|
||||
class: InPost\Shipping\Presenter\ShipmentPresenter
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Presenter\ShipmentStatusPresenter:
|
||||
class: InPost\Shipping\Presenter\ShipmentStatusPresenter
|
||||
public: false
|
||||
|
||||
inpost.shipping.presenter.dispatch_point:
|
||||
class: InPost\Shipping\Presenter\DispatchPointPresenter
|
||||
public: true
|
||||
|
||||
InPost\Shipping\Presenter\DispatchPointPresenter: '@inpost.shipping.presenter.dispatch_point'
|
||||
|
||||
inpost.shipping.validator.api_configuration:
|
||||
class: InPost\Shipping\Validator\ApiConfigurationValidator
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Validator\AddressValidator:
|
||||
class: InPost\Shipping\Validator\AddressValidator
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.validator.sender:
|
||||
class: InPost\Shipping\Validator\SenderValidator
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.validator.weekend_delivery_configuration:
|
||||
class: InPost\Shipping\Validator\WeekendDeliveryConfigurationValidator
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Validator\ShipmentDimensionsValidator:
|
||||
class: InPost\Shipping\Validator\ShipmentDimensionsValidator
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.validator.orders_configuration:
|
||||
class: InPost\Shipping\Validator\OrdersConfigurationValidator
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.validator.module_controllers:
|
||||
class: InPost\Shipping\Validator\ModuleControllersValidator
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\DataProvider\OrganizationDataProvider:
|
||||
class: InPost\Shipping\DataProvider\OrganizationDataProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.data_provider.order_shipments:
|
||||
class: InPost\Shipping\DataProvider\OrderShipmentsDataProvider
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\DataProvider\CarrierDataProvider:
|
||||
class: InPost\Shipping\DataProvider\CarrierDataProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\DataProvider\OrderDimensionsDataProvider:
|
||||
class: InPost\Shipping\DataProvider\OrderDimensionsDataProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\DataProvider\TemplateDimensionsDataProvider:
|
||||
class: InPost\Shipping\DataProvider\TemplateDimensionsDataProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\ChoiceProvider\SendingMethodChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\SendingMethodChoiceProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\ChoiceProvider\DispatchPointChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\DispatchPointChoiceProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\ChoiceProvider\CarrierChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\CarrierChoiceProvider
|
||||
public: false
|
||||
|
||||
InPost\Shipping\ChoiceProvider\ShippingServiceChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\ShippingServiceChoiceProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\ChoiceProvider\DimensionTemplateChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\DimensionTemplateChoiceProvider
|
||||
autowiring_types: InPost\Shipping\ChoiceProvider\DimensionTemplateChoiceProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\ChoiceProvider\WeekdayChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\WeekdayChoiceProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\ChoiceProvider\ShipmentLabelTypeChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\ShipmentLabelTypeChoiceProvider
|
||||
public: false
|
||||
|
||||
InPost\Shipping\ChoiceProvider\ShipmentLabelFormatChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\ShipmentLabelFormatChoiceProvider
|
||||
public: false
|
||||
|
||||
InPost\Shipping\ChoiceProvider\ShipmentReferenceFieldChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\ShipmentReferenceFieldChoiceProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\ChoiceProvider\OrderStateChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\OrderStateChoiceProvider
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.choice_provider.product_template:
|
||||
class: InPost\Shipping\ChoiceProvider\ProductTemplateChoiceProvider
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\ChoiceProvider\ModuleChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\ModuleChoiceProvider
|
||||
public: false
|
||||
|
||||
InPost\Shipping\ChoiceProvider\ModulePageChoiceProvider:
|
||||
class: InPost\Shipping\ChoiceProvider\ModulePageChoiceProvider
|
||||
public: false
|
||||
|
||||
inpost.shipping.install.installer:
|
||||
class: InPost\Shipping\Install\Installer
|
||||
public: true
|
||||
arguments:
|
||||
$subInstallers:
|
||||
- '@inpost.shipping.install.hooks'
|
||||
- '@inpost.shipping.install.tabs'
|
||||
- '@inpost.shipping.install.database'
|
||||
- '@inpost.shipping.install.configuration'
|
||||
|
||||
inpost.shipping.install.hooks:
|
||||
class: InPost\Shipping\Install\Hooks
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.install.tabs:
|
||||
class: InPost\Shipping\Install\Tabs
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.install.database:
|
||||
class: InPost\Shipping\Install\Database
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.install.configuration:
|
||||
class: InPost\Shipping\Install\Configuration
|
||||
public: false
|
||||
arguments:
|
||||
$configurations:
|
||||
- '@inpost.shipping.configuration.shipx'
|
||||
- '@inpost.shipping.configuration.sending'
|
||||
- '@inpost.shipping.configuration.szybkie_zwroty'
|
||||
- '@inpost.shipping.configuration.carriers'
|
||||
- '@inpost.shipping.configuration.orders'
|
||||
|
||||
InPost\Shipping\CarrierUpdater:
|
||||
class: InPost\Shipping\CarrierUpdater
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\CarrierConfigurationUpdater:
|
||||
class: InPost\Shipping\CarrierConfigurationUpdater
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.handler.product_update:
|
||||
class: InPost\Shipping\Handler\ProductUpdateHandler
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Helper\DefaultShipmentReferenceExtractor:
|
||||
class: InPost\Shipping\Helper\DefaultShipmentReferenceExtractor
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Helper\ParcelDimensionsComparator:
|
||||
class: InPost\Shipping\Helper\ParcelDimensionsComparator
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.handler.add_service:
|
||||
class: InPost\Shipping\Handler\ShippingService\AddServiceHandler
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.handler.update_service:
|
||||
class: InPost\Shipping\Handler\ShippingService\UpdateServiceHandler
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.handler.delete_service:
|
||||
class: InPost\Shipping\Handler\ShippingService\DeleteServiceHandler
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.handler.shipment.create:
|
||||
class: InPost\Shipping\Handler\Shipment\CreateShipmentHandler
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.handler.shipment.bulk_create:
|
||||
class: InPost\Shipping\Handler\Shipment\BulkCreateShipmentHandler
|
||||
public: true
|
||||
parent: 'inpost.shipping.handler.shipment.create'
|
||||
|
||||
inpost.shipping.handler.dispatch_order.create:
|
||||
class: InPost\Shipping\Handler\DispatchOrder\CreateDispatchOrderHandler
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.handler.dispatch_order.update:
|
||||
class: InPost\Shipping\Handler\DispatchOrder\UpdateDispatchOrderHandler
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Builder\Shipment\CreateShipmentPayloadBuilder:
|
||||
class: InPost\Shipping\Builder\Shipment\CreateShipmentPayloadBuilder
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Builder\Shipment\ParcelPayloadBuilder:
|
||||
class: InPost\Shipping\Builder\Shipment\ParcelPayloadBuilder
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Builder\DispatchOrder\CreateDispatchOrderPayloadBuilder:
|
||||
class: InPost\Shipping\Builder\DispatchOrder\CreateDispatchOrderPayloadBuilder
|
||||
public: false
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.handler.shipment.print_label:
|
||||
class: InPost\Shipping\Handler\Shipment\PrintShipmentLabelHandler
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.views.modal.dispatch_order:
|
||||
class: InPost\Shipping\Views\Modal\CreateDispatchOrderModal
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
InPost\Shipping\Views\Modal\CreateDispatchOrderModal: '@inpost.shipping.views.modal.dispatch_order'
|
||||
|
||||
inpost.shipping.views.modal.shipment:
|
||||
class: InPost\Shipping\Views\Modal\CreateShipmentModal
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.views.modal.shipment_details:
|
||||
class: InPost\Shipping\Views\Modal\ShipmentDetailsModal
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.views.modal.print_label:
|
||||
class: InPost\Shipping\Views\Modal\PrintShipmentLabelModal
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.views.shipment_nav_tabs:
|
||||
class: InPost\Shipping\Views\ShipmentNavTabs
|
||||
public: true
|
||||
autowire: true
|
||||
|
||||
inpost.shipping.views.dispatch_point_nav_tabs:
|
||||
class: InPost\Shipping\Views\DispatchPointNavTabs
|
||||
public: true
|
||||
autowire: true
|
||||
147
modules/inpostshipping/config/common.yml
Normal file
147
modules/inpostshipping/config/common.yml
Normal file
@@ -0,0 +1,147 @@
|
||||
services:
|
||||
inpost.shipping.module:
|
||||
class: InPostShipping
|
||||
factory: [ 'Module', 'getInstanceByName' ]
|
||||
public: false
|
||||
arguments:
|
||||
- 'inpostshipping'
|
||||
|
||||
InPostShipping: '@inpost.shipping.module'
|
||||
|
||||
inpost.shipping.shop_context:
|
||||
class: InPost\Shipping\PrestaShopContext
|
||||
public: true
|
||||
|
||||
InPost\Shipping\PrestaShopContext: '@inpost.shipping.shop_context'
|
||||
|
||||
inpost.shipping.hook_dispatcher:
|
||||
class: InPost\Shipping\HookDispatcher
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.module'
|
||||
- '@inpost.shipping.shop_context'
|
||||
|
||||
InPost\Shipping\HookDispatcher: '@inpost.shipping.hook_dispatcher'
|
||||
|
||||
inpost.shipping.adapter.translate:
|
||||
class: InPost\Shipping\Adapter\TranslateAdapter
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.shop_context'
|
||||
|
||||
inpost.shipping.adapter.assets_manager:
|
||||
class: InPost\Shipping\Adapter\AssetsManager
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.module'
|
||||
- '@inpost.shipping.shop_context'
|
||||
|
||||
inpost.shipping.adapter.tools:
|
||||
class: InPost\Shipping\Adapter\ToolsAdapter
|
||||
public: false
|
||||
arguments:
|
||||
- '@inpost.shipping.shop_context'
|
||||
|
||||
InPost\Shipping\Adapter\ToolsAdapter: '@inpost.shipping.adapter.tools'
|
||||
|
||||
inpost.shipping.configuration.shipx:
|
||||
class: InPost\Shipping\Configuration\ShipXConfiguration
|
||||
public: true
|
||||
|
||||
InPost\Shipping\Configuration\ShipXConfiguration: '@inpost.shipping.configuration.shipx'
|
||||
|
||||
inpost.shipping.configuration.szybkie_zwroty:
|
||||
class: InPost\Shipping\Configuration\SzybkieZwrotyConfiguration
|
||||
public: true
|
||||
|
||||
InPost\Shipping\Configuration\SzybkieZwrotyConfiguration: '@inpost.shipping.configuration.szybkie_zwroty'
|
||||
|
||||
inpost.shipping.configuration.carriers:
|
||||
class: InPost\Shipping\Configuration\CarriersConfiguration
|
||||
public: true
|
||||
|
||||
InPost\Shipping\Configuration\CarriersConfiguration: '@inpost.shipping.configuration.carriers'
|
||||
|
||||
inpost.shipping.configuration.orders:
|
||||
class: InPost\Shipping\Configuration\OrdersConfiguration
|
||||
public: true
|
||||
|
||||
InPost\Shipping\Configuration\OrdersConfiguration: '@inpost.shipping.configuration.orders'
|
||||
|
||||
inpost.shipping.configuration.checkout:
|
||||
class: InPost\Shipping\Configuration\CheckoutConfiguration
|
||||
public: true
|
||||
|
||||
InPost\Shipping\Configuration\CheckoutConfiguration: '@inpost.shipping.configuration.checkout'
|
||||
|
||||
inpost.shipping.data_provider.customer_choice:
|
||||
class: InPost\Shipping\DataProvider\CustomerChoiceDataProvider
|
||||
public: true
|
||||
|
||||
InPost\Shipping\DataProvider\CustomerChoiceDataProvider: '@inpost.shipping.data_provider.customer_choice'
|
||||
|
||||
inpost.shipping.data_provider.point:
|
||||
class: InPost\Shipping\DataProvider\PointDataProvider
|
||||
public: true
|
||||
|
||||
inpost.shipping.data_provider.language:
|
||||
class: InPost\Shipping\DataProvider\LanguageDataProvider
|
||||
public: false
|
||||
arguments:
|
||||
- '@inpost.shipping.shop_context'
|
||||
|
||||
InPost\Shipping\DataProvider\LanguageDataProvider: '@inpost.shipping.data_provider.language'
|
||||
|
||||
inpost.shipping.shipx.factory.request:
|
||||
class: InPost\Shipping\ShipX\RequestFactory\ShipXRequestFactory
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.configuration.shipx'
|
||||
|
||||
InPost\Shipping\ShipX\RequestFactory\ShipXRequestFactory: '@inpost.shipping.shipx.factory.request'
|
||||
|
||||
inpost.shipping.shipx.factory.authorized_request:
|
||||
class: InPost\Shipping\ShipX\RequestFactory\AuthorizedRequestFactory
|
||||
public: true
|
||||
parent: 'inpost.shipping.shipx.factory.request'
|
||||
|
||||
InPost\Shipping\ShipX\RequestFactory\AuthorizedRequestFactory: '@inpost.shipping.shipx.factory.authorized_request'
|
||||
|
||||
inpost.shipping.shipx.factory.organization_request:
|
||||
class: InPost\Shipping\ShipX\RequestFactory\OrganizationRequestFactory
|
||||
public: true
|
||||
parent: 'inpost.shipping.shipx.factory.authorized_request'
|
||||
|
||||
inpost.shipping.presenter.point:
|
||||
class: InPost\Shipping\Presenter\PointPresenter
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.module'
|
||||
- '@inpost.shipping.data_provider.language'
|
||||
|
||||
InPost\Shipping\Presenter\PointPresenter: '@inpost.shipping.presenter.point'
|
||||
|
||||
inpost.shipping.presenter.point_address:
|
||||
class: InPost\Shipping\Presenter\PointAddressPresenter
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.presenter.point'
|
||||
|
||||
inpost.shipping.handler.shipment.update_status:
|
||||
class: InPost\Shipping\Handler\Shipment\UpdateShipmentStatusHandler
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.configuration.shipx'
|
||||
- '@inpost.shipping.configuration.orders'
|
||||
|
||||
InPost\Shipping\Handler\Shipment\UpdateShipmentStatusHandler: '@inpost.shipping.handler.shipment.update_status'
|
||||
|
||||
inpost.shipping.handler.cron_jobs:
|
||||
class: InPost\Shipping\Handler\CronJobsHandler
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.module'
|
||||
- '@inpost.shipping.adapter.tools'
|
||||
- '@inpost.shipping.handler.shipment.update_status'
|
||||
|
||||
InPost\Shipping\Handler\CronJobsHandler: '@inpost.shipping.handler.cron_jobs'
|
||||
32
modules/inpostshipping/config/front/index.php
Normal file
32
modules/inpostshipping/config/front/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;
|
||||
23
modules/inpostshipping/config/front/services.yml
Normal file
23
modules/inpostshipping/config/front/services.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
imports:
|
||||
- { resource: ../common.yml }
|
||||
|
||||
services:
|
||||
inpost.shipping.time_checker:
|
||||
class: InPost\Shipping\TimeChecker
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.configuration.carriers'
|
||||
|
||||
inpost.shipping.updater.cart_choice:
|
||||
class: InPost\Shipping\CartChoiceUpdater
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.module'
|
||||
- '@inpost.shipping.data_provider.point'
|
||||
|
||||
inpost.shipping.presenter.checkout_data:
|
||||
class: InPost\Shipping\Presenter\CheckoutDataPresenter
|
||||
public: true
|
||||
arguments:
|
||||
- '@inpost.shipping.data_provider.customer_choice'
|
||||
- '@inpost.shipping.data_provider.point'
|
||||
32
modules/inpostshipping/config/index.php
Normal file
32
modules/inpostshipping/config/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;
|
||||
13
modules/inpostshipping/config_pl.xml
Normal file
13
modules/inpostshipping/config_pl.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>inpostshipping</name>
|
||||
<displayName><![CDATA[InPost Wysyłka]]></displayName>
|
||||
<version><![CDATA[1.6.0]]></version>
|
||||
<description><![CDATA[Oficjalny moduł integracji usług InPost dla PrestaShop]]></description>
|
||||
<author><![CDATA[InPost S.A.]]></author>
|
||||
<tab><![CDATA[shipping_logistics]]></tab>
|
||||
<confirmUninstall><![CDATA[Jesteś pewien, że chcesz odinstalować ten moduł?]]></confirmUninstall>
|
||||
<is_configurable>1</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries>pl</limited_countries>
|
||||
</module>
|
||||
@@ -0,0 +1,257 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/InPostShippingAdminController.php';
|
||||
|
||||
use InPost\Shipping\Configuration\CarriersConfiguration;
|
||||
use InPost\Shipping\Configuration\CheckoutConfiguration;
|
||||
use InPost\Shipping\Configuration\OrdersConfiguration;
|
||||
use InPost\Shipping\Configuration\SendingConfiguration;
|
||||
use InPost\Shipping\Configuration\ShipXConfiguration;
|
||||
use InPost\Shipping\Configuration\SzybkieZwrotyConfiguration;
|
||||
use InPost\Shipping\Handler\ShippingService\AddServiceHandler;
|
||||
use InPost\Shipping\Handler\ShippingService\DeleteServiceHandler;
|
||||
use InPost\Shipping\Handler\ShippingService\UpdateServiceHandler;
|
||||
use InPost\Shipping\Presenter\Store\Modules\OrganizationModule;
|
||||
use InPost\Shipping\Validator\ApiConfigurationValidator;
|
||||
use InPost\Shipping\Validator\ModuleControllersValidator;
|
||||
use InPost\Shipping\Validator\OrdersConfigurationValidator;
|
||||
use InPost\Shipping\Validator\SenderValidator;
|
||||
use InPost\Shipping\Validator\WeekendDeliveryConfigurationValidator;
|
||||
|
||||
class AdminInPostAjaxController extends InPostShippingAdminController
|
||||
{
|
||||
public $ajax = true;
|
||||
|
||||
public function ajaxProcessRefreshOrganizationData()
|
||||
{
|
||||
/** @var OrganizationModule $organizationPresenter */
|
||||
$organizationPresenter = $this->module->getService('inpost.shipping.store.module.organization');
|
||||
|
||||
$this->response = $organizationPresenter->present();
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateApiConfiguration()
|
||||
{
|
||||
$token = Tools::getValue('apiToken');
|
||||
$organizationId = Tools::getValue('organizationId');
|
||||
|
||||
/** @var ApiConfigurationValidator $validator */
|
||||
$validator = $this->module->getService('inpost.shipping.validator.api_configuration');
|
||||
|
||||
if ($validator->validate([
|
||||
'token' => $token,
|
||||
'organizationId' => $organizationId,
|
||||
'sandbox' => false,
|
||||
])) {
|
||||
/** @var ShipXConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.shipx');
|
||||
$configuration->setProductionApiToken($token);
|
||||
$configuration->setProductionOrganizationId($organizationId);
|
||||
|
||||
$this->ajaxProcessRefreshOrganizationData();
|
||||
} else {
|
||||
$this->errors = $validator->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateSandboxApiConfiguration()
|
||||
{
|
||||
$token = Tools::getValue('sandboxApiToken');
|
||||
$organizationId = Tools::getValue('sandboxOrganizationId');
|
||||
$enableSandbox = Tools::getValue('enableSandbox');
|
||||
|
||||
/** @var ShipXConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.shipx');
|
||||
/** @var ApiConfigurationValidator $validator */
|
||||
$validator = $this->module->getService('inpost.shipping.validator.api_configuration');
|
||||
|
||||
if ($validator->validate([
|
||||
'token' => $token,
|
||||
'organizationId' => $organizationId,
|
||||
'sandbox' => true,
|
||||
])) {
|
||||
$configuration->setSandboxModeEnabled($enableSandbox);
|
||||
$configuration->setSandboxApiToken($token);
|
||||
$configuration->setSandboxOrganizationId($organizationId);
|
||||
} else {
|
||||
$this->errors = $validator->getErrors();
|
||||
if (!$enableSandbox) {
|
||||
$configuration->setSandboxModeEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
$this->ajaxProcessRefreshOrganizationData();
|
||||
}
|
||||
|
||||
public function ajaxProcessDisableSandboxMode()
|
||||
{
|
||||
/** @var ShipXConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.shipx');
|
||||
$configuration->setSandboxModeEnabled(false);
|
||||
|
||||
$this->ajaxProcessRefreshOrganizationData();
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateSenderDetails()
|
||||
{
|
||||
$sender = json_decode(Tools::getValue('sender'), true);
|
||||
|
||||
/** @var SenderValidator $validator */
|
||||
$validator = $this->module->getService('inpost.shipping.validator.sender');
|
||||
|
||||
if ($validator->validate($sender)) {
|
||||
/** @var SendingConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.sending');
|
||||
|
||||
$configuration->setSenderDetails($sender);
|
||||
} else {
|
||||
$this->errors = $validator->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateSendingOptions()
|
||||
{
|
||||
/** @var SendingConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.sending');
|
||||
|
||||
$configuration->setDefaultSendingMethod(Tools::getValue('sendingMethod'));
|
||||
$configuration->setDefaultLocker(json_decode(Tools::getValue('locker')));
|
||||
$configuration->setDefaultPOP(json_decode(Tools::getValue('pop')));
|
||||
$configuration->setDefaultDispatchPointId(Tools::getValue('dispatchPoint'));
|
||||
$configuration->setDefaultShipmentReferenceField(Tools::getValue('referenceField'));
|
||||
}
|
||||
|
||||
public function ajaxProcessAddService()
|
||||
{
|
||||
/** @var AddServiceHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.add_service');
|
||||
|
||||
if ($carrier = $handler->handle(Tools::getAllValues())) {
|
||||
$this->presentCarrier($carrier);
|
||||
} else {
|
||||
$this->errors = $handler->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateService()
|
||||
{
|
||||
/** @var UpdateServiceHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.update_service');
|
||||
|
||||
if ($carrier = $handler->handle(Tools::getAllValues())) {
|
||||
$this->presentCarrier($carrier);
|
||||
} else {
|
||||
$this->errors = $handler->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
protected function presentCarrier(InPostCarrierModel $carrier)
|
||||
{
|
||||
$presenter = $this->module->getService('inpost.shipping.presenter.carrier');
|
||||
|
||||
$this->response['carrier'] = $presenter->present($carrier);
|
||||
}
|
||||
|
||||
public function ajaxProcessDeleteService()
|
||||
{
|
||||
/** @var DeleteServiceHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.delete_service');
|
||||
|
||||
if (!$handler->handle(Tools::getAllValues())) {
|
||||
$this->errors = $handler->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateWeekendDelivery()
|
||||
{
|
||||
/** @var WeekendDeliveryConfigurationValidator $validator */
|
||||
$validator = $this->module->getService('inpost.shipping.validator.weekend_delivery_configuration');
|
||||
|
||||
if ($validator->validate($request = Tools::getAllValues())) {
|
||||
/** @var CarriersConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.carriers');
|
||||
|
||||
$configuration->setWeekendDeliveryStartDay($request['startDay']);
|
||||
$configuration->setWeekendDeliveryStartHour($request['startHour']);
|
||||
$configuration->setWeekendDeliveryEndDay($request['endDay']);
|
||||
$configuration->setWeekendDeliveryEndHour($request['endHour']);
|
||||
} else {
|
||||
$this->errors = $validator->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateOrdersConfiguration()
|
||||
{
|
||||
/** @var OrdersConfigurationValidator $validator */
|
||||
$validator = $this->module->getService('inpost.shipping.validator.orders_configuration');
|
||||
|
||||
if ($validator->validate($request = Tools::getAllValues())) {
|
||||
/** @var OrdersConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.orders');
|
||||
|
||||
$configuration->setDisplayOrderConfirmationLocker($request['displayOrderConfirmationLocker']);
|
||||
if ($changeStateOnLabelPrinted = $request['changeOrderStateOnShipmentLabelPrinted']) {
|
||||
$configuration->setShipmentLabelPrintedOrderStateId($request['shipmentLabelPrintedOrderStateId']);
|
||||
}
|
||||
$configuration->setChangeOrderStateOnShipmentLabelPrinted($changeStateOnLabelPrinted);
|
||||
if ($changeStateOnShipmentDelivered = $request['changeOrderStateOnShipmentDelivered']) {
|
||||
$configuration->setShipmentDeliveredOrderStateId($request['shipmentDeliveredOrderStateId']);
|
||||
}
|
||||
$configuration->setChangeOrderStateOnShipmentDelivered($changeStateOnShipmentDelivered);
|
||||
} else {
|
||||
$this->errors = $validator->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateSzybkieZwroty()
|
||||
{
|
||||
$storeName = Tools::getValue('storeName');
|
||||
|
||||
/** @var SzybkieZwrotyConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.szybkie_zwroty');
|
||||
$configuration->setStoreName($storeName);
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateCheckoutConfiguration()
|
||||
{
|
||||
/** @var CheckoutConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.checkout');
|
||||
|
||||
if (Tools::getValue('usingCustomModule')) {
|
||||
/** @var ModuleControllersValidator $validator */
|
||||
$validator = $this->module->getService('inpost.shipping.validator.module_controllers');
|
||||
|
||||
$controllers = json_decode(Tools::getValue('customControllers'), true) ?: [];
|
||||
if ($validator->validate($controllers)) {
|
||||
$configuration->setUsingCustomCheckoutModule(true);
|
||||
$configuration->setCustomCheckoutControllers($controllers);
|
||||
} else {
|
||||
$this->errors = $validator->getErrors();
|
||||
}
|
||||
} else {
|
||||
$configuration->setUsingCustomCheckoutModule(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
<?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\Handler\DispatchOrder\CreateDispatchOrderHandler;
|
||||
use InPost\Shipping\Handler\Shipment\BulkCreateShipmentHandler;
|
||||
use InPost\Shipping\Handler\Shipment\CreateShipmentHandler;
|
||||
use InPost\Shipping\Install\Tabs;
|
||||
use InPost\Shipping\ShipX\Resource\SendingMethod;
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
use InPost\Shipping\ShipX\Resource\Status;
|
||||
use InPost\Shipping\Views\Modal\ShipmentDetailsModal;
|
||||
|
||||
require_once dirname(__FILE__) . '/AdminInPostShipmentsController.php';
|
||||
|
||||
class AdminInPostConfirmedShipmentsController extends AdminInPostShipmentsController
|
||||
{
|
||||
const TRANSLATION_SOURCE = 'AdminInPostConfirmedShipmentsController';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->_select .= ' , IF(
|
||||
a.sending_method = "' . SendingMethod::DISPATCH_ORDER . '",
|
||||
a.id_dispatch_order IS NOT NULL,
|
||||
NULL
|
||||
) as dispatch_order';
|
||||
$this->_where .= ' AND a.status LIKE "' . Status::STATUS_CONFIRMED . '"';
|
||||
}
|
||||
|
||||
protected function getFieldsList()
|
||||
{
|
||||
return array_merge(parent::getFieldsList(), [
|
||||
'label_printed' => [
|
||||
'type' => 'bool',
|
||||
'title' => $this->module->l('Label printed', self::TRANSLATION_SOURCE),
|
||||
'class' => 'fixed-width-xs',
|
||||
'align' => 'center',
|
||||
'callback' => 'displayBoolean',
|
||||
],
|
||||
'dispatch_order' => [
|
||||
'type' => 'bool',
|
||||
'title' => $this->module->l('Dispatch order', self::TRANSLATION_SOURCE),
|
||||
'tmpTableFilter' => true,
|
||||
'class' => 'fixed-width-xs',
|
||||
'align' => 'center',
|
||||
'callback' => 'displayBoolean',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
protected function addListActions()
|
||||
{
|
||||
parent::addListActions();
|
||||
|
||||
$this->addRowAction('createDispatchOrder');
|
||||
$this->addRowActionSkipList(
|
||||
'createDispatchOrder',
|
||||
InPostShipmentModel::getSkipCreateDispatchOrderList($this->organizationId, $this->sandbox)
|
||||
);
|
||||
|
||||
$this->bulk_actions = array_merge(
|
||||
array_slice($this->bulk_actions, 0, 2),
|
||||
[
|
||||
'createDispatchOrders' => [
|
||||
'text' => $this->module->l('Create dispatch orders', self::TRANSLATION_SOURCE),
|
||||
'icon' => 'icon-truck',
|
||||
],
|
||||
],
|
||||
array_slice($this->bulk_actions, 2)
|
||||
);
|
||||
}
|
||||
|
||||
protected function getModalServices()
|
||||
{
|
||||
return array_merge(parent::getModalServices(), [
|
||||
'inpost.shipping.views.modal.dispatch_order',
|
||||
]);
|
||||
}
|
||||
|
||||
public function initBreadcrumbs($tab_id = null, $tabs = null)
|
||||
{
|
||||
parent::initBreadcrumbs($tab_id, $tabs);
|
||||
|
||||
if (!$this->shopContext->is17()) {
|
||||
$this->breadcrumbs[] = $this->module->l('Confirmed shipments', Tabs::TRANSLATION_SOURCE);
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessCreateShipment()
|
||||
{
|
||||
/** @var CreateShipmentHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.shipment.create');
|
||||
|
||||
if ($shipment = $handler->handle(Tools::getAllValues())) {
|
||||
$this->response['shipmentId'] = $shipment->id;
|
||||
}
|
||||
|
||||
$this->errors = $handler->getErrors();
|
||||
}
|
||||
|
||||
public function ajaxProcessBulkCreateShipment()
|
||||
{
|
||||
/** @var BulkCreateShipmentHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.shipment.bulk_create');
|
||||
|
||||
if ($shipments = $handler->handle(Tools::getAllValues())) {
|
||||
$this->response['shipmentIds'] = array_map(function (InPostShipmentModel $shipment) {
|
||||
return $shipment->id;
|
||||
}, $shipments);
|
||||
}
|
||||
|
||||
if ($handler->hasErrors()) {
|
||||
$this->errors = $handler->getErrors();
|
||||
} else {
|
||||
$this->response['redirect'] = $this->link->getAdminLink($this->controller_name);
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessViewShipment()
|
||||
{
|
||||
/** @var InPostShipmentModel $shipment */
|
||||
if ($shipment = $this->loadObject()) {
|
||||
/** @var ShipmentDetailsModal $modal */
|
||||
$modal = $this->module->getService('inpost.shipping.views.modal.shipment_details');
|
||||
|
||||
$template = $this->shopContext->is177()
|
||||
? 'views/templates/hook/177/modal/shipment-details.tpl'
|
||||
: 'views/templates/hook/modal/shipment-details.tpl';
|
||||
|
||||
$this->response['content'] = $modal->setShipment($shipment)
|
||||
->setTemplate($template)
|
||||
->renderContent();
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessCreateDispatchOrder()
|
||||
{
|
||||
/** @var InPostShipmentModel $shipment */
|
||||
if ($shipment = $this->loadObject()) {
|
||||
if ($shipment->id_dispatch_order) {
|
||||
$this->errors[] = $this->module->l('A dispatch order for this shipment already exists', self::TRANSLATION_SOURCE);
|
||||
} else {
|
||||
/** @var CreateDispatchOrderHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.dispatch_order.create');
|
||||
|
||||
if ($result = $handler->handle([$shipment->shipx_shipment_id], Tools::getValue('id_dispatch_point'))) {
|
||||
$shipment->id_dispatch_order = $result->id;
|
||||
$shipment->update();
|
||||
|
||||
$this->dispatchOrderRedirect();
|
||||
} else {
|
||||
$this->errors = $handler->getErrors();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessBulkCreateDispatchOrders()
|
||||
{
|
||||
if (Tools::isSubmit('orderIds')) {
|
||||
if (!$this->boxes = $this->getOrderShipments()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$this->boxes = Tools::getValue($this->table . 'Box');
|
||||
}
|
||||
|
||||
$this->processBulkCreateDispatchOrders();
|
||||
}
|
||||
|
||||
public function processBulkCreateDispatchOrders()
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
$skipList = $this->list_skip_actions['createdispatchorder'];
|
||||
$boxes = array_filter($this->boxes, function ($id) use ($skipList) {
|
||||
return !isset($skipList[$id]);
|
||||
});
|
||||
|
||||
if (!empty($boxes)) {
|
||||
/** @var CreateDispatchOrderHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.dispatch_order.create');
|
||||
|
||||
$collection = (new PrestaShopCollection(InPostShipmentModel::class))
|
||||
->where('id_shipment', '=', $boxes)
|
||||
->where('sending_method', '=', SendingMethod::DISPATCH_ORDER);
|
||||
|
||||
$shipmentIndex = [];
|
||||
$idIndex = [];
|
||||
|
||||
/** @var InPostShipmentModel $shipment */
|
||||
foreach ($collection as $shipment) {
|
||||
$key = in_array($shipment->service, Service::LOCKER_SERVICES) ? 'locker' : 'courier';
|
||||
$shipmentIndex[$key][] = $shipment;
|
||||
$idIndex[$key][] = $shipment->shipx_shipment_id;
|
||||
}
|
||||
|
||||
foreach ($idIndex as $key => $ids) {
|
||||
if ($result = $handler->handle($ids, Tools::getValue('id_dispatch_point'))) {
|
||||
foreach ($shipmentIndex[$key] as $shipment) {
|
||||
$shipment->id_dispatch_order = $result->id;
|
||||
$shipment->update();
|
||||
}
|
||||
} else {
|
||||
$this->errors = $handler->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
$this->dispatchOrderRedirect();
|
||||
} else {
|
||||
$this->errors[] = $this->module->l('All of the selected shipments already have dispatch orders or have a different sending method', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = $this->module->l('You must select at least one item', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
}
|
||||
|
||||
protected function dispatchOrderRedirect()
|
||||
{
|
||||
$url = $this->link->getAdminLink(Tabs::DISPATCH_ORDERS_CONTROLLER_NAME, true, [], [
|
||||
'conf' => 4,
|
||||
]);
|
||||
|
||||
if ($this->ajax) {
|
||||
$this->response['redirect'] = $url;
|
||||
} else {
|
||||
$this->redirect_after = $url;
|
||||
}
|
||||
}
|
||||
|
||||
public function displayBoolean($value)
|
||||
{
|
||||
if ($value !== null) {
|
||||
return $value
|
||||
? $this->module->l('Yes', self::TRANSLATION_SOURCE)
|
||||
: $this->module->l('No', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?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\Configuration\ShipXConfiguration;
|
||||
use InPost\Shipping\Handler\DispatchOrder\UpdateDispatchOrderHandler;
|
||||
use InPost\Shipping\Install\Tabs;
|
||||
use InPost\Shipping\Presenter\DispatchPointPresenter;
|
||||
use InPost\Shipping\ShipX\Resource\Organization\DispatchOrder;
|
||||
use InPost\Shipping\Views\ShipmentNavTabs;
|
||||
|
||||
require_once dirname(__FILE__) . '/InPostShippingAdminController.php';
|
||||
|
||||
class AdminInPostDispatchOrdersController extends InPostShippingAdminController
|
||||
{
|
||||
const TRANSLATION_SOURCE = 'AdminInPostDispatchOrdersController';
|
||||
|
||||
protected $dispatchPointList;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'inpost_dispatch_order';
|
||||
$this->identifier = 'id_dispatch_order';
|
||||
$this->bootstrap = true;
|
||||
$this->list_no_link = true;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->className = InPostDispatchOrderModel::class;
|
||||
|
||||
/** @var ShipXConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.shipx');
|
||||
|
||||
$this->_select = ' GROUP_CONCAT(s.tracking_number) as shipments, o.id_currency';
|
||||
$this->_join = '
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'inpost_dispatch_point` dp ON dp.id_dispatch_point= a.id_dispatch_point
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'inpost_shipment` s ON s.id_dispatch_order = a.id_dispatch_order
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'orders` o ON o.id_order = s.id_order';
|
||||
$this->_where = '
|
||||
AND s.sandbox = ' . ($configuration->isSandboxModeEnabled() ? 1 : 0) . '
|
||||
AND s.organization_id = ' . $configuration->getOrganizationId();
|
||||
$this->_group = 'GROUP BY a.id_dispatch_order';
|
||||
$this->_orderWay = 'desc';
|
||||
|
||||
$this->fields_list = [
|
||||
'number' => [
|
||||
'title' => $this->module->l('Dispatch order number', self::TRANSLATION_SOURCE),
|
||||
],
|
||||
'id_dispatch_point' => [
|
||||
'title' => $this->module->l('Dispatch point', self::TRANSLATION_SOURCE),
|
||||
'type' => 'select',
|
||||
'list' => $this->getDispatchPointList(),
|
||||
'filter_key' => 'a!id_dispatch_point',
|
||||
'callback' => 'displayDispatchPoint',
|
||||
],
|
||||
'price' => [
|
||||
'type' => 'price',
|
||||
'currency' => true,
|
||||
'title' => $this->module->l('Price', self::TRANSLATION_SOURCE),
|
||||
'search' => false,
|
||||
'class' => 'fixed-width-xs',
|
||||
],
|
||||
'status' => [
|
||||
'title' => $this->module->l('State', self::TRANSLATION_SOURCE),
|
||||
'filter_key' => 'a!status',
|
||||
],
|
||||
'shipments' => [
|
||||
'title' => $this->module->l('Associated shipments', self::TRANSLATION_SOURCE),
|
||||
'search' => false,
|
||||
'callback' => 'displayShipments',
|
||||
],
|
||||
'date_add' => [
|
||||
'title' => $this->module->l('Created at', self::TRANSLATION_SOURCE),
|
||||
'type' => 'datetime',
|
||||
'filter_key' => 'a!date_add',
|
||||
],
|
||||
];
|
||||
|
||||
$this->addRowAction('print');
|
||||
}
|
||||
|
||||
protected function getDispatchPointList()
|
||||
{
|
||||
if (!isset($this->dispatchPointList)) {
|
||||
$this->dispatchPointList = [];
|
||||
|
||||
/** @var DispatchPointPresenter $presenter */
|
||||
$presenter = $this->module->getService('inpost.shipping.presenter.dispatch_point');
|
||||
$collection = (new PrestaShopCollection(InPostDispatchPointModel::class))
|
||||
->where('deleted', '=', 0);
|
||||
|
||||
/** @var InPostDispatchPointModel $dispatchPoint */
|
||||
foreach ($collection as $dispatchPoint) {
|
||||
$this->dispatchPointList[$dispatchPoint->id] = $presenter->present($dispatchPoint);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->dispatchPointList;
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
|
||||
$this->module->getAssetsManager()
|
||||
->registerJavaScripts([
|
||||
_THEME_JS_DIR_ . 'custom.js',
|
||||
'admin/tools.js',
|
||||
'admin/dispatch-orders.js',
|
||||
])
|
||||
->registerStyleSheets([
|
||||
'admin/table-fix.css',
|
||||
]);
|
||||
|
||||
if (!$this->shopContext->is17()) {
|
||||
$this->module->getAssetsManager()
|
||||
->registerStyleSheets([
|
||||
'admin/nav-tabs.css',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
parent::initToolbar();
|
||||
|
||||
unset($this->toolbar_btn['new']);
|
||||
|
||||
$this->toolbar_btn['status_refresh'] = [
|
||||
'href' => $this->link->getAdminLink($this->controller_name, true, [], [
|
||||
'action' => 'refreshStatuses',
|
||||
]),
|
||||
'desc' => $this->module->l('Refresh dispatch order statuses', self::TRANSLATION_SOURCE),
|
||||
'imgclass' => 'refresh',
|
||||
];
|
||||
}
|
||||
|
||||
public function initBreadcrumbs($tab_id = null, $tabs = null)
|
||||
{
|
||||
parent::initBreadcrumbs($tab_id, $tabs);
|
||||
|
||||
if (!$this->shopContext->is17()) {
|
||||
$this->breadcrumbs = array_merge([
|
||||
$this->module->l('InPost shipments', Tabs::TRANSLATION_SOURCE),
|
||||
], $this->breadcrumbs);
|
||||
}
|
||||
}
|
||||
|
||||
public function processRefreshStatuses(array $dispatchOrderIds = [])
|
||||
{
|
||||
/** @var UpdateDispatchOrderHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.dispatch_order.update');
|
||||
|
||||
$handler->handle($dispatchOrderIds);
|
||||
|
||||
$this->redirect_after = $this->link->getAdminLink($this->controller_name, true, [], [
|
||||
'conf' => 4,
|
||||
]);
|
||||
}
|
||||
|
||||
public function ajaxProcessPrint()
|
||||
{
|
||||
$this->processPrint();
|
||||
}
|
||||
|
||||
public function processPrint()
|
||||
{
|
||||
/** @var InPostDispatchOrderModel $dispatchOrderModel */
|
||||
if ($dispatchOrderModel = $this->loadObject()) {
|
||||
$this->offerDownload(
|
||||
DispatchOrder::getPrintout($dispatchOrderModel->shipx_dispatch_order_id),
|
||||
'dispatch_order'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function displayDispatchPoint($id_dispatch_point)
|
||||
{
|
||||
return $id_dispatch_point ? $this->getDispatchPointList()[$id_dispatch_point] : null;
|
||||
}
|
||||
|
||||
public function displayShipments($shipments)
|
||||
{
|
||||
return str_replace(',', '<br/>', $shipments);
|
||||
}
|
||||
|
||||
public function displayPrintLink($token, $id)
|
||||
{
|
||||
if (!array_key_exists('print', self::$cache_lang)) {
|
||||
self::$cache_lang['print'] = $this->module->l('Print', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
return $this->displayLink($token, $id, 'print');
|
||||
}
|
||||
|
||||
protected function renderNavTabs()
|
||||
{
|
||||
/** @var ShipmentNavTabs $view */
|
||||
$view = $this->module->getService('inpost.shipping.views.shipment_nav_tabs');
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
<?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\Views\DispatchPointNavTabs;
|
||||
|
||||
require_once dirname(__FILE__) . '/InPostShippingAdminController.php';
|
||||
|
||||
class AdminInPostDispatchPointsController extends InPostShippingAdminController
|
||||
{
|
||||
const TRANSLATION_SOURCE = 'AdminInPostDispatchPointsController';
|
||||
|
||||
/** @var InPostDispatchPointModel */
|
||||
protected $object;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'inpost_dispatch_point';
|
||||
$this->identifier = 'id_dispatch_point';
|
||||
$this->bootstrap = true;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->className = InPostDispatchPointModel::class;
|
||||
|
||||
$this->_where .= ' AND a.deleted = 0';
|
||||
|
||||
$this->fields_list = [
|
||||
'name' => [
|
||||
'title' => $this->module->l('Name', self::TRANSLATION_SOURCE),
|
||||
],
|
||||
'street' => [
|
||||
'title' => $this->module->l('Street', self::TRANSLATION_SOURCE),
|
||||
],
|
||||
'building_number' => [
|
||||
'title' => $this->module->l('Building number', self::TRANSLATION_SOURCE),
|
||||
],
|
||||
'post_code' => [
|
||||
'title' => $this->module->l('Postal code', self::TRANSLATION_SOURCE),
|
||||
],
|
||||
'city' => [
|
||||
'title' => $this->module->l('City', self::TRANSLATION_SOURCE),
|
||||
],
|
||||
];
|
||||
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('delete');
|
||||
|
||||
$this->bulk_actions = [
|
||||
'delete' => [
|
||||
'text' => $this->module->l('Delete selected', self::TRANSLATION_SOURCE),
|
||||
'icon' => 'icon-trash',
|
||||
'confirm' => $this->module->l('Delete selected items?', self::TRANSLATION_SOURCE),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
|
||||
if ($this->shopContext->is17()) {
|
||||
$this->module->getAssetsManager()
|
||||
->registerJavaScripts([
|
||||
'admin/dispatch-points.js',
|
||||
])
|
||||
->registerStyleSheets([
|
||||
'admin/table-fix.css',
|
||||
]);
|
||||
} else {
|
||||
$this->module->getAssetsManager()
|
||||
->registerStyleSheets([
|
||||
'admin/nav-tabs.css',
|
||||
'admin/table-fix.css',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function initPageHeaderToolbar()
|
||||
{
|
||||
if (empty($this->display)) {
|
||||
$this->page_header_toolbar_btn['new_dispatch_point'] = [
|
||||
'href' => $this->link->getAdminLink($this->controller_name, true, [], [
|
||||
'add' . $this->table => true,
|
||||
]),
|
||||
'desc' => $this->module->l('Add a new dispatch point', self::TRANSLATION_SOURCE),
|
||||
'icon' => 'process-icon-new',
|
||||
];
|
||||
}
|
||||
|
||||
parent::initPageHeaderToolbar();
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$this->fields_form = [
|
||||
'legend' => [
|
||||
'title' => $this->module->l('Dispatch point'),
|
||||
'icon' => 'icon-truck',
|
||||
],
|
||||
'input' => [
|
||||
'name' => [
|
||||
'type' => 'text',
|
||||
'label' => $this->module->l('Name', self::TRANSLATION_SOURCE),
|
||||
'name' => 'name',
|
||||
'required' => true,
|
||||
'maxlength' => 255,
|
||||
'col' => 6,
|
||||
],
|
||||
'office_hours' => [
|
||||
'type' => 'text',
|
||||
'label' => $this->module->l('Office hours', self::TRANSLATION_SOURCE),
|
||||
'name' => 'office_hours',
|
||||
'maxlength' => 255,
|
||||
'col' => 6,
|
||||
],
|
||||
'email' => [
|
||||
'type' => 'text',
|
||||
'label' => $this->module->l('Email', self::TRANSLATION_SOURCE),
|
||||
'name' => 'email',
|
||||
'maxlength' => 255,
|
||||
'col' => 6,
|
||||
],
|
||||
'phone' => [
|
||||
'type' => 'text',
|
||||
'label' => $this->module->l('Phone', self::TRANSLATION_SOURCE),
|
||||
'name' => 'phone',
|
||||
'maxlength' => 255,
|
||||
'col' => 6,
|
||||
],
|
||||
'street' => [
|
||||
'type' => 'text',
|
||||
'label' => $this->module->l('Street', self::TRANSLATION_SOURCE),
|
||||
'required' => true,
|
||||
'name' => 'street',
|
||||
'maxlength' => 255,
|
||||
'col' => 6,
|
||||
],
|
||||
'building_number' => [
|
||||
'type' => 'text',
|
||||
'label' => $this->module->l('Building number', self::TRANSLATION_SOURCE),
|
||||
'required' => true,
|
||||
'name' => 'building_number',
|
||||
'maxlength' => 255,
|
||||
'col' => 2,
|
||||
],
|
||||
'post_code' => [
|
||||
'type' => 'text',
|
||||
'label' => $this->module->l('Postal code', self::TRANSLATION_SOURCE),
|
||||
'hint' => $this->module->l('Polish format (xx-xxx)', self::TRANSLATION_SOURCE),
|
||||
'required' => true,
|
||||
'name' => 'post_code',
|
||||
'maxlength' => 6,
|
||||
'col' => 2,
|
||||
],
|
||||
'city' => [
|
||||
'type' => 'text',
|
||||
'label' => $this->module->l('City', self::TRANSLATION_SOURCE),
|
||||
'required' => true,
|
||||
'name' => 'city',
|
||||
'maxlength' => 255,
|
||||
'col' => 6,
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
'title' => $this->module->l('Save', self::TRANSLATION_SOURCE),
|
||||
],
|
||||
];
|
||||
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
public function processAdd()
|
||||
{
|
||||
if (($result = parent::processAdd()) && $back = Tools::getValue('back')) {
|
||||
$this->redirect_after = urldecode($back);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function _childValidation()
|
||||
{
|
||||
if (!preg_match('/^\d{2}-\d{3}$/', Tools::getValue('post_code'))) {
|
||||
$this->errors['post_code'] = $this->module->l('Invalid postal code format', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
}
|
||||
|
||||
protected function renderNavTabs()
|
||||
{
|
||||
/** @var DispatchPointNavTabs $view */
|
||||
$view = $this->module->getService('inpost.shipping.views.dispatch_point_nav_tabs');
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
protected function shouldRenderNavTabs($content)
|
||||
{
|
||||
return $content === $this->layout;
|
||||
}
|
||||
|
||||
public function initHeader()
|
||||
{
|
||||
parent::initHeader();
|
||||
|
||||
if ($this->shopContext->is17()) {
|
||||
$this->context->smarty->assign([
|
||||
'current_tab_level' => 3,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?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\Install\Tabs;
|
||||
use InPost\Shipping\ShipX\Resource\Status;
|
||||
|
||||
require_once dirname(__FILE__) . '/AdminInPostShipmentsController.php';
|
||||
|
||||
class AdminInPostSentShipmentsController extends AdminInPostShipmentsController
|
||||
{
|
||||
const TRANSLATION_SOURCE = 'AdminInPostSentShipmentsController';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->_select .= ', COALESCE(sl.title, a.status) as status_title, sl.description';
|
||||
$this->_join .= '
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'inpost_shipment_status` s ON s.name = a.status
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'inpost_shipment_status_lang` sl
|
||||
ON sl.id_status = s.id_status AND sl.id_lang = ' . (int) $this->context->language->id;
|
||||
$this->_where .= ' AND a.status NOT IN ("' . implode('","', Status::NOT_SENT_STATUSES) . '")';
|
||||
}
|
||||
|
||||
protected function getFieldsList()
|
||||
{
|
||||
$fields = parent::getFieldsList();
|
||||
|
||||
return array_merge(
|
||||
array_slice($fields, 0, 2),
|
||||
[
|
||||
'status_title' => [
|
||||
'title' => $this->module->l('State', self::TRANSLATION_SOURCE),
|
||||
'type' => 'select',
|
||||
'list' => $this->getStatusList(),
|
||||
'filter_key' => 'a!status',
|
||||
'callback' => 'displayStatus',
|
||||
],
|
||||
],
|
||||
array_slice($fields, 2)
|
||||
);
|
||||
}
|
||||
|
||||
protected function getStatusList()
|
||||
{
|
||||
$list = [];
|
||||
|
||||
$collection = new PrestaShopCollection(InPostShipmentStatusModel::class, $this->context->language->id);
|
||||
|
||||
/** @var InPostShipmentStatusModel $status */
|
||||
foreach ($collection as $status) {
|
||||
$list[$status->name] = $status->title;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function initBreadcrumbs($tab_id = null, $tabs = null)
|
||||
{
|
||||
parent::initBreadcrumbs($tab_id, $tabs);
|
||||
|
||||
if (!$this->shopContext->is17()) {
|
||||
$this->breadcrumbs = array_merge([
|
||||
$this->module->l('InPost shipments', Tabs::TRANSLATION_SOURCE),
|
||||
], $this->breadcrumbs);
|
||||
}
|
||||
}
|
||||
|
||||
public function displayStatus($status, $row)
|
||||
{
|
||||
if ($description = $row['description']) {
|
||||
return sprintf(
|
||||
'<a data-toggle="tooltip" title="%s">%s</a>',
|
||||
$description,
|
||||
$status
|
||||
);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,574 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/InPostShippingAdminController.php';
|
||||
|
||||
use InPost\Shipping\CarrierUpdater;
|
||||
use InPost\Shipping\Configuration\ShipXConfiguration;
|
||||
use InPost\Shipping\Configuration\SzybkieZwrotyConfiguration;
|
||||
use InPost\Shipping\Handler\Shipment\PrintShipmentLabelHandler;
|
||||
use InPost\Shipping\Handler\Shipment\UpdateShipmentStatusHandler;
|
||||
use InPost\Shipping\ShipX\Resource\Organization\DispatchOrder;
|
||||
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
|
||||
use InPost\Shipping\ShipX\Resource\SendingMethod;
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
use InPost\Shipping\Translations\SendingMethodTranslator;
|
||||
use InPost\Shipping\Translations\ShippingServiceTranslator;
|
||||
use InPost\Shipping\Views\Modal\AbstractModal;
|
||||
use InPost\Shipping\Views\ShipmentNavTabs;
|
||||
|
||||
abstract class AdminInPostShipmentsController extends InPostShippingAdminController
|
||||
{
|
||||
const TRANSLATION_SOURCE = 'AdminInPostShipmentsController';
|
||||
|
||||
/** @var InPostShipmentModel */
|
||||
protected $object;
|
||||
|
||||
protected $sandbox;
|
||||
protected $organizationId;
|
||||
|
||||
protected $sendingMethodList;
|
||||
protected $shippingServiceList;
|
||||
|
||||
protected $szybkieZwrotyUrl;
|
||||
protected $parcelLockerShipmentIndex;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'inpost_shipment';
|
||||
$this->identifier = 'id_shipment';
|
||||
$this->bootstrap = true;
|
||||
$this->list_no_link = true;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->className = InPostShipmentModel::class;
|
||||
|
||||
/** @var ShipXConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.shipx');
|
||||
$this->sandbox = $configuration->isSandboxModeEnabled();
|
||||
$this->organizationId = $configuration->getOrganizationId();
|
||||
|
||||
if ($this->sandbox) {
|
||||
$this->warnings[] = $this->module->l('Sandbox mode is enabled', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
$this->_select = 'o.reference as order_reference, o.id_currency';
|
||||
$this->_join = 'INNER JOIN `' . _DB_PREFIX_ . 'orders` o ON o.id_order = a.id_order';
|
||||
$this->_where = '
|
||||
AND a.sandbox = ' . ($this->sandbox ? 1 : 0) . '
|
||||
AND a.organization_id = ' . $this->organizationId;
|
||||
$this->_orderWay = 'desc';
|
||||
|
||||
$this->fields_list = $this->getFieldsList();
|
||||
|
||||
if ($configuration->hasConfiguration()) {
|
||||
$this->addListActions();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFieldsList()
|
||||
{
|
||||
return [
|
||||
'tracking_number' => [
|
||||
'title' => $this->module->l('Shipment number', self::TRANSLATION_SOURCE),
|
||||
'callback' => 'displayTrackingUrl',
|
||||
],
|
||||
'order_reference' => [
|
||||
'title' => $this->module->l('Order reference', self::TRANSLATION_SOURCE),
|
||||
'callback' => 'displayOrderReference',
|
||||
'filter_key' => 'o!reference',
|
||||
],
|
||||
'price' => [
|
||||
'type' => 'price',
|
||||
'currency' => true,
|
||||
'title' => $this->module->l('Price', self::TRANSLATION_SOURCE),
|
||||
'search' => false,
|
||||
'class' => 'fixed-width-xs',
|
||||
],
|
||||
'service' => [
|
||||
'title' => $this->module->l('Service', self::TRANSLATION_SOURCE),
|
||||
'type' => 'select',
|
||||
'list' => $this->getShippingServiceList(),
|
||||
'filter_key' => 'a!service',
|
||||
'callback' => 'displayShippingServiceName',
|
||||
],
|
||||
'sending_method' => [
|
||||
'title' => $this->module->l('Sending method', self::TRANSLATION_SOURCE),
|
||||
'type' => 'select',
|
||||
'list' => $this->getSendingMethodList(),
|
||||
'filter_key' => 'a!sending_method',
|
||||
'callback' => 'displaySendingMethodName',
|
||||
],
|
||||
'phone' => [
|
||||
'title' => $this->module->l('Receiver phone', self::TRANSLATION_SOURCE),
|
||||
],
|
||||
'email' => [
|
||||
'title' => $this->module->l('Receiver email', self::TRANSLATION_SOURCE),
|
||||
],
|
||||
'reference' => [
|
||||
'title' => $this->module->l('Reference', self::TRANSLATION_SOURCE),
|
||||
'filter_key' => 'a!reference',
|
||||
],
|
||||
'date_add' => [
|
||||
'title' => $this->module->l('Created at', self::TRANSLATION_SOURCE),
|
||||
'type' => 'datetime',
|
||||
'filter_key' => 'a!date_add',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function addListActions()
|
||||
{
|
||||
$this->addRowAction('printLabel');
|
||||
$this->addRowAction('printReturnLabel');
|
||||
$this->addRowAction('printDispatchOrder');
|
||||
|
||||
$this->addRowActionSkipList(
|
||||
'printDispatchOrder',
|
||||
InPostShipmentModel::getSkipPrintDispatchOrderList($this->organizationId, $this->sandbox)
|
||||
);
|
||||
|
||||
$this->bulk_actions = [
|
||||
'printLabels' => [
|
||||
'text' => $this->module->l('Print labels', self::TRANSLATION_SOURCE),
|
||||
'icon' => 'icon-print',
|
||||
],
|
||||
'printReturnLabels' => [
|
||||
'text' => $this->module->l('Print return labels', self::TRANSLATION_SOURCE),
|
||||
'icon' => 'icon-print',
|
||||
],
|
||||
'printDispatchOrders' => [
|
||||
'text' => $this->module->l('Print dispatch orders', self::TRANSLATION_SOURCE),
|
||||
'icon' => 'icon-print',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
|
||||
$this->module->getAssetsManager()
|
||||
->registerJavaScripts([
|
||||
'admin/tools.js',
|
||||
'admin/common.js',
|
||||
'admin/shipments.js',
|
||||
])
|
||||
->registerStyleSheets([
|
||||
'admin/table-fix.css',
|
||||
]);
|
||||
|
||||
Media::addJsDef([
|
||||
'controllerUrl' => $this->link->getAdminLink($this->controller_name),
|
||||
]);
|
||||
|
||||
if (!$this->shopContext->is17()) {
|
||||
$this->module->getAssetsManager()
|
||||
->registerStyleSheets([
|
||||
'admin/nav-tabs.css',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
parent::initToolbar();
|
||||
|
||||
unset($this->toolbar_btn['new']);
|
||||
|
||||
$this->toolbar_btn['status_refresh'] = [
|
||||
'href' => $this->link->getAdminLink($this->controller_name, true, [], [
|
||||
'action' => 'refreshStatuses',
|
||||
]),
|
||||
'desc' => $this->module->l('Refresh shipment statuses', self::TRANSLATION_SOURCE),
|
||||
'imgclass' => 'refresh',
|
||||
];
|
||||
}
|
||||
|
||||
public function initModal()
|
||||
{
|
||||
parent::initModal();
|
||||
|
||||
foreach ($this->getModalServices() as $service) {
|
||||
/** @var AbstractModal $modal */
|
||||
$modal = $this->module->getService($service);
|
||||
$this->modals[] = $modal->getModalData();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getModalServices()
|
||||
{
|
||||
return [
|
||||
'inpost.shipping.views.modal.print_label',
|
||||
];
|
||||
}
|
||||
|
||||
public function ajaxProcessBulkRefreshStatuses()
|
||||
{
|
||||
if ($shipmentsIds = $this->getOrderShipments()) {
|
||||
$this->processRefreshStatuses($shipmentsIds);
|
||||
}
|
||||
}
|
||||
|
||||
public function processRefreshStatuses(array $shipmentIds = [])
|
||||
{
|
||||
/** @var UpdateShipmentStatusHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.shipment.update_status');
|
||||
|
||||
$handler->handle($shipmentIds);
|
||||
|
||||
if ($this->ajax) {
|
||||
$this->response['message'] = $this->module->l('Shipment statuses have been updated', self::TRANSLATION_SOURCE);
|
||||
} else {
|
||||
$this->redirect_after = $this->link->getAdminLink($this->controller_name, true, [], [
|
||||
'conf' => 4,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessPrintLabel()
|
||||
{
|
||||
$this->processPrintLabel();
|
||||
}
|
||||
|
||||
public function processPrintLabel()
|
||||
{
|
||||
/** @var InPostShipmentModel $shipmentModel */
|
||||
if ($shipmentModel = $this->loadObject()) {
|
||||
/** @var PrintShipmentLabelHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.shipment.print_label');
|
||||
|
||||
$label = $handler->handle(
|
||||
$shipmentModel,
|
||||
$this->resolvePrintOptions(true)
|
||||
);
|
||||
|
||||
$this->offerDownload($label, $shipmentModel->service);
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessBulkPrintLabels()
|
||||
{
|
||||
$this->boxes = Tools::getValue($this->table . 'Box');
|
||||
$this->processBulkPrintLabels();
|
||||
}
|
||||
|
||||
public function processBulkPrintLabels()
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
/** @var PrintShipmentLabelHandler $handler */
|
||||
$handler = $this->module->getService('inpost.shipping.handler.shipment.print_label');
|
||||
|
||||
$shipmentModels = InPostShipmentModel::getByIds(
|
||||
$this->boxes,
|
||||
$this->sandbox,
|
||||
$this->organizationId
|
||||
);
|
||||
|
||||
$labels = $handler->handleMultiple(
|
||||
$shipmentModels,
|
||||
$this->resolvePrintOptions(true)
|
||||
);
|
||||
|
||||
$this->offerDownload($labels);
|
||||
} else {
|
||||
$this->errors[] = $this->module->l('You must select at least one item', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessPrintReturnLabel()
|
||||
{
|
||||
$this->processPrintReturnLabel();
|
||||
}
|
||||
|
||||
public function processPrintReturnLabel()
|
||||
{
|
||||
/** @var InPostShipmentModel $shipmentModel */
|
||||
if ($shipmentModel = $this->loadObject()) {
|
||||
if (in_array($shipmentModel->service, Service::LOCKER_SERVICES)) {
|
||||
$url = $this->getSzybkieZwrotyUrl();
|
||||
if ($this->ajax) {
|
||||
$this->response['redirect'] = $url;
|
||||
} else {
|
||||
Tools::redirect($url);
|
||||
}
|
||||
} else {
|
||||
$this->offerDownload(Shipment::getReturnLabel(
|
||||
$shipmentModel->shipx_shipment_id,
|
||||
$this->resolvePrintOptions()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessBulkPrintReturnLabels()
|
||||
{
|
||||
$this->boxes = Tools::getValue($this->table . 'Box');
|
||||
$this->processBulkPrintReturnLabels();
|
||||
}
|
||||
|
||||
public function processBulkPrintReturnLabels()
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
$shipmentIds = InPostShipmentModel::getShipXShipmentIds($this->boxes, $this->sandbox, true);
|
||||
|
||||
$this->offerDownload(Shipment::getMultipleReturnLabels(
|
||||
$shipmentIds,
|
||||
$this->resolvePrintOptions()
|
||||
));
|
||||
} else {
|
||||
$this->errors[] = $this->module->l('You must select at least one item', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
}
|
||||
|
||||
protected function resolvePrintOptions($withType = false)
|
||||
{
|
||||
$query = [];
|
||||
|
||||
if ($withType) {
|
||||
$query['type'] = in_array($type = Tools::getValue('label_type'), Shipment::LABEL_TYPES)
|
||||
? $type
|
||||
: Shipment::TYPE_A6;
|
||||
}
|
||||
|
||||
$query['format'] = in_array($format = Tools::getValue('label_format'), Shipment::LABEL_FORMATS)
|
||||
? $format
|
||||
: Shipment::FORMAT_PDF;
|
||||
|
||||
return [
|
||||
'query' => $query,
|
||||
];
|
||||
}
|
||||
|
||||
public function ajaxProcessPrintDispatchOrder()
|
||||
{
|
||||
$this->processPrintDispatchOrder();
|
||||
}
|
||||
|
||||
public function processPrintDispatchOrder()
|
||||
{
|
||||
/** @var InPostShipmentModel $shipmentModel */
|
||||
if ($shipmentModel = $this->loadObject()) {
|
||||
if ($shipmentModel->id_dispatch_order) {
|
||||
$this->offerDownload(
|
||||
DispatchOrder::getPrintoutsByShipmentIds([$shipmentModel->shipx_shipment_id]),
|
||||
'dispatch_order'
|
||||
);
|
||||
} else {
|
||||
$this->errors[] = $this->module->l('No dispatch order for the selected shipment', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessBulkPrintDispatchOrders()
|
||||
{
|
||||
if (Tools::isSubmit('orderIds')) {
|
||||
if (!$this->boxes = $this->getOrderShipments()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$this->boxes = Tools::getValue($this->table . 'Box');
|
||||
}
|
||||
|
||||
$this->processBulkPrintDispatchOrders();
|
||||
}
|
||||
|
||||
public function processBulkPrintDispatchOrders()
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
$skipList = $this->list_skip_actions['printdispatchorder'];
|
||||
$boxes = array_filter($this->boxes, function ($id) use ($skipList) {
|
||||
return !isset($skipList[$id]);
|
||||
});
|
||||
|
||||
if (!empty($boxes)) {
|
||||
$ids = InPostShipmentModel::getShipXShipmentIds($this->boxes, $this->sandbox, false, true);
|
||||
|
||||
$this->offerDownload(DispatchOrder::getPrintoutsByShipmentIds($ids));
|
||||
} else {
|
||||
$this->errors[] = $this->module->l('None of the selected shipments has dispatch orders', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = $this->module->l('You must select at least one item', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getOrderShipments()
|
||||
{
|
||||
if ($orderIds = Tools::getValue('orderIds', [])) {
|
||||
$shipmentIds = InPostShipmentModel::getShipmentIdsByOrderIds(
|
||||
$orderIds,
|
||||
$this->sandbox,
|
||||
$this->organizationId
|
||||
);
|
||||
|
||||
if (empty($shipmentIds)) {
|
||||
$this->errors[] = $this->module->l('There exist no InPost shipments for selected orders', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
return $shipmentIds;
|
||||
} else {
|
||||
$this->errors[] = $this->module->l('You must select at least one item', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function getSendingMethodList()
|
||||
{
|
||||
if (!isset($this->sendingMethodList)) {
|
||||
$this->sendingMethodList = [];
|
||||
|
||||
/** @var SendingMethodTranslator $translator */
|
||||
$translator = $this->module->getService('inpost.shipping.translations.sending_method');
|
||||
foreach (SendingMethod::SENDING_METHODS as $method) {
|
||||
$this->sendingMethodList[$method] = $translator->translate($method);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->sendingMethodList;
|
||||
}
|
||||
|
||||
protected function getShippingServiceList()
|
||||
{
|
||||
if (!isset($this->shippingServiceList)) {
|
||||
$this->shippingServiceList = [];
|
||||
|
||||
/** @var ShippingServiceTranslator $translator */
|
||||
$translator = $this->module->getService('inpost.shipping.translations.shipping_service');
|
||||
foreach (Service::SERVICES as $service) {
|
||||
$this->shippingServiceList[$service] = $translator->translate($service);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->shippingServiceList;
|
||||
}
|
||||
|
||||
protected function getSzybkieZwrotyUrl()
|
||||
{
|
||||
if (!isset($this->szybkieZwrotyUrl)) {
|
||||
/** @var SzybkieZwrotyConfiguration $configuration */
|
||||
$configuration = $this->module->getService('inpost.shipping.configuration.szybkie_zwroty');
|
||||
$this->szybkieZwrotyUrl = $configuration->getOrderReturnFormUrl(true);
|
||||
}
|
||||
|
||||
return $this->szybkieZwrotyUrl;
|
||||
}
|
||||
|
||||
public function displayShippingServiceName($service)
|
||||
{
|
||||
$list = $this->getShippingServiceList();
|
||||
|
||||
return isset($list[$service]) ? $list[$service] : $service;
|
||||
}
|
||||
|
||||
public function displaySendingMethodName($method)
|
||||
{
|
||||
$list = $this->getSendingMethodList();
|
||||
|
||||
return isset($list[$method]) ? $list[$method] : $method;
|
||||
}
|
||||
|
||||
public function displayTrackingUrl($trackingNumber)
|
||||
{
|
||||
return sprintf(
|
||||
'<a href="%s" target="_blank">%s</a>',
|
||||
str_replace('@', $trackingNumber, CarrierUpdater::TRACKING_URL),
|
||||
$trackingNumber
|
||||
);
|
||||
}
|
||||
|
||||
public function displayOrderReference($reference, $row)
|
||||
{
|
||||
return sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
$this->link->getAdminLink('AdminOrders', true, [], [
|
||||
'vieworder' => true,
|
||||
'id_order' => $row['id_order'],
|
||||
]),
|
||||
$reference
|
||||
);
|
||||
}
|
||||
|
||||
public function displayCreateDispatchOrderLink($token, $id)
|
||||
{
|
||||
if (!array_key_exists('createDispatchOrder', self::$cache_lang)) {
|
||||
self::$cache_lang['createDispatchOrder'] = $this->module->l('Create dispatch order', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
return $this->displayLink($token, $id, 'createDispatchOrder', 'truck');
|
||||
}
|
||||
|
||||
public function displayPrintLabelLink($token, $id)
|
||||
{
|
||||
if (!array_key_exists('printLabel', self::$cache_lang)) {
|
||||
self::$cache_lang['printLabel'] = $this->module->l('Print label', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
return $this->displayLink($token, $id, 'printLabel');
|
||||
}
|
||||
|
||||
public function displayPrintReturnLabelLink($token, $id)
|
||||
{
|
||||
if (!array_key_exists('printReturnLabel', self::$cache_lang)) {
|
||||
self::$cache_lang['printReturnLabel'] = $this->module->l('Print return label', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
if (!isset($this->parcelLockerShipmentIndex)) {
|
||||
$this->parcelLockerShipmentIndex = [];
|
||||
|
||||
foreach ($this->_list as $item) {
|
||||
if (in_array($item['service'], Service::LOCKER_SERVICES)) {
|
||||
$this->parcelLockerShipmentIndex[$item['id_shipment']] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->displayLink(
|
||||
$token,
|
||||
$id,
|
||||
'printReturnLabel',
|
||||
'print',
|
||||
isset($this->parcelLockerShipmentIndex[$id]) ? $this->getSzybkieZwrotyUrl() : null
|
||||
);
|
||||
}
|
||||
|
||||
public function displayPrintDispatchOrderLink($token, $id)
|
||||
{
|
||||
if (!array_key_exists('printDispatchOrder', self::$cache_lang)) {
|
||||
self::$cache_lang['printDispatchOrder'] = $this->module->l('Print dispatch order', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
return $this->displayLink($token, $id, 'printDispatchOrder');
|
||||
}
|
||||
|
||||
protected function renderNavTabs()
|
||||
{
|
||||
/** @var ShipmentNavTabs $view */
|
||||
$view = $this->module->getService('inpost.shipping.views.shipment_nav_tabs');
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?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\Adapter\LinkAdapter;
|
||||
use InPost\Shipping\Api\Response;
|
||||
use InPost\Shipping\PrestaShopContext;
|
||||
use InPost\Shipping\ShipX\Exception\ShipXException;
|
||||
|
||||
abstract class InPostShippingAdminController extends ModuleAdminController
|
||||
{
|
||||
const TRANSLATION_SOURCE = 'InPostShippingAdminController';
|
||||
|
||||
/** @var InPostShipping */
|
||||
public $module;
|
||||
|
||||
public $override_folder;
|
||||
|
||||
/** @var LinkAdapter */
|
||||
protected $link;
|
||||
|
||||
/** @var PrestaShopContext */
|
||||
protected $shopContext;
|
||||
|
||||
protected $response = [
|
||||
'status' => true,
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->override_folder = '';
|
||||
|
||||
$this->link = $this->module->getService('inpost.shipping.adapter.link');
|
||||
$this->shopContext = $this->module->getService('inpost.shipping.shop_context');
|
||||
}
|
||||
|
||||
public function initPageHeaderToolbar()
|
||||
{
|
||||
$this->page_header_toolbar_btn['configuration'] = [
|
||||
'href' => $this->link->getAdminLink('AdminModules', true, [], [
|
||||
'configure' => $this->module->name,
|
||||
]),
|
||||
'desc' => $this->module->l('Module configuration', self::TRANSLATION_SOURCE),
|
||||
'icon' => 'process-icon-cogs',
|
||||
];
|
||||
|
||||
parent::initPageHeaderToolbar();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
try {
|
||||
$result = parent::postProcess();
|
||||
} catch (Exception $exception) {
|
||||
$result = false;
|
||||
$this->handleException($exception);
|
||||
}
|
||||
|
||||
if ($this->ajax) {
|
||||
$this->ajaxResponse();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function handleException(Exception $exception)
|
||||
{
|
||||
$message = $exception->getMessage();
|
||||
|
||||
if ($exception instanceof ShipXException &&
|
||||
($details = $exception->getDetails()) &&
|
||||
is_string($details)
|
||||
) {
|
||||
$message .= " $details";
|
||||
}
|
||||
|
||||
$this->errors[] = $message;
|
||||
}
|
||||
|
||||
protected function ajaxResponse()
|
||||
{
|
||||
if (!empty($this->errors)) {
|
||||
$this->response['status'] = false;
|
||||
$this->response['errors'] = $this->errors;
|
||||
}
|
||||
|
||||
header('Content-type: application/json');
|
||||
$this->ajaxDie(json_encode($this->response));
|
||||
}
|
||||
|
||||
protected function offerDownload(Response $response, $filename = null)
|
||||
{
|
||||
$contentDisposition = $response->getHeader('Content-Disposition');
|
||||
|
||||
if ($filename) {
|
||||
$contentDisposition = sprintf(
|
||||
'attachment; filename="%s_%s%s"',
|
||||
$filename,
|
||||
date('Y-m-d_H-i-s'),
|
||||
$this->getExtensionFromHeader($contentDisposition)
|
||||
);
|
||||
}
|
||||
|
||||
header('Content-type: ' . $response->getHeader('Content-type'));
|
||||
header('Content-Disposition: ' . $contentDisposition);
|
||||
echo $response->getContents();
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
protected function getExtensionFromHeader($contentDisposition)
|
||||
{
|
||||
if (preg_match('/filename[^;=\n]*=(([\'"]).*?\2|[^;\n]*)/', $contentDisposition, $matches)) {
|
||||
$filename = str_replace($matches[2], '', $matches[1]);
|
||||
|
||||
return '.' . pathinfo($filename, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function displayLink($token, $id, $action, $icon = 'print', $href = null)
|
||||
{
|
||||
$tpl = $this->createTemplate('list-action.tpl');
|
||||
|
||||
$tpl->assign([
|
||||
'id' => $id,
|
||||
'href' => $href ?: $this->link->getAdminLink($this->controller_name, false, [], [
|
||||
'action' => $action,
|
||||
$this->identifier => $id,
|
||||
'ajax' => true,
|
||||
'token' => $token,
|
||||
]),
|
||||
'class' => !$href ? 'js-' . $action : '',
|
||||
'action' => static::$cache_lang[$action],
|
||||
'icon' => $icon,
|
||||
]);
|
||||
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
protected function smartyOutputContent($content)
|
||||
{
|
||||
if ($this->shouldRenderNavTabs($content) &&
|
||||
$navTabs = $this->renderNavTabs()
|
||||
) {
|
||||
$this->context->smarty->assign('navTabs', $navTabs);
|
||||
$this->context->smarty->assign(
|
||||
'page_header_toolbar',
|
||||
$this->createTemplate('page_header_toolbar.tpl')->fetch()
|
||||
);
|
||||
$this->context->smarty->assign(
|
||||
'header',
|
||||
$this->createTemplate('header.tpl')->fetch()
|
||||
);
|
||||
}
|
||||
|
||||
parent::smartyOutputContent($content);
|
||||
}
|
||||
|
||||
protected function shouldRenderNavTabs($content)
|
||||
{
|
||||
return $content === $this->layout && !$this->shopContext->is17();
|
||||
}
|
||||
|
||||
protected function renderNavTabs()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/controllers/admin/index.php
Normal file
32
modules/inpostshipping/controllers/admin/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;
|
||||
146
modules/inpostshipping/controllers/front/ajax.php
Normal file
146
modules/inpostshipping/controllers/front/ajax.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?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\CartChoiceUpdater;
|
||||
|
||||
class InPostShippingAjaxModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
const TRANSLATION_SOURCE = 'ajax';
|
||||
|
||||
/** @var InPostShipping */
|
||||
public $module;
|
||||
|
||||
protected $response = [
|
||||
'success' => true,
|
||||
];
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (!Validate::isLoadedObject($this->context->cart)) {
|
||||
$this->errors[] = $this->module->l('Shopping cart does not exist', self::TRANSLATION_SOURCE);
|
||||
} elseif (!$carrierData = $this->getCarrierData()) {
|
||||
$this->errors[] = $this->module->l('Selected carrier is not InPost Parcel Lockers', self::TRANSLATION_SOURCE);
|
||||
} else {
|
||||
switch (Tools::getValue('action')) {
|
||||
case 'updateTargetLocker':
|
||||
$this->ajaxProcessUpdateTargetPoint($carrierData);
|
||||
break;
|
||||
case 'updateReceiverDetails':
|
||||
$this->ajaxProcessUpdateReceiverDetails($carrierData);
|
||||
break;
|
||||
case 'updateChoice':
|
||||
$this->ajaxProcessUpdateChoice($carrierData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->ajaxResponse();
|
||||
}
|
||||
|
||||
protected function ajaxProcessUpdateTargetPoint(array $carrierData)
|
||||
{
|
||||
$updater = $this->getUpdater($carrierData)
|
||||
->setTargetPoint($this->getLockerFromPost($carrierData['id_carrier']))
|
||||
->saveChoice($this->context->cart->id);
|
||||
|
||||
if ($updater->hasErrors()) {
|
||||
$this->errors = $updater->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
protected function ajaxProcessUpdateReceiverDetails(array $carrierData)
|
||||
{
|
||||
$updater = $this->getUpdater($carrierData)
|
||||
->setEmail(Tools::getValue('inpost_email'))
|
||||
->setPhone(Tools::getValue('inpost_phone'))
|
||||
->saveChoice($this->context->cart->id);
|
||||
|
||||
if ($updater->hasErrors()) {
|
||||
$this->errors = $updater->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
protected function ajaxProcessUpdateChoice(array $carrierData)
|
||||
{
|
||||
$updater = $this->getUpdater($carrierData)
|
||||
->setEmail(Tools::getValue('inpost_email'))
|
||||
->setPhone(Tools::getValue('inpost_phone'));
|
||||
|
||||
if ($carrierData['lockerService']) {
|
||||
$updater->setTargetPoint($this->getLockerFromPost($carrierData['id_carrier']));
|
||||
}
|
||||
|
||||
$updater->saveChoice($this->context->cart->id);
|
||||
|
||||
if ($updater->hasErrors()) {
|
||||
$this->errors = $updater->getErrors();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getCarrierData()
|
||||
{
|
||||
$deliveryOption = $this->context->cart->getDeliveryOption();
|
||||
|
||||
$carrierIds = explode(',', trim($deliveryOption[$this->context->cart->id_address_delivery], ','));
|
||||
foreach ($carrierIds as $carrierId) {
|
||||
if ($carrierData = InPostCarrierModel::getDataByCarrierId($carrierId)) {
|
||||
return $carrierData;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getUpdater(array $carrierData)
|
||||
{
|
||||
/** @var CartChoiceUpdater $updater */
|
||||
$updater = $this->module->getService('inpost.shipping.updater.cart_choice');
|
||||
|
||||
return $updater
|
||||
->setCartChoice(new InPostCartChoiceModel($this->context->cart->id))
|
||||
->setCarrierData($carrierData);
|
||||
}
|
||||
|
||||
protected function getLockerFromPost($id_carrier)
|
||||
{
|
||||
$locker = Tools::getValue('inpost_locker');
|
||||
|
||||
return isset($locker[$id_carrier])
|
||||
? $locker[$id_carrier]
|
||||
: null;
|
||||
}
|
||||
|
||||
protected function ajaxResponse()
|
||||
{
|
||||
if (!empty($this->errors)) {
|
||||
$this->response = [
|
||||
'success' => false,
|
||||
'errors' => $this->errors,
|
||||
];
|
||||
}
|
||||
|
||||
header('Content-type: application/json');
|
||||
$this->ajaxDie(json_encode($this->response));
|
||||
}
|
||||
}
|
||||
65
modules/inpostshipping/controllers/front/cron.php
Normal file
65
modules/inpostshipping/controllers/front/cron.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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\Exception\InvalidActionException;
|
||||
use InPost\Shipping\Handler\CronJobsHandler;
|
||||
use InPost\Shipping\ShipX\Exception\ShipXException;
|
||||
|
||||
class InPostShippingCronModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
const TRANSLATION_SOURCE = 'cron';
|
||||
|
||||
/** @var InPostShipping */
|
||||
public $module;
|
||||
|
||||
/** @var CronJobsHandler */
|
||||
protected $cronJobsHandler;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->cronJobsHandler = $this->module->getService('inpost.shipping.handler.cron_jobs');
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if ($this->cronJobsHandler->checkToken(Tools::getValue('token'))) {
|
||||
try {
|
||||
$this->cronJobsHandler->handle(Tools::getValue('action'));
|
||||
|
||||
die($this->module->l('Job complete', self::TRANSLATION_SOURCE));
|
||||
} catch (InvalidActionException $exception) {
|
||||
die($this->module->l('Unknown action', self::TRANSLATION_SOURCE));
|
||||
} catch (ShipXException $exception) {
|
||||
die(sprintf(
|
||||
$this->module->l('Job failed: %s', self::TRANSLATION_SOURCE),
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
} else {
|
||||
die($this->module->l('Invalid token', self::TRANSLATION_SOURCE));
|
||||
}
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/controllers/front/index.php
Normal file
32
modules/inpostshipping/controllers/front/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;
|
||||
32
modules/inpostshipping/controllers/index.php
Normal file
32
modules/inpostshipping/controllers/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;
|
||||
32
modules/inpostshipping/index.php
Normal file
32
modules/inpostshipping/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;
|
||||
214
modules/inpostshipping/inpostshipping.php
Normal file
214
modules/inpostshipping/inpostshipping.php
Normal file
@@ -0,0 +1,214 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (file_exists($autoloadPath = dirname(__FILE__) . '/vendor/autoload.php')) {
|
||||
require_once $autoloadPath;
|
||||
}
|
||||
|
||||
class InPostShipping extends CarrierModule
|
||||
{
|
||||
public $confirmUninstall;
|
||||
|
||||
public $id_carrier;
|
||||
|
||||
/** @var \InPost\Shipping\HookDispatcher */
|
||||
protected $hookDispatcher;
|
||||
|
||||
/** @var \InPost\Shipping\Install\Installer */
|
||||
protected $installer;
|
||||
|
||||
/** @var \InPost\Shipping\Adapter\TranslateAdapter */
|
||||
protected $translate;
|
||||
|
||||
/** @var \InPost\Shipping\Adapter\AssetsManager */
|
||||
protected $assetsManager;
|
||||
|
||||
protected $serviceContainer;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'inpostshipping';
|
||||
$this->tab = 'shipping_logistics';
|
||||
$this->version = '1.6.0';
|
||||
$this->author = 'InPost S.A.';
|
||||
$this->need_instance = 0;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('InPost Shipping');
|
||||
$this->description = $this->l('Official InPost integration module for PrestaShop');
|
||||
$this->confirmUninstall = $this->l('Are you sure you want to uninstall this module?');
|
||||
|
||||
$this->limited_countries = ['pl'];
|
||||
|
||||
$this->ps_versions_compliancy = ['min' => '1.6.1', 'max' => _PS_VERSION_];
|
||||
|
||||
if ($this->shouldUseLiveApi()) {
|
||||
$this->useLiveApi();
|
||||
}
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
return parent::install()
|
||||
&& $this->getInstaller()->install();
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
return $this->getInstaller()->uninstall()
|
||||
&& parent::uninstall();
|
||||
}
|
||||
|
||||
protected function getInstaller()
|
||||
{
|
||||
if (!isset($this->installer)) {
|
||||
$this->installer = $this->getService('inpost.shipping.install.installer');
|
||||
}
|
||||
|
||||
return $this->installer;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
/** @var \InPost\Shipping\Presenter\Store\StorePresenter $storePresenter */
|
||||
$storePresenter = $this->getService('inpost.shipping.store.presenter');
|
||||
Media::addJsDef([
|
||||
'store' => $storePresenter->present(),
|
||||
]);
|
||||
|
||||
$assetsManager = $this->getAssetsManager();
|
||||
|
||||
$assetsManager
|
||||
->registerJavaScripts([
|
||||
'app.js',
|
||||
$assetsManager::GEO_WIDGET_JS_URL,
|
||||
])
|
||||
->registerStyleSheets([$assetsManager::GEO_WIDGET_CSS_URL]);
|
||||
|
||||
return $this->display(__FILE__, '/views/templates/admin/configuration.tpl');
|
||||
}
|
||||
|
||||
public function getService($serviceName)
|
||||
{
|
||||
if (!isset($this->serviceContainer)) {
|
||||
$this->serviceContainer = new \PrestaShop\ModuleLibServiceContainer\DependencyInjection\ServiceContainer(
|
||||
$this->name,
|
||||
$this->getLocalPath()
|
||||
);
|
||||
}
|
||||
|
||||
return $this->serviceContainer->getService($serviceName);
|
||||
}
|
||||
|
||||
protected function getHookDispatcher()
|
||||
{
|
||||
if (!isset($this->hookDispatcher)) {
|
||||
$this->hookDispatcher = $this->getService('inpost.shipping.hook_dispatcher');
|
||||
}
|
||||
|
||||
return $this->hookDispatcher;
|
||||
}
|
||||
|
||||
public function __call($methodName, array $arguments)
|
||||
{
|
||||
return $this->getHookDispatcher()->dispatch($methodName, isset($arguments[0]) ? $arguments[0] : []);
|
||||
}
|
||||
|
||||
protected function useLiveApi()
|
||||
{
|
||||
/** @var \InPost\Shipping\Configuration\ShipXConfiguration $configuration */
|
||||
$configuration = $this->getService('inpost.shipping.configuration.shipx');
|
||||
$configuration->setSandboxMode(false);
|
||||
}
|
||||
|
||||
protected function getTranslate()
|
||||
{
|
||||
if (!isset($this->translate)) {
|
||||
$this->translate = $this->getService('inpost.shipping.adapter.translate');
|
||||
}
|
||||
|
||||
return $this->translate;
|
||||
}
|
||||
|
||||
public function getAssetsManager()
|
||||
{
|
||||
if (!isset($this->assetsManager)) {
|
||||
$this->assetsManager = $this->getService('inpost.shipping.adapter.assets_manager');
|
||||
}
|
||||
|
||||
return $this->assetsManager;
|
||||
}
|
||||
|
||||
public function l($string, $specific = false, $locale = null)
|
||||
{
|
||||
if (self::$_generate_config_xml_mode) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
return $this->getTranslate()->getModuleTranslation(
|
||||
$this,
|
||||
$string,
|
||||
$specific ? Tools::strtolower($specific) : $this->name,
|
||||
$locale
|
||||
);
|
||||
}
|
||||
|
||||
public function isUsingNewTranslationSystem()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @param Cart $params */
|
||||
public function getOrderShippingCost($params, $shipping_cost)
|
||||
{
|
||||
if (!$this->context->controller instanceof AdminController) {
|
||||
/** @var \InPost\Shipping\TimeChecker $timeChecker */
|
||||
$timeChecker = $this->getService('inpost.shipping.time_checker');
|
||||
|
||||
if (!$timeChecker->shouldEnableWeekendDelivery()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $shipping_cost;
|
||||
}
|
||||
|
||||
/** @param Cart $params */
|
||||
public function getOrderShippingCostExternal($params)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function shouldUseLiveApi()
|
||||
{
|
||||
return isset($this->context->controller)
|
||||
? $this->context->controller instanceof FrontController
|
||||
: 'module' === Tools::getValue('fc') && $this->name === Tools::getValue('module');
|
||||
}
|
||||
}
|
||||
BIN
modules/inpostshipping/logo.png
Normal file
BIN
modules/inpostshipping/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
127
modules/inpostshipping/src/Adapter/AssetsManager.php
Normal file
127
modules/inpostshipping/src/Adapter/AssetsManager.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?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\Adapter;
|
||||
|
||||
use Context;
|
||||
use FrontController;
|
||||
use InPost\Shipping\PrestaShopContext;
|
||||
use InPostShipping;
|
||||
use Validate;
|
||||
|
||||
class AssetsManager
|
||||
{
|
||||
const GEO_WIDGET_JS_URL = 'https://geowidget.easypack24.net/js/sdk-for-javascript.js';
|
||||
const GEO_WIDGET_CSS_URL = 'https://geowidget.easypack24.net/css/easypack.css';
|
||||
|
||||
protected $module;
|
||||
protected $shopContext;
|
||||
protected $controller;
|
||||
|
||||
public function __construct(
|
||||
InPostShipping $module,
|
||||
PrestaShopContext $shopContext
|
||||
) {
|
||||
$this->module = $module;
|
||||
$this->shopContext = $shopContext;
|
||||
$this->controller = Context::getContext()->controller;
|
||||
}
|
||||
|
||||
public function registerJavaScripts(array $javaScripts, array $params = [])
|
||||
{
|
||||
$uris = array_map([$this, 'getJavaScriptUri'], $javaScripts);
|
||||
|
||||
if ($this->controller instanceof FrontController && $this->shopContext->is17()) {
|
||||
$params['server'] = 'remote';
|
||||
|
||||
foreach ($uris as $uri) {
|
||||
$this->controller->registerJavascript(
|
||||
$this->getMediaId($uri),
|
||||
$uri,
|
||||
$params
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->controller->addJS($uris, false);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function registerStyleSheets(array $styleSheets, array $params = [])
|
||||
{
|
||||
$uris = array_map([$this, 'getStyleSheetUri'], $styleSheets);
|
||||
|
||||
if ($this->controller instanceof FrontController && $this->shopContext->is17()) {
|
||||
$params['server'] = 'remote';
|
||||
|
||||
foreach ($uris as $uri) {
|
||||
$this->controller->registerStylesheet(
|
||||
$this->getMediaId($uri),
|
||||
$uri,
|
||||
$params
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->controller->addCSS(
|
||||
$uris,
|
||||
'all',
|
||||
null,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getStyleSheetUri($path)
|
||||
{
|
||||
return $this->isModuleMedia($path)
|
||||
? $this->getModuleMediaUri('views/css/' . $path)
|
||||
: $path;
|
||||
}
|
||||
|
||||
protected function getJavaScriptUri($path)
|
||||
{
|
||||
return $this->isModuleMedia($path)
|
||||
? $this->getModuleMediaUri('views/js/' . $path)
|
||||
: $path;
|
||||
}
|
||||
|
||||
protected function getModuleMediaUri($path)
|
||||
{
|
||||
return $this->module->getPathUri() . $path . '?version=' . $this->module->version;
|
||||
}
|
||||
|
||||
protected function getMediaId($uri)
|
||||
{
|
||||
return 'inpost-' . sha1($uri);
|
||||
}
|
||||
|
||||
protected function isModuleMedia($path)
|
||||
{
|
||||
return !Validate::isAbsoluteUrl($path)
|
||||
&& strpos($path, _THEME_DIR_) === false;
|
||||
}
|
||||
}
|
||||
72
modules/inpostshipping/src/Adapter/LinkAdapter.php
Normal file
72
modules/inpostshipping/src/Adapter/LinkAdapter.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?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\Adapter;
|
||||
|
||||
use Context;
|
||||
use InPost\Shipping\PrestaShopContext;
|
||||
use PrestaShopException;
|
||||
use Tools;
|
||||
|
||||
class LinkAdapter
|
||||
{
|
||||
protected $shopContext;
|
||||
protected $link;
|
||||
|
||||
public function __construct(PrestaShopContext $shopContext)
|
||||
{
|
||||
$this->shopContext = $shopContext;
|
||||
$this->link = Context::getContext()->link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter for getAdminLink from the core Link class
|
||||
*
|
||||
* @param string $controller controller name
|
||||
* @param bool $withToken include the token in the url
|
||||
* @param array $sfRouteParams Symfony route parameters
|
||||
* @param array $params query parameters
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function getAdminLink($controller, $withToken = true, $sfRouteParams = [], $params = [])
|
||||
{
|
||||
if ($this->shopContext->is17()) {
|
||||
return $this->link->getAdminLink($controller, $withToken, $sfRouteParams, $params);
|
||||
}
|
||||
|
||||
$paramsAsString = '';
|
||||
foreach ($params as $key => $value) {
|
||||
$paramsAsString .= "&$key=$value";
|
||||
}
|
||||
|
||||
return Tools::getShopDomainSsl(true)
|
||||
. __PS_BASE_URI__
|
||||
. basename(_PS_ADMIN_DIR_) . '/'
|
||||
. $this->link->getAdminLink($controller, $withToken)
|
||||
. $paramsAsString;
|
||||
}
|
||||
}
|
||||
68
modules/inpostshipping/src/Adapter/ToolsAdapter.php
Normal file
68
modules/inpostshipping/src/Adapter/ToolsAdapter.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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\Adapter;
|
||||
|
||||
use Context;
|
||||
use Currency;
|
||||
use InPost\Shipping\PrestaShopContext;
|
||||
use Tools;
|
||||
|
||||
class ToolsAdapter
|
||||
{
|
||||
protected $shopContext;
|
||||
protected $context;
|
||||
|
||||
public function __construct(PrestaShopContext $shopContext)
|
||||
{
|
||||
$this->shopContext = $shopContext;
|
||||
$this->context = Context::getContext();
|
||||
}
|
||||
|
||||
public function displayPrice($price, $currency = null)
|
||||
{
|
||||
if (!isset($currency)) {
|
||||
$currency = $this->context->currency;
|
||||
} elseif (is_int($currency)) {
|
||||
$currency = Currency::getCurrencyInstance($currency);
|
||||
}
|
||||
|
||||
if ($this->shopContext->is176()) {
|
||||
$isoCode = is_array($currency) ? $currency['iso_code'] : $currency->iso_code;
|
||||
|
||||
return $this->context->getCurrentLocale()->formatPrice($price, $isoCode);
|
||||
}
|
||||
|
||||
return Tools::displayPrice($price, $currency);
|
||||
}
|
||||
|
||||
public function hash($value)
|
||||
{
|
||||
if ($this->shopContext->is176()) {
|
||||
return Tools::hash($value);
|
||||
}
|
||||
|
||||
return Tools::encrypt($value);
|
||||
}
|
||||
}
|
||||
139
modules/inpostshipping/src/Adapter/TranslateAdapter.php
Normal file
139
modules/inpostshipping/src/Adapter/TranslateAdapter.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?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\Adapter;
|
||||
|
||||
use Context;
|
||||
use Exception;
|
||||
use InPost\Shipping\PrestaShopContext;
|
||||
use Module;
|
||||
use Tools;
|
||||
use Translate;
|
||||
|
||||
class TranslateAdapter
|
||||
{
|
||||
protected $shopContext;
|
||||
|
||||
public function __construct(PrestaShopContext $shopContext)
|
||||
{
|
||||
$this->shopContext = $shopContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter for getting module translation for a specific locale on PS 1.6
|
||||
*
|
||||
* @param Module|string $module Module instance or name
|
||||
* @param string $originalString string to translate
|
||||
* @param string $source source of the original string
|
||||
* @param string|null $iso locale or language ISO code
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getModuleTranslation(
|
||||
$module,
|
||||
$originalString,
|
||||
$source,
|
||||
$iso = null
|
||||
) {
|
||||
if ($this->shopContext->is17()) {
|
||||
return Translate::getModuleTranslation($module, $originalString, $source, null, false, $iso);
|
||||
} elseif ($iso === null) {
|
||||
return Translate::getModuleTranslation($module, $originalString, $source);
|
||||
}
|
||||
|
||||
static $translations;
|
||||
static $langCache = [];
|
||||
static $translationsMerged = [];
|
||||
|
||||
$name = $module instanceof Module ? $module->name : $module;
|
||||
|
||||
if (empty($iso)) {
|
||||
$iso = Context::getContext()->language->iso_code;
|
||||
}
|
||||
|
||||
if (!isset($translationsMerged[$name][$iso])) {
|
||||
$filesByPriority = [
|
||||
// PrestaShop 1.5 translations
|
||||
_PS_MODULE_DIR_ . $name . '/translations/' . $iso . '.php',
|
||||
// PrestaShop 1.4 translations
|
||||
_PS_MODULE_DIR_ . $name . '/' . $iso . '.php',
|
||||
// Translations in theme
|
||||
_PS_THEME_DIR_ . 'modules/' . $name . '/translations/' . $iso . '.php',
|
||||
_PS_THEME_DIR_ . 'modules/' . $name . '/' . $iso . '.php',
|
||||
];
|
||||
|
||||
foreach ($filesByPriority as $file) {
|
||||
if (file_exists($file)) {
|
||||
$_MODULE = null;
|
||||
include $file;
|
||||
|
||||
if (isset($_MODULE)) {
|
||||
$translations[$iso] = isset($translations[$iso])
|
||||
? array_merge($translations[$iso], $_MODULE)
|
||||
: $_MODULE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$translationsMerged[$name][$iso] = true;
|
||||
}
|
||||
|
||||
$string = preg_replace("/\\\*'/", "\'", $originalString);
|
||||
$key = md5($string);
|
||||
|
||||
$cacheKey = $name . '|' . $string . '|' . $source . '|' . $iso;
|
||||
if (!isset($langCache[$cacheKey])) {
|
||||
if (!isset($translations[$iso])) {
|
||||
return str_replace('"', '"', $string);
|
||||
}
|
||||
|
||||
$currentKey = Tools::strtolower('<{' . $name . '}' . _THEME_NAME_ . '>' . $source) . '_' . $key;
|
||||
$defaultKey = Tools::strtolower('<{' . $name . '}prestashop>' . $source) . '_' . $key;
|
||||
|
||||
if ('controller' == Tools::substr($source, -10, 10)) {
|
||||
$file = Tools::substr($source, 0, -10);
|
||||
$currentKeyFile = Tools::strtolower('<{' . $name . '}' . _THEME_NAME_ . '>' . $file) . '_' . $key;
|
||||
$defaultKeyFile = Tools::strtolower('<{' . $name . '}prestashop>' . $file) . '_' . $key;
|
||||
}
|
||||
|
||||
if (isset($currentKeyFile) && !empty($translations[$iso][$currentKeyFile])) {
|
||||
$ret = Tools::stripslashes($translations[$iso][$currentKeyFile]);
|
||||
} elseif (isset($defaultKeyFile) && !empty($translations[$iso][$defaultKeyFile])) {
|
||||
$ret = Tools::stripslashes($translations[$iso][$defaultKeyFile]);
|
||||
} elseif (!empty($translations[$iso][$currentKey])) {
|
||||
$ret = Tools::stripslashes($translations[$iso][$currentKey]);
|
||||
} elseif (!empty($translations[$iso][$defaultKey])) {
|
||||
$ret = Tools::stripslashes($translations[$iso][$defaultKey]);
|
||||
} else {
|
||||
$ret = Tools::stripslashes($string);
|
||||
}
|
||||
|
||||
$langCache[$cacheKey] = htmlspecialchars($ret, ENT_COMPAT, 'UTF-8');
|
||||
}
|
||||
|
||||
return $langCache[$cacheKey];
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/src/Adapter/index.php
Normal file
32
modules/inpostshipping/src/Adapter/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;
|
||||
289
modules/inpostshipping/src/Api/Request.php
Normal file
289
modules/inpostshipping/src/Api/Request.php
Normal file
@@ -0,0 +1,289 @@
|
||||
<?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\Api;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Query;
|
||||
use GuzzleHttp\Stream\StreamInterface;
|
||||
|
||||
class Request
|
||||
{
|
||||
/**
|
||||
* Guzzle Client.
|
||||
*
|
||||
* @var Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* HTTP method
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $method;
|
||||
|
||||
/**
|
||||
* URL path.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* URL path parameters.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $pathParams = [];
|
||||
|
||||
/**
|
||||
* Request options.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* Query aggregator.
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
protected $queryAggregator;
|
||||
|
||||
/**
|
||||
* @param Client|null $client Guzzle Client
|
||||
*/
|
||||
public function __construct(Client $client = null)
|
||||
{
|
||||
if (is_null($client)) {
|
||||
$client = new Client();
|
||||
}
|
||||
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HTTP method.
|
||||
*
|
||||
* @param string $method
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URL path.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Path parameter values.
|
||||
* Path parameters encoded in the route URL as '{key}' will be replaced
|
||||
* with the appropriate value using the given key/value pairs.
|
||||
*
|
||||
* @param array $pathParams
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPathParams(array $pathParams)
|
||||
{
|
||||
$this->pathParams = array_merge($this->pathParams, $pathParams);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add request headers.
|
||||
*
|
||||
* @param array $headers
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setHeaders(array $headers)
|
||||
{
|
||||
$this->options['headers'] = isset($this->options['headers'])
|
||||
? array_merge($this->options['headers'], $headers)
|
||||
: $headers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add URL-encoded Query parameter values.
|
||||
*
|
||||
* @param array $queryParams
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setQueryParams(array $queryParams)
|
||||
{
|
||||
$this->options['query'] = isset($this->options['query'])
|
||||
? array_merge($this->options['query'], $queryParams)
|
||||
: $queryParams;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the body value.
|
||||
*
|
||||
* @param string|resource|StreamInterface $body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->options['body'] = $body;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add request JSON data.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setJson(array $data)
|
||||
{
|
||||
$this->options['json'] = isset($this->options['json'])
|
||||
? array_merge($this->options['json'], $data)
|
||||
: $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set additional Request options.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
$this->options = array_merge($this->options, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set query aggregator function.
|
||||
*
|
||||
* @param callable $aggregator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setQueryAggregator(callable $aggregator)
|
||||
{
|
||||
$this->queryAggregator = $aggregator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Request HTTP method.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Request URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
$url = $this->path;
|
||||
|
||||
foreach ($this->pathParams as $key => $value) {
|
||||
$url = str_replace("{{$key}}", $value, $url);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Request options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query aggregator.
|
||||
*
|
||||
* @return callable|null
|
||||
*/
|
||||
public function getQueryAggregator()
|
||||
{
|
||||
return $this->queryAggregator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the API Request.
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$request = $this->client->createRequest(
|
||||
$this->getMethod(),
|
||||
$this->getUrl(),
|
||||
$this->getOptions()
|
||||
);
|
||||
|
||||
if ($aggregator = $this->getQueryAggregator()) {
|
||||
$request->getQuery()->setAggregator($aggregator);
|
||||
}
|
||||
|
||||
return new Response($this->client->send($request));
|
||||
}
|
||||
}
|
||||
39
modules/inpostshipping/src/Api/RequestFactoryInterface.php
Normal file
39
modules/inpostshipping/src/Api/RequestFactoryInterface.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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\Api;
|
||||
|
||||
interface RequestFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Create a Request for a given endpoint.
|
||||
*
|
||||
* @param string $method HTTP method
|
||||
* @param string $path URL path
|
||||
* @param array $options request options
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function createRequest($method, $path, array $options = []);
|
||||
}
|
||||
385
modules/inpostshipping/src/Api/Resource/ApiResource.php
Normal file
385
modules/inpostshipping/src/Api/Resource/ApiResource.php
Normal file
@@ -0,0 +1,385 @@
|
||||
<?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\Api\Resource;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use InPost\Shipping\Api\RequestFactoryInterface;
|
||||
use stdClass;
|
||||
|
||||
abstract class ApiResource
|
||||
{
|
||||
/**
|
||||
* Format accepted by date() used to cast datetime fields.
|
||||
*
|
||||
* @const string
|
||||
*/
|
||||
const DATE_FORMAT = 'Y-m-d\TH:i:s.uP';
|
||||
|
||||
/**
|
||||
* Resource attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [];
|
||||
|
||||
/**
|
||||
* Attribute cast types.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $casts = [];
|
||||
|
||||
/**
|
||||
* @param array $data attributes
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
$this->mergeAttributes($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically retrieve attributes on the resource.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->getAttribute($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically set attributes on the resource.
|
||||
*
|
||||
* @param string $key
|
||||
* @param $value
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
$this->setAttribute($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the specified key is an attribute for the resource.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAttribute($key)
|
||||
{
|
||||
return array_key_exists($key, $this->attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an attribute on the resource.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAttribute($key)
|
||||
{
|
||||
return isset($this->attributes[$key]) ? $this->attributes[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an attribute on the resource.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAttribute($key, $value)
|
||||
{
|
||||
if ($this->castsAttribute($key)) {
|
||||
$value = $this->castAs($value, $this->getAttributeCastType($key));
|
||||
}
|
||||
|
||||
$this->attributes[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite attribute values.
|
||||
*
|
||||
* @param array $attributes values to set
|
||||
* @param bool $clear remove all previous data
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAttributes(array $attributes, $clear = false)
|
||||
{
|
||||
if ($clear) {
|
||||
$this->attributes = [];
|
||||
}
|
||||
|
||||
return $this->mergeAttributes($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge attribute values into the attributes array.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function mergeAttributes(array $attributes)
|
||||
{
|
||||
foreach ($attributes as $key => $value) {
|
||||
$this->setAttribute($key, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the specified attribute should be cast.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function castsAttribute($key)
|
||||
{
|
||||
return array_key_exists($key, static::$casts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cast type for the specified attribute.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAttributeCastType($key)
|
||||
{
|
||||
return isset(static::$casts[$key]) ? static::$casts[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast value as Carbon object (no time component).
|
||||
*
|
||||
* @param string|int $value
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
protected function castAsDate($value)
|
||||
{
|
||||
return $this->castAsDateTime($value)->startOfDay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast value as Carbon object.
|
||||
*
|
||||
* @param string|int $value
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
protected function castAsDateTime($value)
|
||||
{
|
||||
if (is_int($value)) {
|
||||
return Carbon::createFromTimestamp($value);
|
||||
} else {
|
||||
return Carbon::createFromFormat(static::DATE_FORMAT, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast value to an ApiResource object instance.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $type
|
||||
*
|
||||
* @return ApiResource[]|ApiResource|null
|
||||
*/
|
||||
protected function castAsClass($value, $type)
|
||||
{
|
||||
if (class_exists($type) && is_subclass_of($type, ApiResource::class)) {
|
||||
$collection = true;
|
||||
|
||||
foreach ($value as $key => $item) {
|
||||
if (!is_int($key) || !is_array($item)) {
|
||||
$collection = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($collection) {
|
||||
return $type::castMany($value);
|
||||
} else {
|
||||
return $type::cast($value);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ApiResource casted attribute value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function castAs($value, $type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'bool':
|
||||
return (bool) $value;
|
||||
case 'date':
|
||||
return $this->castAsDate($value);
|
||||
case 'datetime':
|
||||
return $this->castAsDateTime($value);
|
||||
case 'float':
|
||||
return (float) $value;
|
||||
case 'int':
|
||||
return (int) $value;
|
||||
case 'string':
|
||||
return (string) $value;
|
||||
default:
|
||||
return $this->castAsClass($value, $type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ApiResource instance to JSON string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toJson()
|
||||
{
|
||||
return json_encode($this->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ApiResource instance from JSON.
|
||||
*
|
||||
* @param string $data
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function fromJson($data)
|
||||
{
|
||||
return new static(json_decode($data, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id field key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getIdField()
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id field value.
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->getAttribute(static::getIdField());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new ApiResource instance from raw data.
|
||||
*
|
||||
* @param array|stdClass $data
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function cast($data)
|
||||
{
|
||||
return new static((array) $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new ApiResource instances from raw data.
|
||||
*
|
||||
* @param array[]|stdClass[] $data
|
||||
*
|
||||
* @return static[]
|
||||
*/
|
||||
public static function castMany(array $data)
|
||||
{
|
||||
return array_map('static::cast', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return ApiResource raw data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$array = [];
|
||||
|
||||
foreach ($this->attributes as $key => $value) {
|
||||
if ($value instanceof Carbon) {
|
||||
$value = $value->format(static::DATE_FORMAT);
|
||||
} elseif (is_object($value) && method_exists($value, 'toArray')) {
|
||||
$value = $value->toArray();
|
||||
}
|
||||
|
||||
$array[$key] = $value;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request factory.
|
||||
*
|
||||
* @return RequestFactoryInterface
|
||||
*/
|
||||
abstract public function getRequestFactory();
|
||||
|
||||
/**
|
||||
* Get class API URI path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getBasePath()
|
||||
{
|
||||
return static::BASE_PATH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource API URI path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getResourcePath()
|
||||
{
|
||||
return rtrim(static::BASE_PATH, '/') . '/{' . static::getIdField() . '}';
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
namespace InPost\Shipping\Api\Resource\Traits;
|
||||
|
||||
use InPost\Shipping\Api\Resource\ApiResource;
|
||||
|
||||
/**
|
||||
* @mixin ApiResource
|
||||
*/
|
||||
trait CreateTrait
|
||||
{
|
||||
/**
|
||||
* Create an ApiResource using an array of attributes.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $options
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function create(array $attributes, array $options = [])
|
||||
{
|
||||
return static::cast($attributes)->store($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an ApiResource using a constructed instance.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function store(array $options = [])
|
||||
{
|
||||
$response = $this->getRequestFactory()
|
||||
->createRequest('POST', static::getBasePath(), $options)
|
||||
->setJson($this->toArray())
|
||||
->send();
|
||||
|
||||
return $this->mergeAttributes(is_null($attributes = $response->json()) ? [] : $attributes);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
namespace InPost\Shipping\Api\Resource\Traits;
|
||||
|
||||
use InPost\Shipping\Api\Resource\ApiResource;
|
||||
|
||||
/**
|
||||
* @mixin ApiResource
|
||||
*/
|
||||
trait DeleteTrait
|
||||
{
|
||||
/**
|
||||
* Delete an ApiResource by id.
|
||||
*
|
||||
* @param string|int $id
|
||||
* @param array $options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function delete($id, array $options = [])
|
||||
{
|
||||
$instance = static::cast([static::getIdField() => $id]);
|
||||
|
||||
$instance->destroy($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an ApiResource instance.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function destroy(array $options = [])
|
||||
{
|
||||
$this->getRequestFactory()
|
||||
->createRequest('DELETE', static::getResourcePath(), $options)
|
||||
->setPathParams([static::getIdField() => $this->getId()])
|
||||
->send();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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\Api\Resource\Traits;
|
||||
|
||||
use InPost\Shipping\Api\Resource\ApiResource;
|
||||
|
||||
/**
|
||||
* @mixin ApiResource
|
||||
*/
|
||||
trait GetAllTrait
|
||||
{
|
||||
/** @return static[] */
|
||||
public static function getAll(array $options = [])
|
||||
{
|
||||
$instance = static::cast([]);
|
||||
|
||||
$response = $instance->getRequestFactory()
|
||||
->createRequest('GET', static::getBasePath(), $options)
|
||||
->send();
|
||||
|
||||
return static::castMany($response->json());
|
||||
}
|
||||
}
|
||||
69
modules/inpostshipping/src/Api/Resource/Traits/GetTrait.php
Normal file
69
modules/inpostshipping/src/Api/Resource/Traits/GetTrait.php
Normal 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\Api\Resource\Traits;
|
||||
|
||||
use InPost\Shipping\Api\Resource\ApiResource;
|
||||
|
||||
/**
|
||||
* @mixin ApiResource
|
||||
*/
|
||||
trait GetTrait
|
||||
{
|
||||
/**
|
||||
* Get an ApiResource by id.
|
||||
*
|
||||
* @param string|int $id
|
||||
* @param array $options
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function get($id, array $options = [])
|
||||
{
|
||||
$response = static::cast([])
|
||||
->getRequestFactory()
|
||||
->createRequest('GET', static::getResourcePath(), $options)
|
||||
->setPathParams([static::getIdField() => $id])
|
||||
->send();
|
||||
|
||||
return static::cast($response->json());
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh ApiResource state based on API data.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function refresh(array $options = [])
|
||||
{
|
||||
$response = $this->getRequestFactory()
|
||||
->createRequest('GET', static::getResourcePath(), $options)
|
||||
->setPathParams([static::getIdField() => $this->getId()])
|
||||
->send();
|
||||
|
||||
return $this->setAttributes($response->json(), true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?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\Api\Resource\Traits;
|
||||
|
||||
use InPost\Shipping\Api\Resource\ApiResource;
|
||||
|
||||
/**
|
||||
* @mixin ApiResource
|
||||
*/
|
||||
trait UpdateTrait
|
||||
{
|
||||
/**
|
||||
* Update an ApiResource by id using an array of attributes.
|
||||
*
|
||||
* @param int|string $id
|
||||
* @param array $attributes
|
||||
* @param array $options
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function update($id, array $attributes, array $options = [])
|
||||
{
|
||||
$instance = static::cast(array_merge($attributes, [
|
||||
static::getIdField() => $id,
|
||||
]));
|
||||
|
||||
return $instance->saveChanges($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an ApiResource using the instance attributes.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function saveChanges(array $options = [])
|
||||
{
|
||||
$response = $this->getRequestFactory()
|
||||
->createRequest('PUT', static::getResourcePath())
|
||||
->setPathParams([static::getIdField() => $this->getId()])
|
||||
->setJson($this->toArray())
|
||||
->setOptions($options)
|
||||
->send();
|
||||
|
||||
return $this->mergeAttributes(is_null($attributes = $response->json()) ? [] : $attributes);
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/src/Api/Resource/Traits/index.php
Normal file
32
modules/inpostshipping/src/Api/Resource/Traits/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;
|
||||
32
modules/inpostshipping/src/Api/Resource/index.php
Normal file
32
modules/inpostshipping/src/Api/Resource/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;
|
||||
72
modules/inpostshipping/src/Api/Response.php
Normal file
72
modules/inpostshipping/src/Api/Response.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?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\Api;
|
||||
|
||||
use GuzzleHttp\Message\ResponseInterface;
|
||||
use stdClass;
|
||||
|
||||
class Response
|
||||
{
|
||||
/**
|
||||
* Response from Guzzle.
|
||||
*
|
||||
* @var ResponseInterface
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
public function __construct(ResponseInterface $response)
|
||||
{
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get response contents as string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContents()
|
||||
{
|
||||
$this->response->getBody()->seek(0);
|
||||
|
||||
return $this->response->getBody()->getContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode response JSON.
|
||||
*
|
||||
* @param bool $associative
|
||||
*
|
||||
* @return array|stdClass|null
|
||||
*/
|
||||
public function json($associative = true)
|
||||
{
|
||||
return json_decode($this->getContents(), $associative);
|
||||
}
|
||||
|
||||
public function getHeader($header)
|
||||
{
|
||||
return $this->response->getHeader($header);
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/src/Api/index.php
Normal file
32
modules/inpostshipping/src/Api/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;
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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\Builder\DispatchOrder;
|
||||
|
||||
use InPostDispatchPointModel;
|
||||
|
||||
class CreateDispatchOrderPayloadBuilder
|
||||
{
|
||||
public function buildPayload(InPostDispatchPointModel $dispatchPoint, array $shipmentIds)
|
||||
{
|
||||
$payload = [
|
||||
'name' => $dispatchPoint->name,
|
||||
'address' => [
|
||||
'street' => $dispatchPoint->street,
|
||||
'building_number' => $dispatchPoint->building_number,
|
||||
'post_code' => $dispatchPoint->post_code,
|
||||
'city' => $dispatchPoint->city,
|
||||
],
|
||||
'shipments' => $shipmentIds,
|
||||
];
|
||||
|
||||
foreach (['phone', 'email', 'office_hours'] as $field) {
|
||||
if (!empty($dispatchPoint->{$field})) {
|
||||
$payload[$field] = $dispatchPoint->{$field};
|
||||
}
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/src/Builder/DispatchOrder/index.php
Normal file
32
modules/inpostshipping/src/Builder/DispatchOrder/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;
|
||||
@@ -0,0 +1,222 @@
|
||||
<?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\Builder\Shipment;
|
||||
|
||||
use Address;
|
||||
use Country;
|
||||
use Currency;
|
||||
use InPost\Shipping\Configuration\CarriersConfiguration;
|
||||
use InPost\Shipping\Configuration\SendingConfiguration;
|
||||
use InPost\Shipping\DataProvider\CarrierDataProvider;
|
||||
use InPost\Shipping\DataProvider\CustomerChoiceDataProvider;
|
||||
use InPost\Shipping\Helper\DefaultShipmentReferenceExtractor;
|
||||
use InPost\Shipping\ShipX\Resource\SendingMethod;
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
use Order;
|
||||
|
||||
class CreateShipmentPayloadBuilder
|
||||
{
|
||||
protected $sendingConfiguration;
|
||||
protected $customerChoiceDataProvider;
|
||||
protected $carriersConfiguration;
|
||||
protected $carrierDataProvider;
|
||||
protected $referenceExtractor;
|
||||
protected $parcelPayloadBuilder;
|
||||
|
||||
public function __construct(
|
||||
SendingConfiguration $sendingConfiguration,
|
||||
CustomerChoiceDataProvider $customerChoiceDataProvider,
|
||||
CarriersConfiguration $carriersConfiguration,
|
||||
CarrierDataProvider $carrierDataProvider,
|
||||
DefaultShipmentReferenceExtractor $referenceExtractor,
|
||||
ParcelPayloadBuilder $parcelPayloadBuilder
|
||||
) {
|
||||
$this->sendingConfiguration = $sendingConfiguration;
|
||||
$this->customerChoiceDataProvider = $customerChoiceDataProvider;
|
||||
$this->carriersConfiguration = $carriersConfiguration;
|
||||
$this->carrierDataProvider = $carrierDataProvider;
|
||||
$this->referenceExtractor = $referenceExtractor;
|
||||
$this->parcelPayloadBuilder = $parcelPayloadBuilder;
|
||||
}
|
||||
|
||||
public function buildPayload(Order $order, array $request = [])
|
||||
{
|
||||
$currency = Currency::getCurrencyInstance($order->id_currency);
|
||||
|
||||
if (!empty($request)) {
|
||||
$payload = $this->buildPayloadFromRequestData($request, $currency);
|
||||
} else {
|
||||
$payload = $this->buildPayloadFromOrderData($order, $currency);
|
||||
}
|
||||
|
||||
if (!empty($payload)) {
|
||||
$address = new Address($order->id_address_delivery);
|
||||
|
||||
$payload['receiver'] = array_merge($payload['receiver'], [
|
||||
'first_name' => $address->firstname,
|
||||
'last_name' => $address->lastname,
|
||||
'address' => [
|
||||
'line1' => $address->address1,
|
||||
'line2' => $address->address2,
|
||||
'city' => $address->city,
|
||||
'post_code' => $address->postcode,
|
||||
'country_code' => Country::getIsoById($address->id_country),
|
||||
],
|
||||
]);
|
||||
|
||||
if ($address->company) {
|
||||
$payload['receiver']['company_name'] = $address->company;
|
||||
}
|
||||
|
||||
$payload['external_customer_id'] = 'PrestaShop';
|
||||
|
||||
if ($sender = $this->sendingConfiguration->getSenderDetails()) {
|
||||
$sender['phone'] = preg_replace('/\s+/', '', $sender['phone']);
|
||||
$payload['sender'] = $sender;
|
||||
}
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
protected function buildPayloadFromRequestData(array $request, Currency $currency)
|
||||
{
|
||||
$payload = [
|
||||
'service' => $request['service'],
|
||||
'receiver' => [
|
||||
'email' => $request['email'],
|
||||
'phone' => $request['phone'],
|
||||
],
|
||||
'custom_attributes' => [
|
||||
'sending_method' => $request['sending_method'],
|
||||
],
|
||||
'parcels' => [],
|
||||
];
|
||||
|
||||
$lockerService = in_array($request['service'], Service::LOCKER_SERVICES);
|
||||
|
||||
if ($request['sending_method'] === SendingMethod::POP && $lockerService) {
|
||||
$payload['custom_attributes']['dropoff_point'] = $request['dropoff_pop'];
|
||||
} elseif ($request['sending_method'] === SendingMethod::PARCEL_LOCKER) {
|
||||
$payload['custom_attributes']['dropoff_point'] = $request['dropoff_locker'];
|
||||
}
|
||||
|
||||
$payload['parcels'][] = $this->parcelPayloadBuilder->buildPayloadFromRequestData($request);
|
||||
|
||||
if ($request['service'] === Service::INPOST_LOCKER_STANDARD) {
|
||||
$payload['custom_attributes']['target_point'] = $request['target_point'];
|
||||
|
||||
if ($request['weekend_delivery']) {
|
||||
$payload['end_of_week_collection'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($request['reference']) {
|
||||
if ($lockerService) {
|
||||
$payload['reference'] = $request['reference'];
|
||||
} else {
|
||||
$payload['comments'] = $request['reference'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($request['cod']) {
|
||||
$payload['cod'] = [
|
||||
'amount' => (float) str_replace(',', '.', $request['cod_amount']),
|
||||
'currency' => $currency->iso_code,
|
||||
];
|
||||
}
|
||||
|
||||
if ($request['insurance']) {
|
||||
$payload['insurance'] = [
|
||||
'amount' => (float) str_replace(',', '.', $request['insurance_amount']),
|
||||
'currency' => $currency->iso_code,
|
||||
];
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
protected function buildPayloadFromOrderData(Order $order, Currency $currency)
|
||||
{
|
||||
if ($customerChoice = $this->customerChoiceDataProvider->getDataByCartId($order->id_cart)) {
|
||||
$payload = [
|
||||
'service' => $customerChoice->service,
|
||||
'receiver' => [
|
||||
'email' => $customerChoice->email,
|
||||
'phone' => $customerChoice->phone,
|
||||
],
|
||||
'parcels' => [],
|
||||
];
|
||||
|
||||
$reference = $this->referenceExtractor->getShipmentReference($order);
|
||||
|
||||
if (in_array($customerChoice->service, Service::LOCKER_SERVICES)) {
|
||||
$payload['reference'] = $reference;
|
||||
} else {
|
||||
$payload['comments'] = $reference;
|
||||
}
|
||||
|
||||
$inPostCarrier = $this->carrierDataProvider->getInPostCarrierByCarrierId($order->id_carrier);
|
||||
|
||||
if ($sendingMethod = $this->carriersConfiguration->getDefaultSendingMethods($customerChoice->service)) {
|
||||
$payload['custom_attributes']['sending_method'] = $sendingMethod;
|
||||
|
||||
if ($sendingMethod === SendingMethod::POP &&
|
||||
($point = $this->sendingConfiguration->getDefaultPOP()) ||
|
||||
$sendingMethod === SendingMethod::PARCEL_LOCKER &&
|
||||
$point = $this->sendingConfiguration->getDefaultLocker()
|
||||
) {
|
||||
$payload['custom_attributes']['dropoff_point'] = $point['name'];
|
||||
}
|
||||
}
|
||||
|
||||
$payload['parcels'][] = $this->parcelPayloadBuilder->buildPayloadByOrder($order, $customerChoice->service);
|
||||
|
||||
if (null !== $inPostCarrier && $inPostCarrier->cod) {
|
||||
$payload['cod'] = [
|
||||
'amount' => $order->total_paid,
|
||||
'currency' => $currency->iso_code,
|
||||
];
|
||||
}
|
||||
|
||||
if ($customerChoice->service === Service::INPOST_LOCKER_STANDARD) {
|
||||
$payload['custom_attributes']['target_point'] = $customerChoice->point;
|
||||
|
||||
if (null !== $inPostCarrier && $inPostCarrier->weekend_delivery) {
|
||||
$payload['end_of_week_collection'] = true;
|
||||
}
|
||||
} elseif (null !== $inPostCarrier && $inPostCarrier->cod) {
|
||||
$payload['insurance'] = [
|
||||
'amount' => $order->total_paid,
|
||||
'currency' => $currency->iso_code,
|
||||
];
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?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\Builder\Shipment;
|
||||
|
||||
use InPost\Shipping\Configuration\CarriersConfiguration;
|
||||
use InPost\Shipping\DataProvider\CarrierDataProvider;
|
||||
use InPost\Shipping\DataProvider\OrderDimensionsDataProvider;
|
||||
use InPost\Shipping\Helper\ParcelDimensionsComparator;
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
use Order;
|
||||
|
||||
class ParcelPayloadBuilder
|
||||
{
|
||||
protected $carriersConfiguration;
|
||||
protected $carrierDataProvider;
|
||||
protected $dimensionsDataProvider;
|
||||
protected $dimensionsComparator;
|
||||
|
||||
public function __construct(
|
||||
CarriersConfiguration $carriersConfiguration,
|
||||
CarrierDataProvider $carrierDataProvider,
|
||||
OrderDimensionsDataProvider $dimensionsDataProvider,
|
||||
ParcelDimensionsComparator $dimensionsComparator
|
||||
) {
|
||||
$this->carriersConfiguration = $carriersConfiguration;
|
||||
$this->carrierDataProvider = $carrierDataProvider;
|
||||
$this->dimensionsDataProvider = $dimensionsDataProvider;
|
||||
$this->dimensionsComparator = $dimensionsComparator;
|
||||
}
|
||||
|
||||
public function buildPayloadFromRequestData(array $request)
|
||||
{
|
||||
if ($request['use_template']) {
|
||||
return [
|
||||
'template' => $request['template'],
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'dimensions' => array_map(function ($dimension) {
|
||||
return (float) str_replace(',', '.', $dimension);
|
||||
}, $request['dimensions']),
|
||||
'weight' => [
|
||||
'amount' => (float) str_replace(',', '.', $request['weight']),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function buildPayloadByOrder(Order $order, $service)
|
||||
{
|
||||
if ($this->shouldUseProductDimensions($order) &&
|
||||
$parcel = $this->getParcelByProductDimensions($order, $service)
|
||||
) {
|
||||
return $parcel;
|
||||
} elseif ($dimensions = $this->carriersConfiguration->getDefaultShipmentDimensions($service)) {
|
||||
return [
|
||||
'weight' => [
|
||||
'amount' => $order->getTotalWeight() ?: $dimensions['weight'],
|
||||
],
|
||||
'dimensions' => array_filter($dimensions, function ($key) {
|
||||
return $key !== 'weight';
|
||||
}, ARRAY_FILTER_USE_KEY),
|
||||
];
|
||||
} elseif ($template = $this->carriersConfiguration->getDefaultDimensionTemplates($service)) {
|
||||
return [
|
||||
'template' => $template,
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'weight' => [
|
||||
'amount' => $order->getTotalWeight(),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
protected function getParcelByProductDimensions(Order $order, $service)
|
||||
{
|
||||
$template = $this->getLargestTemplateByOrder($order, $service);
|
||||
$orderDimensions = $this->getDimensionsByLargestOrderProduct($order);
|
||||
|
||||
if (null !== $template && (
|
||||
null === $orderDimensions ||
|
||||
$this->dimensionsComparator->compareTemplateWithDimensions($template, $orderDimensions) >= 0
|
||||
)) {
|
||||
return [
|
||||
'template' => $template,
|
||||
];
|
||||
}
|
||||
|
||||
return $orderDimensions;
|
||||
}
|
||||
|
||||
protected function getLargestTemplateByOrder(Order $order, $service)
|
||||
{
|
||||
if (in_array($service, Service::LOCKER_SERVICES) &&
|
||||
$templates = $this->dimensionsDataProvider->getProductDimensionTemplatesByOrderId($order->id)
|
||||
) {
|
||||
return $this->dimensionsComparator->getLargestTemplate($templates);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getDimensionsByLargestOrderProduct(Order $order)
|
||||
{
|
||||
if ($dimensions = $this->dimensionsDataProvider->getLargestProductDimensionsByOrderId($order->id)) {
|
||||
return [
|
||||
'dimensions' => $dimensions,
|
||||
'weight' => [
|
||||
'amount' => $order->getTotalWeight(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function shouldUseProductDimensions(Order $order)
|
||||
{
|
||||
$inPostCarrier = $this->carrierDataProvider->getInPostCarrierByCarrierId($order->id_carrier);
|
||||
|
||||
return null !== $inPostCarrier && $inPostCarrier->use_product_dimensions;
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/src/Builder/Shipment/index.php
Normal file
32
modules/inpostshipping/src/Builder/Shipment/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;
|
||||
32
modules/inpostshipping/src/Builder/index.php
Normal file
32
modules/inpostshipping/src/Builder/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;
|
||||
66
modules/inpostshipping/src/Cache/CacheClearer.php
Normal file
66
modules/inpostshipping/src/Cache/CacheClearer.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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\Cache;
|
||||
|
||||
use Module;
|
||||
use PrestaShop\ModuleLibCacheDirectoryProvider\Cache\CacheDirectoryProvider;
|
||||
|
||||
class CacheClearer
|
||||
{
|
||||
const CONTAINERS = [
|
||||
'admin',
|
||||
'front',
|
||||
];
|
||||
|
||||
protected $module;
|
||||
protected $cacheDirectory;
|
||||
|
||||
public function __construct(Module $module)
|
||||
{
|
||||
$this->module = $module;
|
||||
|
||||
$this->cacheDirectory = new CacheDirectoryProvider(
|
||||
_PS_VERSION_,
|
||||
_PS_ROOT_DIR_,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
public function clear()
|
||||
{
|
||||
foreach (self::CONTAINERS as $containerName) {
|
||||
$containerFilePath = sprintf(
|
||||
'%s/%s%sContainer.php',
|
||||
rtrim($this->cacheDirectory->getPath(), '/'),
|
||||
ucfirst($this->module->name),
|
||||
ucfirst($containerName)
|
||||
);
|
||||
|
||||
if (file_exists($containerFilePath)) {
|
||||
unlink($containerFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/src/Cache/index.php
Normal file
32
modules/inpostshipping/src/Cache/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;
|
||||
96
modules/inpostshipping/src/CarrierConfigurationUpdater.php
Normal file
96
modules/inpostshipping/src/CarrierConfigurationUpdater.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?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;
|
||||
|
||||
use InPost\Shipping\ChoiceProvider\ShippingServiceChoiceProvider;
|
||||
use InPost\Shipping\Configuration\CarriersConfiguration;
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
use InPost\Shipping\Traits\ErrorsTrait;
|
||||
use InPost\Shipping\Validator\ShipmentDimensionsValidator;
|
||||
use InPostShipping;
|
||||
|
||||
class CarrierConfigurationUpdater
|
||||
{
|
||||
use ErrorsTrait;
|
||||
|
||||
const TRANSLATION_SOURCE = 'CarrierConfigurationUpdater';
|
||||
|
||||
protected $module;
|
||||
protected $carriersConfiguration;
|
||||
protected $serviceChoiceProvider;
|
||||
protected $dimensionsValidator;
|
||||
|
||||
public function __construct(
|
||||
InPostShipping $module,
|
||||
CarriersConfiguration $carriersConfiguration,
|
||||
ShippingServiceChoiceProvider $serviceChoiceProvider,
|
||||
ShipmentDimensionsValidator $dimensionsValidator
|
||||
) {
|
||||
$this->module = $module;
|
||||
$this->carriersConfiguration = $carriersConfiguration;
|
||||
$this->serviceChoiceProvider = $serviceChoiceProvider;
|
||||
$this->dimensionsValidator = $dimensionsValidator;
|
||||
}
|
||||
|
||||
public function update(array $request)
|
||||
{
|
||||
$this->resetErrors();
|
||||
|
||||
if (!in_array($service = $request['service'], Service::SERVICES)) {
|
||||
$this->errors['service'] = $this->module->l('Invalid shipping service', self::TRANSLATION_SOURCE);
|
||||
} else {
|
||||
$sendingMethod = $request['defaultSendingMethod'];
|
||||
if (!in_array($sendingMethod, $this->serviceChoiceProvider->getAvailableSendingMethods($service))) {
|
||||
$this->errors['defaultSendingMethod'] = $this->module->l('This sending method is not available for the selected service', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
if (in_array($service, Service::LOCKER_SERVICES) && $template = $request['defaultTemplate']) {
|
||||
$dimensions = [];
|
||||
if (!in_array($template, $this->serviceChoiceProvider->getAvailableTemplates($service))) {
|
||||
$this->errors['defaultTemplate'] = $this->module->l('This template is not available for the selected service', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
} else {
|
||||
$template = null;
|
||||
$dimensions = array_map(function ($dimension) {
|
||||
return (float) str_replace(',', '.', $dimension);
|
||||
}, json_decode($request['defaultDimensions'], true));
|
||||
|
||||
if (!$this->dimensionsValidator->validate($dimensions)) {
|
||||
$this->errors = array_merge($this->errors, $this->dimensionsValidator->getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->hasErrors()) {
|
||||
$this->carriersConfiguration->setDefaultDimensionTemplate($service, $template);
|
||||
$this->carriersConfiguration->setDefaultShipmentDimensions($service, $dimensions);
|
||||
$this->carriersConfiguration->setDefaultSendingMethod($service, $sendingMethod);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
306
modules/inpostshipping/src/CarrierUpdater.php
Normal file
306
modules/inpostshipping/src/CarrierUpdater.php
Normal file
@@ -0,0 +1,306 @@
|
||||
<?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;
|
||||
|
||||
use Carrier;
|
||||
use Context;
|
||||
use Country;
|
||||
use Db;
|
||||
use Exception;
|
||||
use Group;
|
||||
use InPost\Shipping\DataProvider\LanguageDataProvider;
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
use InPost\Shipping\Traits\ErrorsTrait;
|
||||
use InPostShipping;
|
||||
use Language;
|
||||
use Module;
|
||||
use PrestaShopCollection;
|
||||
use RangeWeight;
|
||||
use TaxRulesGroup;
|
||||
use Validate;
|
||||
|
||||
class CarrierUpdater
|
||||
{
|
||||
use ErrorsTrait;
|
||||
|
||||
const TRANSLATION_SOURCE = 'CarrierUpdater';
|
||||
|
||||
const TRACKING_URL = 'https://inpost.pl/sledzenie-przesylek?number=@';
|
||||
|
||||
protected $module;
|
||||
protected $languageDataProvider;
|
||||
|
||||
protected $groups = [];
|
||||
|
||||
protected $id_country;
|
||||
protected $id_zone;
|
||||
protected $id_tax_rule_group;
|
||||
|
||||
/**
|
||||
* @var Carrier
|
||||
*/
|
||||
protected $carrier;
|
||||
protected $service;
|
||||
protected $updateSettings = true;
|
||||
|
||||
public function __construct(
|
||||
InPostShipping $module,
|
||||
LanguageDataProvider $languageDataProvider
|
||||
) {
|
||||
$this->module = $module;
|
||||
$this->languageDataProvider = $languageDataProvider;
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
if ($this->id_country = Country::getByIso('PL', true)) {
|
||||
$this->id_zone = Country::getIdZone($this->id_country);
|
||||
}
|
||||
|
||||
foreach (TaxRulesGroup::getAssociatedTaxRatesByIdCountry($this->id_country) as $id_tax_rule_group => $rate) {
|
||||
if ((float) $rate === 23.) {
|
||||
$this->id_tax_rule_group = $id_tax_rule_group;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Group::getGroups(Context::getContext()->language->id) as $group) {
|
||||
$this->groups[] = $group['id_group'];
|
||||
}
|
||||
}
|
||||
|
||||
public function update(
|
||||
Carrier $carrier,
|
||||
$service,
|
||||
$cashOnDelivery,
|
||||
$weekendDelivery = false,
|
||||
$updateSettings = true
|
||||
) {
|
||||
$this->resetErrors();
|
||||
|
||||
if (Validate::isLoadedObject($carrier)) {
|
||||
$this->carrier = $carrier->duplicateObject();
|
||||
$this->carrier->copyCarrierData($carrier->id);
|
||||
} else {
|
||||
$this->carrier = $carrier;
|
||||
}
|
||||
|
||||
$weekendDelivery = $weekendDelivery && $service === Service::INPOST_LOCKER_STANDARD;
|
||||
|
||||
$this->service = $service;
|
||||
$this->updateSettings = $updateSettings;
|
||||
|
||||
$this->setCarrierFields($weekendDelivery);
|
||||
|
||||
try {
|
||||
$this->carrier->save();
|
||||
$this->carrier->id_reference = $this->carrier->id_reference ?: $this->carrier->id;
|
||||
|
||||
if ($this->updateSettings) {
|
||||
$this->carrier->setGroups($this->groups);
|
||||
if ($this->id_tax_rule_group) {
|
||||
$this->carrier->setTaxRulesGroup($this->id_tax_rule_group);
|
||||
}
|
||||
|
||||
$this->addRange()
|
||||
->addZone();
|
||||
|
||||
if ($cashOnDelivery) {
|
||||
$this->limitPaymentModules();
|
||||
}
|
||||
}
|
||||
|
||||
$this->copyImage($weekendDelivery);
|
||||
|
||||
if ($carrier->id !== $this->carrier->id) {
|
||||
$carrier->deleted = true;
|
||||
$carrier->update();
|
||||
}
|
||||
|
||||
return $this->carrier;
|
||||
} catch (Exception $exception) {
|
||||
$this->addError($exception->getMessage());
|
||||
$this->carrier->delete();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setCarrierFields($weekendDelivery)
|
||||
{
|
||||
$this->carrier->is_module = true;
|
||||
$this->carrier->external_module_name = $this->module->name;
|
||||
$this->carrier->url = self::TRACKING_URL;
|
||||
$this->carrier->shipping_external = $weekendDelivery;
|
||||
$this->carrier->need_range = true;
|
||||
|
||||
if ($this->updateSettings) {
|
||||
$this->carrier->active = true;
|
||||
$this->carrier->is_free = false;
|
||||
$this->carrier->shipping_handling = true;
|
||||
$this->carrier->shipping_method = Carrier::SHIPPING_METHOD_WEIGHT;
|
||||
$this->carrier->range_behavior = true;
|
||||
|
||||
$this->setDelay()
|
||||
// ->setMaxDimensions()
|
||||
->setMaxWeight();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function setDelay()
|
||||
{
|
||||
foreach ($this->languageDataProvider->getLanguages() as $id_lang => $language) {
|
||||
$this->carrier->delay[$id_lang] = $this->module->l('48 - 72h', self::TRANSLATION_SOURCE, $language['locale']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function setMaxDimensions()
|
||||
{
|
||||
switch ($this->service) {
|
||||
case Service::INPOST_LOCKER_STANDARD:
|
||||
$this->carrier->max_height = 41;
|
||||
$this->carrier->max_width = 38;
|
||||
$this->carrier->max_depth = 64;
|
||||
break;
|
||||
case Service::INPOST_COURIER_C2C:
|
||||
$this->carrier->max_height = 50;
|
||||
$this->carrier->max_width = 50;
|
||||
$this->carrier->max_depth = 80;
|
||||
break;
|
||||
case Service::INPOST_COURIER_PALETTE:
|
||||
$this->carrier->max_height = 120;
|
||||
$this->carrier->max_width = 80;
|
||||
$this->carrier->max_depth = 180;
|
||||
break;
|
||||
default:
|
||||
$this->carrier->max_height = 350;
|
||||
$this->carrier->max_width = 240;
|
||||
$this->carrier->max_depth = 240;
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function setMaxWeight()
|
||||
{
|
||||
switch ($this->service) {
|
||||
case Service::INPOST_LOCKER_STANDARD:
|
||||
case Service::INPOST_COURIER_C2C:
|
||||
$this->carrier->max_weight = 25;
|
||||
break;
|
||||
case Service::INPOST_COURIER_STANDARD:
|
||||
case Service::INPOST_COURIER_EXPRESS_1700:
|
||||
$this->carrier->max_weight = 50;
|
||||
break;
|
||||
case Service::INPOST_COURIER_PALETTE:
|
||||
$this->carrier->max_weight = 800;
|
||||
break;
|
||||
default:
|
||||
$this->carrier->max_weight = 30;
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function addZone()
|
||||
{
|
||||
foreach ($this->carrier->getZones() as $zone) {
|
||||
$this->carrier->deleteZone($zone['id_zone']);
|
||||
}
|
||||
|
||||
$this->carrier->addZone($this->id_zone);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function addRange()
|
||||
{
|
||||
$ranges = (new PrestaShopCollection(RangeWeight::class))
|
||||
->where('id_carrier', '=', $this->carrier->id);
|
||||
|
||||
/** @var RangeWeight $range */
|
||||
foreach ($ranges as $range) {
|
||||
$range->delete();
|
||||
}
|
||||
|
||||
$range = new RangeWeight();
|
||||
$range->id_carrier = $this->carrier->id;
|
||||
$range->delimiter1 = $this->service === Service::INPOST_COURIER_PALETTE ? 50 : 0;
|
||||
$range->delimiter2 = $this->carrier->max_weight;
|
||||
$range->add();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function limitPaymentModules()
|
||||
{
|
||||
if (($module = Module::getInstanceByName('ps_cashondelivery')) ||
|
||||
($module = Module::getInstanceByName('cashondelivery'))
|
||||
) {
|
||||
$paymentModules = [
|
||||
[
|
||||
'id_reference' => (int) $this->carrier->id_reference,
|
||||
'id_module' => (int) $module->id,
|
||||
],
|
||||
];
|
||||
|
||||
$db = Db::getInstance();
|
||||
|
||||
$db->delete('module_carrier', 'id_reference = ' . (int) $this->carrier->id_reference);
|
||||
$db->insert('module_carrier', $paymentModules);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function copyImage($weekendDelivery)
|
||||
{
|
||||
switch ($this->service) {
|
||||
case Service::INPOST_LOCKER_STANDARD:
|
||||
$logo = $weekendDelivery
|
||||
? 'logo_weekend.png'
|
||||
: 'logo_locker.png';
|
||||
break;
|
||||
default:
|
||||
$logo = 'logo.png';
|
||||
break;
|
||||
}
|
||||
|
||||
copy(
|
||||
$this->module->getLocalPath() . 'views/img/' . $logo,
|
||||
_PS_SHIP_IMG_DIR_ . '/' . $this->carrier->id . '.jpg'
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
130
modules/inpostshipping/src/CartChoiceUpdater.php
Normal file
130
modules/inpostshipping/src/CartChoiceUpdater.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?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;
|
||||
|
||||
use InPost\Shipping\DataProvider\PointDataProvider;
|
||||
use InPost\Shipping\Traits\ErrorsTrait;
|
||||
use InPostCartChoiceModel;
|
||||
use InPostShipping;
|
||||
use Validate;
|
||||
|
||||
class CartChoiceUpdater
|
||||
{
|
||||
use ErrorsTrait;
|
||||
|
||||
const TRANSLATION_SOURCE = 'CartChoiceUpdater';
|
||||
|
||||
protected $module;
|
||||
protected $pointDataProvider;
|
||||
|
||||
protected $weekendDelivery = false;
|
||||
protected $cashOnDelivery = false;
|
||||
protected $service;
|
||||
|
||||
/** @var InPostCartChoiceModel */
|
||||
protected $cartChoice;
|
||||
|
||||
public function __construct(
|
||||
InPostShipping $module,
|
||||
PointDataProvider $pointDataProvider
|
||||
) {
|
||||
$this->module = $module;
|
||||
$this->pointDataProvider = $pointDataProvider;
|
||||
}
|
||||
|
||||
public function getCartChoice()
|
||||
{
|
||||
return $this->cartChoice;
|
||||
}
|
||||
|
||||
public function setCartChoice(InPostCartChoiceModel $cartChoice)
|
||||
{
|
||||
$this->cartChoice = $cartChoice;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCarrierData(array $carrierData)
|
||||
{
|
||||
$this->weekendDelivery = $carrierData['weekendDelivery'];
|
||||
$this->cashOnDelivery = $carrierData['cashOnDelivery'];
|
||||
$this->service = $carrierData['service'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTargetPoint($pointId)
|
||||
{
|
||||
if ($pointId && $point = $this->pointDataProvider->getPointData($pointId)) {
|
||||
if ((!$this->weekendDelivery || $point->location_247) &&
|
||||
(!$this->cashOnDelivery || $point->payment_available)
|
||||
) {
|
||||
$this->cartChoice->point = $point->getId();
|
||||
} else {
|
||||
$this->errors['locker'] = $this->module->l('Selected locker is not available for the selected delivery option.', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
} else {
|
||||
$this->errors['locker'] = $this->module->l('Please select a locker.', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEmail($email)
|
||||
{
|
||||
if (!Validate::isEmail($email)) {
|
||||
$this->errors['email'] = $this->module->l('Provided email is invalid.', self::TRANSLATION_SOURCE);
|
||||
} else {
|
||||
$this->cartChoice->email = $email;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPhone($phone)
|
||||
{
|
||||
if (preg_match('/^[0-9]{9}$/', $phone = InPostCartChoiceModel::formatPhone($phone))) {
|
||||
$this->cartChoice->phone = $phone;
|
||||
} else {
|
||||
$this->errors['phone'] = $this->module->l('Provided phone number is invalid - should look like XXXXXXXXX (e.g. 123456789).', self::TRANSLATION_SOURCE);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function saveChoice($id_cart)
|
||||
{
|
||||
$this->cartChoice->service = $this->service;
|
||||
|
||||
if (!Validate::isLoadedObject($this->cartChoice)) {
|
||||
$this->cartChoice->id = $id_cart;
|
||||
$this->cartChoice->add();
|
||||
} else {
|
||||
$this->cartChoice->update();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use Carrier;
|
||||
use Context;
|
||||
|
||||
class CarrierChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
protected $context;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->context = Context::getContext();
|
||||
}
|
||||
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach (Carrier::getCarriers($this->context->language->id) as $carrier) {
|
||||
$choices[$carrier['id_reference']] = [
|
||||
'value' => $carrier['id_reference'],
|
||||
'text' => $carrier['name'],
|
||||
];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
interface ChoiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getChoices();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
|
||||
use InPost\Shipping\Translations\DimensionTemplateTranslator;
|
||||
|
||||
class DimensionTemplateChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
protected $translator;
|
||||
|
||||
public function __construct(DimensionTemplateTranslator $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach ($this->getAvailableTemplates() as $template) {
|
||||
$choices[] = [
|
||||
'value' => $template,
|
||||
'text' => $this->translator->translate($template),
|
||||
];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
protected function getAvailableTemplates()
|
||||
{
|
||||
return Shipment::DIMENSION_TEMPLATES;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use InPost\Shipping\Presenter\DispatchPointPresenter;
|
||||
use InPostDispatchPointModel;
|
||||
use PrestaShopCollection;
|
||||
|
||||
class DispatchPointChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
protected $presenter;
|
||||
|
||||
protected $dispatchPoints;
|
||||
|
||||
public function __construct(DispatchPointPresenter $dispatchPointPresenter)
|
||||
{
|
||||
$this->presenter = $dispatchPointPresenter;
|
||||
}
|
||||
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
$this->initCollection();
|
||||
|
||||
/** @var InPostDispatchPointModel $dispatchPoint */
|
||||
foreach ($this->dispatchPoints as $dispatchPoint) {
|
||||
$choices[] = [
|
||||
'value' => (int) $dispatchPoint->id,
|
||||
'text' => $this->presenter->present($dispatchPoint),
|
||||
];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
protected function initCollection()
|
||||
{
|
||||
if (!isset($this->dispatchPoints)) {
|
||||
$this->dispatchPoints = (new PrestaShopCollection(InPostDispatchPointModel::class))
|
||||
->where('deleted', '=', 0);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -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\ChoiceProvider;
|
||||
|
||||
use CarrierModule;
|
||||
use Module;
|
||||
use PaymentModule;
|
||||
use StockManagerModule;
|
||||
use TaxManagerModule;
|
||||
|
||||
class ModuleChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach (Module::getModulesInstalled() as $module) {
|
||||
if (($module = Module::getInstanceByName($module['name'])) &&
|
||||
!$this->shouldSkipModule($module)
|
||||
) {
|
||||
$choices[] = [
|
||||
'value' => $module->name,
|
||||
'label' => $module->displayName,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
protected function shouldSkipModule(Module $module)
|
||||
{
|
||||
return $module instanceof CarrierModule
|
||||
|| $module instanceof PaymentModule
|
||||
|| $module instanceof TaxManagerModule
|
||||
|| $module instanceof StockManagerModule;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use Meta;
|
||||
|
||||
class ModulePageChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach (Meta::getPages() as $page) {
|
||||
if ($this->isModulePage($page)) {
|
||||
list(, $moduleName, $controller) = explode('-', $page);
|
||||
|
||||
$choices[$moduleName][] = [
|
||||
'value' => $controller,
|
||||
'label' => $controller,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
protected function isModulePage($page)
|
||||
{
|
||||
return 0 === strncmp($page, 'module-', 7);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use Context;
|
||||
use OrderState;
|
||||
|
||||
class OrderStateChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
protected $context;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->context = Context::getContext();
|
||||
}
|
||||
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach (OrderState::getOrderStates($this->context->language->id) as $orderState) {
|
||||
$choices[] = [
|
||||
'value' => $orderState['id_order_state'],
|
||||
'text' => $orderState['name'],
|
||||
];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
use InPost\Shipping\Translations\DimensionTemplateTranslator;
|
||||
|
||||
class ProductTemplateChoiceProvider extends DimensionTemplateChoiceProvider
|
||||
{
|
||||
protected $serviceChoiceProvider;
|
||||
|
||||
public function __construct(
|
||||
DimensionTemplateTranslator $translator,
|
||||
ShippingServiceChoiceProvider $serviceChoiceProvider
|
||||
) {
|
||||
parent::__construct($translator);
|
||||
|
||||
$this->serviceChoiceProvider = $serviceChoiceProvider;
|
||||
}
|
||||
|
||||
protected function getAvailableTemplates()
|
||||
{
|
||||
return $this->serviceChoiceProvider->getAvailableTemplates(Service::INPOST_LOCKER_STANDARD);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
namespace InPost\Shipping\ChoiceProvider;
|
||||
|
||||
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
|
||||
use InPost\Shipping\ShipX\Resource\SendingMethod;
|
||||
use InPost\Shipping\Translations\SendingMethodTranslator;
|
||||
|
||||
class SendingMethodChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
protected $translator;
|
||||
|
||||
public function __construct(SendingMethodTranslator $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach (SendingMethod::SENDING_METHODS as $method) {
|
||||
$choices[] = [
|
||||
'value' => $method,
|
||||
'text' => $this->translator->translate($method),
|
||||
'unavailableTemplates' => $this->getUnavailableTemplates($method),
|
||||
];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
protected function getUnavailableTemplates($method)
|
||||
{
|
||||
if ($method === SendingMethod::PARCEL_LOCKER) {
|
||||
return [Shipment::TEMPLATE_EXTRA_LARGE];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
|
||||
use Tools;
|
||||
|
||||
class ShipmentLabelFormatChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach (Shipment::LABEL_FORMATS as $format) {
|
||||
$choices[] = [
|
||||
'value' => $format,
|
||||
'text' => Tools::strtoupper($format),
|
||||
];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
|
||||
|
||||
class ShipmentLabelTypeChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
public function getChoices()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => Shipment::TYPE_A6,
|
||||
'text' => 'A6',
|
||||
],
|
||||
[
|
||||
'value' => Shipment::TYPE_NORMAL,
|
||||
'text' => 'A4',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use InPost\Shipping\Translations\FieldTranslator;
|
||||
|
||||
class ShipmentReferenceFieldChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
const TRANSLATION_SOURCE = 'ShipmentReferenceFieldChoiceProvider';
|
||||
|
||||
const ORDER_REFERENCE = 'reference';
|
||||
const ORDER_ID = 'id_order';
|
||||
|
||||
const FIELDS = [
|
||||
self::ORDER_REFERENCE,
|
||||
self::ORDER_ID,
|
||||
];
|
||||
|
||||
protected $translator;
|
||||
|
||||
public function __construct(FieldTranslator $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach (self::FIELDS as $field) {
|
||||
$choices[] = [
|
||||
'value' => $field,
|
||||
'text' => $this->translator->translate($field),
|
||||
];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use InPost\Shipping\DataProvider\OrganizationDataProvider;
|
||||
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
|
||||
use InPost\Shipping\ShipX\Resource\SendingMethod;
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
use InPost\Shipping\Translations\ShippingServiceTranslator;
|
||||
|
||||
class ShippingServiceChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
protected $organizationDataProvider;
|
||||
protected $translator;
|
||||
|
||||
protected $availableServices;
|
||||
|
||||
public function __construct(
|
||||
OrganizationDataProvider $organizationDataProvider,
|
||||
ShippingServiceTranslator $translator
|
||||
) {
|
||||
$this->organizationDataProvider = $organizationDataProvider;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach (Service::SERVICES as $service) {
|
||||
$choices[$service] = [
|
||||
'value' => $service,
|
||||
'text' => $this->translator->translate($service),
|
||||
'disabled' => !$this->isAvailable($service),
|
||||
'availableTemplates' => $this->getAvailableTemplates($service),
|
||||
'availableSendingMethods' => $this->getAvailableSendingMethods($service),
|
||||
];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
protected function isAvailable($service)
|
||||
{
|
||||
if (!isset($this->availableServices)) {
|
||||
if ($organization = $this->organizationDataProvider->getOrganizationData()) {
|
||||
$this->availableServices = array_flip($organization['services']);
|
||||
} else {
|
||||
$this->availableServices = [];
|
||||
}
|
||||
}
|
||||
|
||||
return isset($this->availableServices[$service]);
|
||||
}
|
||||
|
||||
public function getAvailableTemplates($service)
|
||||
{
|
||||
switch ($service) {
|
||||
case Service::INPOST_LOCKER_STANDARD:
|
||||
return [
|
||||
Shipment::TEMPLATE_SMALL,
|
||||
Shipment::TEMPLATE_MEDIUM,
|
||||
Shipment::TEMPLATE_LARGE,
|
||||
];
|
||||
case Service::INPOST_COURIER_C2C:
|
||||
return [
|
||||
Shipment::TEMPLATE_SMALL,
|
||||
Shipment::TEMPLATE_MEDIUM,
|
||||
Shipment::TEMPLATE_LARGE,
|
||||
Shipment::TEMPLATE_EXTRA_LARGE,
|
||||
];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvailableSendingMethods($service)
|
||||
{
|
||||
switch ($service) {
|
||||
case Service::INPOST_LOCKER_STANDARD:
|
||||
case Service::INPOST_COURIER_C2C:
|
||||
return SendingMethod::SENDING_METHODS;
|
||||
case Service::INPOST_COURIER_LOCAL_STANDARD:
|
||||
case Service::INPOST_COURIER_LOCAL_EXPRESS:
|
||||
case Service::INPOST_COURIER_LOCAL_SUPER_EXPRESS:
|
||||
return [SendingMethod::DISPATCH_ORDER];
|
||||
default:
|
||||
return [
|
||||
SendingMethod::DISPATCH_ORDER,
|
||||
SendingMethod::POP,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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\ChoiceProvider;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use InPost\Shipping\Translations\WeekdayTranslator;
|
||||
|
||||
class WeekdayChoiceProvider implements ChoiceProviderInterface
|
||||
{
|
||||
protected $translator;
|
||||
|
||||
const WEEKDAYS = [
|
||||
Carbon::MONDAY,
|
||||
Carbon::TUESDAY,
|
||||
Carbon::WEDNESDAY,
|
||||
Carbon::THURSDAY,
|
||||
Carbon::FRIDAY,
|
||||
Carbon::SATURDAY,
|
||||
Carbon::SUNDAY,
|
||||
];
|
||||
|
||||
public function __construct(WeekdayTranslator $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach (self::WEEKDAYS as $weekday) {
|
||||
$choices[] = [
|
||||
'value' => $weekday,
|
||||
'text' => $this->translator->translate($weekday),
|
||||
];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/src/ChoiceProvider/index.php
Normal file
32
modules/inpostshipping/src/ChoiceProvider/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;
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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\Configuration;
|
||||
|
||||
use Configuration;
|
||||
use ReflectionClass;
|
||||
|
||||
abstract class AbstractConfiguration
|
||||
{
|
||||
protected function set($key, $value)
|
||||
{
|
||||
return Configuration::updateValue($key, $value);
|
||||
}
|
||||
|
||||
protected function get($key)
|
||||
{
|
||||
return Configuration::get($key);
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$result = true;
|
||||
|
||||
$reflection = new ReflectionClass($this);
|
||||
foreach ($reflection->getConstants() as $key) {
|
||||
$result &= Configuration::deleteByName($key);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setDefaults()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<?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\Configuration;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class CarriersConfiguration extends AbstractConfiguration
|
||||
{
|
||||
const WEEKEND_DELIVERY_START_DAY = 'INPOST_SHIPPING_WEEKEND_DELIVERY_START_DAY';
|
||||
const WEEKEND_DELIVERY_START_HOUR = 'INPOST_SHIPPING_WEEKEND_DELIVERY_START_HOUR';
|
||||
const WEEKEND_DELIVERY_END_DAY = 'INPOST_SHIPPING_WEEKEND_DELIVERY_END_DAY';
|
||||
const WEEKEND_DELIVERY_END_HOUR = 'INPOST_SHIPPING_WEEKEND_DELIVERY_END_HOUR';
|
||||
const SERVICE_DEFAULT_SHIPMENT_DIMENSIONS = 'INPOST_SHIPPING_SERVICE_DEFAULT_SHIPMENT_DIMENSIONS';
|
||||
const SERVICE_DEFAULT_DIMENSION_TEMPLATES = 'INPOST_SHIPPING_SERVICE_DEFAULT_DIMENSION_TEMPLATES';
|
||||
const SERVICE_DEFAULT_SENDING_METHODS = 'INPOST_SHIPPING_SERVICE_DEFAULT_SENDING_METHODS';
|
||||
|
||||
protected $defaultDimensions;
|
||||
protected $defaultTemplates;
|
||||
protected $defaultSendingMethods;
|
||||
|
||||
public function getWeekendDeliveryStartDay()
|
||||
{
|
||||
return (int) $this->get(self::WEEKEND_DELIVERY_START_DAY);
|
||||
}
|
||||
|
||||
public function setWeekendDeliveryStartDay($day)
|
||||
{
|
||||
return $this->set(self::WEEKEND_DELIVERY_START_DAY, (int) $day);
|
||||
}
|
||||
|
||||
public function getWeekendDeliveryStartHour()
|
||||
{
|
||||
return (string) $this->get(self::WEEKEND_DELIVERY_START_HOUR);
|
||||
}
|
||||
|
||||
public function setWeekendDeliveryStartHour($hour)
|
||||
{
|
||||
return $this->set(self::WEEKEND_DELIVERY_START_HOUR, $hour);
|
||||
}
|
||||
|
||||
public function getWeekendDeliveryEndDay()
|
||||
{
|
||||
return (int) $this->get(self::WEEKEND_DELIVERY_END_DAY);
|
||||
}
|
||||
|
||||
public function setWeekendDeliveryEndDay($day)
|
||||
{
|
||||
return $this->set(self::WEEKEND_DELIVERY_END_DAY, (int) $day);
|
||||
}
|
||||
|
||||
public function getWeekendDeliveryEndHour()
|
||||
{
|
||||
return (string) $this->get(self::WEEKEND_DELIVERY_END_HOUR);
|
||||
}
|
||||
|
||||
public function setWeekendDeliveryEndHour($hour)
|
||||
{
|
||||
return $this->set(self::WEEKEND_DELIVERY_END_HOUR, $hour);
|
||||
}
|
||||
|
||||
public function getDefaultShipmentDimensions($service = null)
|
||||
{
|
||||
if (!isset($this->defaultDimensions)) {
|
||||
$this->defaultDimensions = json_decode($this->get(self::SERVICE_DEFAULT_SHIPMENT_DIMENSIONS), true) ?: [];
|
||||
}
|
||||
|
||||
return $service
|
||||
? (isset($this->defaultDimensions[$service]) ? $this->defaultDimensions[$service] : null)
|
||||
: $this->defaultDimensions;
|
||||
}
|
||||
|
||||
public function setDefaultShipmentDimensions($service, array $dimensions)
|
||||
{
|
||||
$this->defaultDimensions = $this->updateServiceDefaults(
|
||||
$this->getDefaultShipmentDimensions(),
|
||||
$service,
|
||||
$dimensions
|
||||
);
|
||||
|
||||
return $this->set(self::SERVICE_DEFAULT_SHIPMENT_DIMENSIONS, json_encode($this->defaultDimensions));
|
||||
}
|
||||
|
||||
public function getDefaultDimensionTemplates($service = null)
|
||||
{
|
||||
if (!isset($this->defaultTemplates)) {
|
||||
$this->defaultTemplates = json_decode($this->get(self::SERVICE_DEFAULT_DIMENSION_TEMPLATES), true) ?: [];
|
||||
}
|
||||
|
||||
return $service
|
||||
? (isset($this->defaultTemplates[$service]) ? $this->defaultTemplates[$service] : null)
|
||||
: $this->defaultTemplates;
|
||||
}
|
||||
|
||||
public function setDefaultDimensionTemplate($service, $template)
|
||||
{
|
||||
$this->defaultTemplates = $this->updateServiceDefaults(
|
||||
$this->getDefaultDimensionTemplates(),
|
||||
$service,
|
||||
$template
|
||||
);
|
||||
|
||||
return $this->set(self::SERVICE_DEFAULT_DIMENSION_TEMPLATES, json_encode($this->defaultTemplates));
|
||||
}
|
||||
|
||||
public function getDefaultSendingMethods($service = null)
|
||||
{
|
||||
if (!isset($this->defaultSendingMethods)) {
|
||||
$this->defaultSendingMethods = json_decode($this->get(self::SERVICE_DEFAULT_SENDING_METHODS), true) ?: [];
|
||||
}
|
||||
|
||||
return $service
|
||||
? (isset($this->defaultSendingMethods[$service]) ? $this->defaultSendingMethods[$service] : null)
|
||||
: $this->defaultSendingMethods;
|
||||
}
|
||||
|
||||
public function setDefaultSendingMethod($service, $sendingMethod)
|
||||
{
|
||||
$this->defaultSendingMethods = $this->updateServiceDefaults(
|
||||
$this->getDefaultSendingMethods(),
|
||||
$service,
|
||||
$sendingMethod
|
||||
);
|
||||
|
||||
return $this->set(self::SERVICE_DEFAULT_SENDING_METHODS, json_encode($this->defaultSendingMethods));
|
||||
}
|
||||
|
||||
public function setDefaults()
|
||||
{
|
||||
return $this->setWeekendDeliveryStartDay(Carbon::THURSDAY)
|
||||
&& $this->setWeekendDeliveryStartHour('16:00:00')
|
||||
&& $this->setWeekendDeliveryEndDay(Carbon::SATURDAY)
|
||||
&& $this->setWeekendDeliveryEndHour('10:00:00');
|
||||
}
|
||||
|
||||
private function updateServiceDefaults(array $defaults, $service, $newValue)
|
||||
{
|
||||
if (!empty($newValue)) {
|
||||
$defaults[$service] = $newValue;
|
||||
} else {
|
||||
unset($defaults[$service]);
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
namespace InPost\Shipping\Configuration;
|
||||
|
||||
class CheckoutConfiguration extends AbstractConfiguration
|
||||
{
|
||||
const USING_CUSTOM_CHECKOUT_MODULE = 'INPOST_SHIPPING_USING_CUSTOM_CHECKOUT_MODULE';
|
||||
const CUSTOM_CHECKOUT_CONTROLLERS = 'INPOST_SHIPPING_CUSTOM_CHECKOUT_CONTROLLERS';
|
||||
|
||||
protected $customCheckoutControllers;
|
||||
|
||||
public function isUsingCustomCheckoutModule()
|
||||
{
|
||||
return (bool) $this->get(self::USING_CUSTOM_CHECKOUT_MODULE);
|
||||
}
|
||||
|
||||
public function setUsingCustomCheckoutModule($usingCustomCheckout)
|
||||
{
|
||||
return $this->set(self::USING_CUSTOM_CHECKOUT_MODULE, (bool) $usingCustomCheckout);
|
||||
}
|
||||
|
||||
public function getCustomCheckoutControllers()
|
||||
{
|
||||
if (!isset($this->customCheckoutControllers)) {
|
||||
$this->customCheckoutControllers = json_decode($this->get(self::CUSTOM_CHECKOUT_CONTROLLERS), true) ?: [];
|
||||
}
|
||||
|
||||
return $this->customCheckoutControllers;
|
||||
}
|
||||
|
||||
public function setCustomCheckoutControllers(array $controllers)
|
||||
{
|
||||
if ($this->set(self::CUSTOM_CHECKOUT_CONTROLLERS, json_encode($controllers))) {
|
||||
$this->customCheckoutControllers = $controllers;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?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\Configuration;
|
||||
|
||||
class OrdersConfiguration extends AbstractConfiguration
|
||||
{
|
||||
const ORDER_CONF_DISPLAY_LOCKER = 'INPOST_SHIPPING_ORDER_CONF_DISPLAY_LOCKER';
|
||||
const CHANGE_OS_SHIPMENT_LABEL_PRINTED = 'INPOST_SHIPPING_CHANGE_OS_SHIPMENT_LABEL_PRINTED';
|
||||
const SHIPMENT_LABEL_PRINTED_OS_ID = 'INPOST_SHIPPING_SHIPMENT_LABEL_PRINTED_OS_ID';
|
||||
const CHANGE_OS_SHIPMENT_DELIVERED = 'INPOST_SHIPPING_CHANGE_OS_SHIPMENT_DELIVERED';
|
||||
const SHIPMENT_DELIVERED_OS_ID = 'INPOST_SHIPPING_SHIPMENT_DELIVERED_OS_ID';
|
||||
|
||||
public function shouldDisplayOrderConfirmationLocker()
|
||||
{
|
||||
return (bool) $this->get(self::ORDER_CONF_DISPLAY_LOCKER);
|
||||
}
|
||||
|
||||
public function setDisplayOrderConfirmationLocker($display)
|
||||
{
|
||||
return $this->set(self::ORDER_CONF_DISPLAY_LOCKER, (bool) $display);
|
||||
}
|
||||
|
||||
public function shouldChangeOrderStateOnShipmentLabelPrinted()
|
||||
{
|
||||
return (bool) $this->get(self::CHANGE_OS_SHIPMENT_LABEL_PRINTED);
|
||||
}
|
||||
|
||||
public function setChangeOrderStateOnShipmentLabelPrinted($change)
|
||||
{
|
||||
return $this->set(self::CHANGE_OS_SHIPMENT_LABEL_PRINTED, (bool) $change);
|
||||
}
|
||||
|
||||
public function getShipmentLabelPrintedOrderStateId()
|
||||
{
|
||||
return (int) $this->get(self::SHIPMENT_LABEL_PRINTED_OS_ID);
|
||||
}
|
||||
|
||||
public function setShipmentLabelPrintedOrderStateId($orderStateId)
|
||||
{
|
||||
return $this->set(self::SHIPMENT_LABEL_PRINTED_OS_ID, (int) $orderStateId);
|
||||
}
|
||||
|
||||
public function shouldChangeOrderStateOnShipmentDelivered()
|
||||
{
|
||||
return (bool) $this->get(self::CHANGE_OS_SHIPMENT_DELIVERED);
|
||||
}
|
||||
|
||||
public function setChangeOrderStateOnShipmentDelivered($change)
|
||||
{
|
||||
return $this->set(self::CHANGE_OS_SHIPMENT_DELIVERED, (bool) $change);
|
||||
}
|
||||
|
||||
public function getShipmentDeliveredOrderStateId()
|
||||
{
|
||||
return (int) $this->get(self::SHIPMENT_DELIVERED_OS_ID);
|
||||
}
|
||||
|
||||
public function setShipmentDeliveredOrderStateId($orderStateId)
|
||||
{
|
||||
return $this->set(self::SHIPMENT_DELIVERED_OS_ID, (int) $orderStateId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?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\Configuration;
|
||||
|
||||
use InPost\Shipping\ChoiceProvider\ShipmentReferenceFieldChoiceProvider;
|
||||
|
||||
class SendingConfiguration extends AbstractConfiguration
|
||||
{
|
||||
const SENDER_DETAILS = 'INPOST_SHIPPING_SENDER_DETAILS';
|
||||
const DEFAULT_SENDING_METHOD = 'INPOST_SHIPPING_DEFAULT_SENDING_METHOD';
|
||||
const DEFAULT_LOCKER = 'INPOST_SHIPPING_DEFAULT_LOCKER';
|
||||
const DEFAULT_POP = 'INPOST_SHIPPING_DEFAULT_POP';
|
||||
const DEFAULT_DISPATCH_POINT_ID = 'INPOST_SHIPPING_DEFAULT_DISPATCH_POINT';
|
||||
const DEFAULT_SHIPMENT_REFERENCE_FIELD = 'INPOST_SHIPPING_DEFAULT_SHIPMENT_REFERENCE_FIELD';
|
||||
|
||||
public function getSenderDetails()
|
||||
{
|
||||
return json_decode($this->get(self::SENDER_DETAILS), true);
|
||||
}
|
||||
|
||||
public function setSenderDetails(array $senderDetails)
|
||||
{
|
||||
$senderDetails = $senderDetails ? json_encode($senderDetails) : false;
|
||||
|
||||
return $this->set(self::SENDER_DETAILS, $senderDetails);
|
||||
}
|
||||
|
||||
public function getDefaultSendingMethod()
|
||||
{
|
||||
return (string) $this->get(self::DEFAULT_SENDING_METHOD);
|
||||
}
|
||||
|
||||
public function setDefaultSendingMethod($sendingMethod)
|
||||
{
|
||||
return $this->set(self::DEFAULT_SENDING_METHOD, $sendingMethod);
|
||||
}
|
||||
|
||||
public function getDefaultLocker()
|
||||
{
|
||||
return json_decode($this->get(self::DEFAULT_LOCKER), true);
|
||||
}
|
||||
|
||||
public function setDefaultLocker($locker)
|
||||
{
|
||||
$locker = $locker ? json_encode($locker) : false;
|
||||
|
||||
return $this->set(self::DEFAULT_LOCKER, $locker);
|
||||
}
|
||||
|
||||
public function getDefaultPOP()
|
||||
{
|
||||
return json_decode($this->get(self::DEFAULT_POP), true);
|
||||
}
|
||||
|
||||
public function setDefaultPOP($pop)
|
||||
{
|
||||
$pop = $pop ? json_encode($pop) : false;
|
||||
|
||||
return $this->set(self::DEFAULT_POP, $pop);
|
||||
}
|
||||
|
||||
public function getDefaultDispatchPointId()
|
||||
{
|
||||
return (int) $this->get(self::DEFAULT_DISPATCH_POINT_ID);
|
||||
}
|
||||
|
||||
public function setDefaultDispatchPointId($dispatchPointId)
|
||||
{
|
||||
return $this->set(self::DEFAULT_DISPATCH_POINT_ID, (int) $dispatchPointId);
|
||||
}
|
||||
|
||||
public function getDefaultShipmentReferenceField()
|
||||
{
|
||||
return (string) $this->get(self::DEFAULT_SHIPMENT_REFERENCE_FIELD);
|
||||
}
|
||||
|
||||
public function setDefaultShipmentReferenceField($field)
|
||||
{
|
||||
return $this->set(self::DEFAULT_SHIPMENT_REFERENCE_FIELD, $field);
|
||||
}
|
||||
|
||||
public function setDefaults()
|
||||
{
|
||||
return $this->setDefaultShipmentReferenceField(ShipmentReferenceFieldChoiceProvider::ORDER_REFERENCE);
|
||||
}
|
||||
}
|
||||
143
modules/inpostshipping/src/Configuration/ShipXConfiguration.php
Normal file
143
modules/inpostshipping/src/Configuration/ShipXConfiguration.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?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\Configuration;
|
||||
|
||||
class ShipXConfiguration extends AbstractConfiguration
|
||||
{
|
||||
const API_TOKEN = 'INPOST_SHIPPING_API_TOKEN';
|
||||
const ORGANIZATION_ID = 'INPOST_SHIPPING_ORGANIZATION_ID';
|
||||
const SANDBOX_MODE_ENABLED = 'INPOST_SHIPPING_SANDBOX_MODE_ENABLED';
|
||||
const SANDBOX_API_TOKEN = 'INPOST_SHIPPING_SANDBOX_API_TOKEN';
|
||||
const SANDBOX_ORGANIZATION_ID = 'INPOST_SHIPPING_SANDBOX_ORGANIZATION_ID';
|
||||
|
||||
protected $useSandbox;
|
||||
protected $apiToken;
|
||||
protected $organizationId;
|
||||
|
||||
public function getProductionApiToken()
|
||||
{
|
||||
return (string) $this->get(self::API_TOKEN);
|
||||
}
|
||||
|
||||
public function setProductionApiToken($token)
|
||||
{
|
||||
return $this->set(self::API_TOKEN, $token);
|
||||
}
|
||||
|
||||
public function getProductionOrganizationId()
|
||||
{
|
||||
return (int) $this->get(self::ORGANIZATION_ID);
|
||||
}
|
||||
|
||||
public function setProductionOrganizationId($organizationId)
|
||||
{
|
||||
return $this->set(self::ORGANIZATION_ID, (int) $organizationId);
|
||||
}
|
||||
|
||||
public function isSandboxModeEnabled()
|
||||
{
|
||||
return (bool) $this->get(self::SANDBOX_MODE_ENABLED);
|
||||
}
|
||||
|
||||
public function setSandboxModeEnabled($enabled)
|
||||
{
|
||||
return $this->set(self::SANDBOX_MODE_ENABLED, (bool) $enabled);
|
||||
}
|
||||
|
||||
public function getSandboxApiToken()
|
||||
{
|
||||
return (string) $this->get(self::SANDBOX_API_TOKEN);
|
||||
}
|
||||
|
||||
public function setSandboxApiToken($token)
|
||||
{
|
||||
return $this->set(self::SANDBOX_API_TOKEN, $token);
|
||||
}
|
||||
|
||||
public function getSandboxOrganizationId()
|
||||
{
|
||||
return (int) $this->get(self::SANDBOX_ORGANIZATION_ID);
|
||||
}
|
||||
|
||||
public function setSandboxOrganizationId($organizationId)
|
||||
{
|
||||
return $this->set(self::SANDBOX_ORGANIZATION_ID, (int) $organizationId);
|
||||
}
|
||||
|
||||
public function useSandboxMode()
|
||||
{
|
||||
return isset($this->useSandbox)
|
||||
? $this->useSandbox
|
||||
: $this->isSandboxModeEnabled();
|
||||
}
|
||||
|
||||
public function setSandboxMode($enabled)
|
||||
{
|
||||
$this->useSandbox = null !== $enabled ? (bool) $enabled : null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getApiToken()
|
||||
{
|
||||
if (isset($this->apiToken)) {
|
||||
return $this->apiToken;
|
||||
}
|
||||
|
||||
return $this->useSandboxMode()
|
||||
? $this->getSandboxApiToken()
|
||||
: $this->getProductionApiToken();
|
||||
}
|
||||
|
||||
public function setApiToken($token)
|
||||
{
|
||||
$this->apiToken = null !== $token ? (string) $token : null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrganizationId()
|
||||
{
|
||||
if (isset($this->organizationId)) {
|
||||
return $this->organizationId;
|
||||
}
|
||||
|
||||
return $this->useSandboxMode()
|
||||
? $this->getSandboxOrganizationId()
|
||||
: $this->getProductionOrganizationId();
|
||||
}
|
||||
|
||||
public function setOrganizationId($organizationId)
|
||||
{
|
||||
$this->organizationId = null !== $organizationId ? (int) $organizationId : null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasConfiguration()
|
||||
{
|
||||
return $this->getOrganizationId() && $this->getApiToken();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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\Configuration;
|
||||
|
||||
class SzybkieZwrotyConfiguration extends AbstractConfiguration
|
||||
{
|
||||
const STORE_NAME = 'INPOST_SHIPPING_SZYBKIE_ZWROTY_STORE_NAME';
|
||||
|
||||
public function getStoreName()
|
||||
{
|
||||
return (string) $this->get(self::STORE_NAME);
|
||||
}
|
||||
|
||||
public function setStoreName($storeName)
|
||||
{
|
||||
return $this->set(self::STORE_NAME, $storeName);
|
||||
}
|
||||
|
||||
public function getUrlTemplate()
|
||||
{
|
||||
return 'https://szybkiezwroty.pl/%s#navigate-buttons';
|
||||
}
|
||||
|
||||
public function getOrderReturnFormUrl($noStore = false)
|
||||
{
|
||||
if (($storeName = $this->getStoreName()) || $noStore) {
|
||||
return sprintf($this->getUrlTemplate(), $storeName);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/src/Configuration/index.php
Normal file
32
modules/inpostshipping/src/Configuration/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;
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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\DataProvider;
|
||||
|
||||
use Carrier;
|
||||
use InPostCarrierModel;
|
||||
use Validate;
|
||||
|
||||
class CarrierDataProvider
|
||||
{
|
||||
protected $carriers = [];
|
||||
|
||||
/** @return InPostCarrierModel|null */
|
||||
public function getInPostCarrierByCarrierId($id_carrier)
|
||||
{
|
||||
if (!isset($this->carriers[$id_carrier])) {
|
||||
$carrier = new Carrier($id_carrier);
|
||||
|
||||
if (Validate::isLoadedObject($inPostCarrier = new InPostCarrierModel($carrier->id_reference))) {
|
||||
$this->carriers[$id_carrier] = $inPostCarrier;
|
||||
} else {
|
||||
$this->carriers[$id_carrier] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->carriers[$id_carrier] ?: null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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\DataProvider;
|
||||
|
||||
use InPostCartChoiceModel;
|
||||
use Validate;
|
||||
|
||||
class CustomerChoiceDataProvider
|
||||
{
|
||||
protected $data = [];
|
||||
|
||||
/** @return InPostCartChoiceModel|null */
|
||||
public function getDataByCartId($id_cart)
|
||||
{
|
||||
if (!isset($this->data[$id_cart])) {
|
||||
if (Validate::isLoadedObject($cartChoice = new InPostCartChoiceModel($id_cart))) {
|
||||
$this->data[$id_cart] = $cartChoice;
|
||||
} else {
|
||||
$this->data[$id_cart] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data[$id_cart] ?: null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?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\DataProvider;
|
||||
|
||||
use InPost\Shipping\PrestaShopContext;
|
||||
use Language;
|
||||
|
||||
class LanguageDataProvider
|
||||
{
|
||||
protected $shopContext;
|
||||
|
||||
protected $languages;
|
||||
protected $locales;
|
||||
|
||||
public function __construct(PrestaShopContext $shopContext)
|
||||
{
|
||||
$this->shopContext = $shopContext;
|
||||
}
|
||||
|
||||
public function getLanguages()
|
||||
{
|
||||
$this->initLanguages();
|
||||
|
||||
return $this->languages;
|
||||
}
|
||||
|
||||
public function getLocaleById($id_lang)
|
||||
{
|
||||
$this->initLanguages();
|
||||
|
||||
return isset($this->languages[$id_lang]) ? $this->languages[$id_lang]['locale'] : null;
|
||||
}
|
||||
|
||||
protected function initLanguages()
|
||||
{
|
||||
if (!isset($this->languages)) {
|
||||
foreach (Language::getLanguages(false) as $language) {
|
||||
if (!$this->shopContext->is17()) {
|
||||
$language['locale'] = $language['iso_code'];
|
||||
}
|
||||
|
||||
$this->languages[$language['id_lang']] = $language;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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\DataProvider;
|
||||
|
||||
use Db;
|
||||
use DbQuery;
|
||||
use InPostProductTemplateModel;
|
||||
|
||||
class OrderDimensionsDataProvider
|
||||
{
|
||||
public function getProductDimensionTemplatesByOrderId($id_order)
|
||||
{
|
||||
return InPostProductTemplateModel::getTemplatesByOrderId($id_order);
|
||||
}
|
||||
|
||||
public function getLargestProductDimensionsByOrderId($id_order)
|
||||
{
|
||||
$query = (new DbQuery())
|
||||
->select('(10 * p.depth) AS length, (10 * p.width) AS width, (10 * p.height) AS height')
|
||||
->from('order_detail', 'od')
|
||||
->innerJoin('product', 'p', 'p.id_product = od.product_id')
|
||||
->where('od.id_order = ' . (int) $id_order)
|
||||
->where('p.depth > 0 OR p.width > 0 OR p.height > 0')
|
||||
->orderBy('(p.depth + p.width + p.height) DESC');
|
||||
|
||||
return Db::getInstance()->getRow($query) ?: null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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\DataProvider;
|
||||
|
||||
use InPost\Shipping\Configuration\ShipXConfiguration;
|
||||
use InPost\Shipping\Presenter\ShipmentPresenter;
|
||||
use InPostShipmentModel;
|
||||
use PrestaShopCollection;
|
||||
|
||||
class OrderShipmentsDataProvider
|
||||
{
|
||||
protected $shipXConfiguration;
|
||||
protected $shipmentPresenter;
|
||||
|
||||
public function __construct(
|
||||
ShipXConfiguration $shipXConfiguration,
|
||||
ShipmentPresenter $shipmentPresenter
|
||||
) {
|
||||
$this->shipXConfiguration = $shipXConfiguration;
|
||||
$this->shipmentPresenter = $shipmentPresenter;
|
||||
}
|
||||
|
||||
public function getOrderShipments($id_order)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
$shipments = (new PrestaShopCollection(InPostShipmentModel::class))
|
||||
->where('sandbox', '=', $this->shipXConfiguration->useSandboxMode())
|
||||
->where('id_order', '=', $id_order)
|
||||
->where('organization_id', '=', $this->shipXConfiguration->getOrganizationId());
|
||||
|
||||
/** @var InPostShipmentModel $shipment */
|
||||
foreach ($shipments as $shipment) {
|
||||
$result[] = $this->shipmentPresenter->present($shipment);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -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\DataProvider;
|
||||
|
||||
use Exception;
|
||||
use InPost\Shipping\Configuration\ShipXConfiguration;
|
||||
use InPost\Shipping\ShipX\Exception\ResourceNotFoundException;
|
||||
use InPost\Shipping\ShipX\Exception\TokenInvalidException;
|
||||
use InPost\Shipping\ShipX\Resource\Organization;
|
||||
use InPost\Shipping\Traits\ErrorsTrait;
|
||||
|
||||
class OrganizationDataProvider
|
||||
{
|
||||
use ErrorsTrait;
|
||||
|
||||
protected $shipXConfiguration;
|
||||
|
||||
protected $organization;
|
||||
|
||||
public function __construct(ShipXConfiguration $shipXConfiguration)
|
||||
{
|
||||
$this->shipXConfiguration = $shipXConfiguration;
|
||||
}
|
||||
|
||||
public function getOrganizationData()
|
||||
{
|
||||
if (!isset($this->organization)) {
|
||||
$this->organization = false;
|
||||
|
||||
if ($organizationId = $this->shipXConfiguration->getOrganizationId()) {
|
||||
try {
|
||||
$this->organization = Organization::get($organizationId)->toArray();
|
||||
} catch (Exception $exception) {
|
||||
if ($exception instanceof TokenInvalidException ||
|
||||
$exception instanceof ResourceNotFoundException
|
||||
) {
|
||||
$this->errors['authorization'] = $exception->getMessage();
|
||||
} else {
|
||||
$this->errors['exception'] = $exception->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->organization;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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\DataProvider;
|
||||
|
||||
use Exception;
|
||||
use InPost\Shipping\ShipX\Exception\ResourceNotFoundException;
|
||||
use InPost\Shipping\ShipX\Resource\Point;
|
||||
use InPost\Shipping\Traits\ErrorsTrait;
|
||||
|
||||
class PointDataProvider
|
||||
{
|
||||
use ErrorsTrait;
|
||||
|
||||
/** @var Point[] */
|
||||
protected $points = [];
|
||||
|
||||
public function getPointData($id)
|
||||
{
|
||||
if (!isset($this->points[$id])) {
|
||||
try {
|
||||
$this->points[$id] = Point::get($id);
|
||||
} catch (ResourceNotFoundException $exception) {
|
||||
$this->points[$id] = false;
|
||||
} catch (Exception $exception) {
|
||||
$this->addError($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return isset($this->points[$id]) ? $this->points[$id] : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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\DataProvider;
|
||||
|
||||
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
|
||||
|
||||
class TemplateDimensionsDataProvider
|
||||
{
|
||||
public function getDimensions($template)
|
||||
{
|
||||
switch ($template) {
|
||||
case Shipment::TEMPLATE_SMALL:
|
||||
return [
|
||||
'dimensions' => [
|
||||
'length' => 80.,
|
||||
'width' => 380.,
|
||||
'height' => 640.,
|
||||
],
|
||||
'weight' => [
|
||||
'amount' => 25.,
|
||||
],
|
||||
];
|
||||
case Shipment::TEMPLATE_MEDIUM:
|
||||
return [
|
||||
'dimensions' => [
|
||||
'length' => 190.,
|
||||
'width' => 380.,
|
||||
'height' => 640.,
|
||||
],
|
||||
'weight' => [
|
||||
'amount' => 25.,
|
||||
],
|
||||
];
|
||||
case Shipment::TEMPLATE_LARGE:
|
||||
return [
|
||||
'dimensions' => [
|
||||
'length' => 410.,
|
||||
'width' => 380.,
|
||||
'height' => 640.,
|
||||
],
|
||||
'weight' => [
|
||||
'amount' => 25.,
|
||||
],
|
||||
];
|
||||
case Shipment::TEMPLATE_EXTRA_LARGE:
|
||||
return [
|
||||
'dimensions' => [
|
||||
'length' => 500.,
|
||||
'width' => 500.,
|
||||
'height' => 800.,
|
||||
],
|
||||
'weight' => [
|
||||
'amount' => 25.,
|
||||
],
|
||||
];
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/src/DataProvider/index.php
Normal file
32
modules/inpostshipping/src/DataProvider/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;
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidActionException extends Exception
|
||||
{
|
||||
}
|
||||
32
modules/inpostshipping/src/Exception/index.php
Normal file
32
modules/inpostshipping/src/Exception/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;
|
||||
98
modules/inpostshipping/src/Handler/CronJobsHandler.php
Normal file
98
modules/inpostshipping/src/Handler/CronJobsHandler.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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\Handler;
|
||||
|
||||
use Context;
|
||||
use InPost\Shipping\Adapter\ToolsAdapter;
|
||||
use InPost\Shipping\Exception\InvalidActionException;
|
||||
use InPost\Shipping\Handler\Shipment\UpdateShipmentStatusHandler;
|
||||
use InPostShipping;
|
||||
|
||||
class CronJobsHandler
|
||||
{
|
||||
const ACTION_UPDATE_SHIPMENT_STATUS = 'updateShipmentStatus';
|
||||
|
||||
const ACTIONS = [
|
||||
self::ACTION_UPDATE_SHIPMENT_STATUS,
|
||||
];
|
||||
|
||||
protected $module;
|
||||
protected $context;
|
||||
protected $tools;
|
||||
protected $updateShipmentStatusHandler;
|
||||
|
||||
public function __construct(
|
||||
InPostShipping $module,
|
||||
ToolsAdapter $tools,
|
||||
UpdateShipmentStatusHandler $updateShipmentStatusHandler
|
||||
) {
|
||||
$this->module = $module;
|
||||
$this->context = Context::getContext();
|
||||
$this->tools = $tools;
|
||||
$this->updateShipmentStatusHandler = $updateShipmentStatusHandler;
|
||||
}
|
||||
|
||||
public function handle($action)
|
||||
{
|
||||
set_time_limit(0);
|
||||
|
||||
switch ($action) {
|
||||
case self::ACTION_UPDATE_SHIPMENT_STATUS:
|
||||
$this->updateShipmentStatusHandler->handle();
|
||||
break;
|
||||
default:
|
||||
throw new InvalidActionException();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAvailableActionsUrls()
|
||||
{
|
||||
$urls = [];
|
||||
|
||||
foreach (self::ACTIONS as $action) {
|
||||
$urls[$action] = $this->getActionUrl($action);
|
||||
}
|
||||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
public function checkToken($token)
|
||||
{
|
||||
return $token === $this->getToken();
|
||||
}
|
||||
|
||||
protected function getActionUrl($action)
|
||||
{
|
||||
return $this->context->link->getModuleLink($this->module->name, 'cron', [
|
||||
'action' => $action,
|
||||
'token' => $this->getToken(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getToken()
|
||||
{
|
||||
return $this->tools->hash($this->module->name . '_cron');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?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\Handler\DispatchOrder;
|
||||
|
||||
use Exception;
|
||||
use InPost\Shipping\Builder\DispatchOrder\CreateDispatchOrderPayloadBuilder;
|
||||
use InPost\Shipping\ShipX\Exception\ValidationFailedException;
|
||||
use InPost\Shipping\ShipX\Resource\Organization\DispatchOrder;
|
||||
use InPost\Shipping\Traits\ErrorsTrait;
|
||||
use InPost\Shipping\Translations\ValidationErrorTranslator;
|
||||
use InPostDispatchOrderModel;
|
||||
use InPostDispatchPointModel;
|
||||
use InPostShipping;
|
||||
use Validate;
|
||||
|
||||
class CreateDispatchOrderHandler
|
||||
{
|
||||
use ErrorsTrait;
|
||||
const TRANSLATION_SOURCE = 'CreateDispatchOrderHandler';
|
||||
|
||||
const RETRY_NUMBER = 2;
|
||||
|
||||
protected $module;
|
||||
protected $errorTranslator;
|
||||
protected $payloadBuilder;
|
||||
|
||||
public function __construct(
|
||||
InPostShipping $module,
|
||||
ValidationErrorTranslator $errorTranslator,
|
||||
CreateDispatchOrderPayloadBuilder $dispatchOrderPayloadBuilder
|
||||
) {
|
||||
$this->module = $module;
|
||||
$this->errorTranslator = $errorTranslator;
|
||||
$this->payloadBuilder = $dispatchOrderPayloadBuilder;
|
||||
}
|
||||
|
||||
public function handle(array $shipmentIds, $id_dispatch_point)
|
||||
{
|
||||
$this->resetErrors();
|
||||
|
||||
try {
|
||||
$dispatchPoint = new InPostDispatchPointModel($id_dispatch_point);
|
||||
|
||||
if (Validate::isLoadedObject($dispatchPoint)) {
|
||||
$payload = $this->payloadBuilder->buildPayload($dispatchPoint, $shipmentIds);
|
||||
|
||||
$this->waitForDispatchOrderNumber(
|
||||
$dispatchOrder = DispatchOrder::create($payload)
|
||||
);
|
||||
|
||||
return $this->saveDispatchOrder($dispatchOrder, $dispatchPoint);
|
||||
} else {
|
||||
$this->addError(
|
||||
$this->module->l('Invalid dispatch point ID', self::TRANSLATION_SOURCE)
|
||||
);
|
||||
}
|
||||
} catch (ValidationFailedException $exception) {
|
||||
if ($errors = $exception->getValidationErrors()) {
|
||||
$this->translateErrors($errors);
|
||||
} else {
|
||||
$this->addError($exception->getDetails());
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
$this->addError($exception->getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function saveDispatchOrder(
|
||||
DispatchOrder $dispatchOrder,
|
||||
InPostDispatchPointModel $dispatchPoint
|
||||
) {
|
||||
$dispatchOrderModel = new InPostDispatchOrderModel();
|
||||
|
||||
$dispatchOrderModel->shipx_dispatch_order_id = $dispatchOrder->getId();
|
||||
$dispatchOrderModel->id_dispatch_point = $dispatchPoint->id;
|
||||
$dispatchOrderModel->status = $dispatchOrder->status;
|
||||
|
||||
if ($number = $dispatchOrder->external_id) {
|
||||
$dispatchOrderModel->number = $number;
|
||||
}
|
||||
|
||||
if ($price = $dispatchOrder->price) {
|
||||
$dispatchOrderModel->price = $price;
|
||||
}
|
||||
|
||||
if ($dispatchOrderModel->add()) {
|
||||
return $dispatchOrderModel;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function waitForDispatchOrderNumber(DispatchOrder $dispatchOrder)
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
$number = $dispatchOrder->external_id;
|
||||
while (empty($number) && $i++ < self::RETRY_NUMBER) {
|
||||
sleep(1);
|
||||
$dispatchOrder->refresh();
|
||||
$number = $dispatchOrder->external_id;
|
||||
}
|
||||
}
|
||||
|
||||
protected function translateErrors($errors)
|
||||
{
|
||||
foreach ($errors as $fieldName => $values) {
|
||||
foreach ($values as $error) {
|
||||
$this->addError($this->errorTranslator->translate($error, $fieldName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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\Handler\DispatchOrder;
|
||||
|
||||
use InPost\Shipping\Configuration\ShipXConfiguration;
|
||||
use InPost\Shipping\ShipX\Resource\Organization\DispatchOrder;
|
||||
use InPostDispatchOrderModel;
|
||||
|
||||
class UpdateDispatchOrderHandler
|
||||
{
|
||||
protected $shipXConfiguration;
|
||||
|
||||
public function __construct(ShipXConfiguration $shipXConfiguration)
|
||||
{
|
||||
$this->shipXConfiguration = $shipXConfiguration;
|
||||
}
|
||||
|
||||
public function handle(array $ids = [])
|
||||
{
|
||||
$collection = InPostDispatchOrderModel::getDispatchOrders(
|
||||
$this->shipXConfiguration->useSandboxMode(),
|
||||
$this->shipXConfiguration->getOrganizationId(),
|
||||
$ids
|
||||
);
|
||||
|
||||
if (count($collection)) {
|
||||
$dispatchOrderIds = [];
|
||||
$collectionKeyIndex = [];
|
||||
|
||||
foreach ($collection as $key => $dispatchOrderModel) {
|
||||
$dispatchOrderIds[] = $dispatchOrderModel->shipx_dispatch_order_id;
|
||||
$collectionKeyIndex[$dispatchOrderModel->shipx_dispatch_order_id] = $key;
|
||||
}
|
||||
|
||||
/** @var DispatchOrder $dispatchOrder */
|
||||
foreach (DispatchOrder::getCollection(['id' => $dispatchOrderIds]) as $dispatchOrder) {
|
||||
$dispatchOrderModel = $collection[$collectionKeyIndex[$dispatchOrder->getId()]];
|
||||
if ($dispatchOrderModel->number != $dispatchOrder->external_id ||
|
||||
$dispatchOrderModel->status != $dispatchOrder->status
|
||||
) {
|
||||
if ($number = $dispatchOrder->external_id) {
|
||||
$dispatchOrderModel->number = $number;
|
||||
}
|
||||
$dispatchOrderModel->status = $dispatchOrder->status;
|
||||
$dispatchOrderModel->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
modules/inpostshipping/src/Handler/DispatchOrder/index.php
Normal file
32
modules/inpostshipping/src/Handler/DispatchOrder/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;
|
||||
88
modules/inpostshipping/src/Handler/ProductUpdateHandler.php
Normal file
88
modules/inpostshipping/src/Handler/ProductUpdateHandler.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?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\Handler;
|
||||
|
||||
use InPost\Shipping\ChoiceProvider\ShippingServiceChoiceProvider;
|
||||
use InPost\Shipping\ShipX\Resource\Service;
|
||||
use InPost\Shipping\Traits\ErrorsTrait;
|
||||
use InPostProductTemplateModel;
|
||||
use InPostShipping;
|
||||
use Product;
|
||||
use Validate;
|
||||
|
||||
class ProductUpdateHandler
|
||||
{
|
||||
use ErrorsTrait;
|
||||
|
||||
const TRANSLATION_SOURCE = 'ProductUpdateHandler';
|
||||
|
||||
protected $module;
|
||||
protected $serviceChoiceProvider;
|
||||
|
||||
public function __construct(
|
||||
InPostShipping $module,
|
||||
ShippingServiceChoiceProvider $serviceChoiceProvider
|
||||
) {
|
||||
$this->module = $module;
|
||||
$this->serviceChoiceProvider = $serviceChoiceProvider;
|
||||
}
|
||||
|
||||
public function update(Product $product, $template)
|
||||
{
|
||||
$this->resetErrors();
|
||||
|
||||
$productTemplate = new InPostProductTemplateModel($product->id);
|
||||
|
||||
if ($template !== null) {
|
||||
if (!in_array($template, $this->serviceChoiceProvider->getAvailableTemplates(Service::INPOST_LOCKER_STANDARD))) {
|
||||
$this->addError(
|
||||
$this->module->l('Selected InPost shipment dimension template is not valid', self::TRANSLATION_SOURCE)
|
||||
);
|
||||
} else {
|
||||
$productTemplate->template = $template;
|
||||
if (Validate::isLoadedObject($productTemplate)) {
|
||||
if (!$productTemplate->update()) {
|
||||
$this->addError(
|
||||
$this->module->l('Could not update default InPost shipment dimension template', self::TRANSLATION_SOURCE)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$productTemplate->id = $product->id;
|
||||
if (!$productTemplate->add()) {
|
||||
$this->addError(
|
||||
$this->module->l('Could not update default InPost shipment dimension template', self::TRANSLATION_SOURCE)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif (Validate::isLoadedObject($productTemplate) && !$productTemplate->delete()) {
|
||||
$this->addError(
|
||||
$this->module->l('Could not remove default InPost shipment dimension template', self::TRANSLATION_SOURCE)
|
||||
);
|
||||
}
|
||||
|
||||
return !$this->hasErrors();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?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\Handler\Shipment;
|
||||
|
||||
use Exception;
|
||||
use InPost\Shipping\ShipX\Exception\ValidationFailedException;
|
||||
use InPost\Shipping\ShipX\Resource\Organization\Shipment;
|
||||
use InPostShipmentModel;
|
||||
use Order;
|
||||
use PrestaShopCollection;
|
||||
|
||||
class BulkCreateShipmentHandler extends CreateShipmentHandler
|
||||
{
|
||||
const TRANSLATION_SOURCE = 'BulkCreateShipmentHandler';
|
||||
|
||||
public function handle(array $request)
|
||||
{
|
||||
$this->resetErrors();
|
||||
|
||||
if (!empty($request['orderIds'])) {
|
||||
$orders = (new PrestaShopCollection(Order::class))
|
||||
->where('id_order', 'IN', $request['orderIds']);
|
||||
|
||||
if (count($orders)) {
|
||||
$shipments = [];
|
||||
|
||||
/** @var Order $order */
|
||||
foreach ($orders as $order) {
|
||||
try {
|
||||
if ($payload = $this->payloadBuilder->buildPayload($order)) {
|
||||
$shipments[] = $this->saveShipment($order, Shipment::create($payload));
|
||||
}
|
||||
} catch (ValidationFailedException $exception) {
|
||||
if ($errors = $exception->getValidationErrors()) {
|
||||
foreach ($this->translateErrors($errors) as $error) {
|
||||
$this->addOrderError($order->reference, $error);
|
||||
}
|
||||
} else {
|
||||
$this->addError($exception->getDetails());
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
$this->addOrderError($order->reference, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$this->waitForTransactionsData($shipments);
|
||||
} catch (Exception $exception) {
|
||||
$this->addError($exception->getMessage());
|
||||
}
|
||||
|
||||
if (empty($shipments) && !$this->hasErrors()) {
|
||||
$this->addError($this->module->l('None of the selected orders were placed with an InPost carrier as a delivery option', self::TRANSLATION_SOURCE));
|
||||
}
|
||||
|
||||
return $shipments;
|
||||
} else {
|
||||
$this->addError($this->module->l('Invalid order IDs', self::TRANSLATION_SOURCE));
|
||||
}
|
||||
} else {
|
||||
$this->addError($this->module->l('No orders selected', self::TRANSLATION_SOURCE));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @param InPostShipmentModel[] $shipments */
|
||||
private function waitForTransactionsData(array $shipments)
|
||||
{
|
||||
$shipmentIds = [];
|
||||
$remaining = [];
|
||||
|
||||
foreach ($shipments as $shipmentModel) {
|
||||
$remaining[$shipmentModel->shipx_shipment_id] = $shipmentModel;
|
||||
$shipmentIds[$shipmentModel->shipx_shipment_id] = $shipmentModel->shipx_shipment_id;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
while (!empty($remaining) && $i++ < self::REFRESH_RETRY_NUMBER) {
|
||||
sleep(1);
|
||||
|
||||
/** @var Shipment $shipment */
|
||||
foreach (Shipment::getCollection(['id' => $shipmentIds]) as $shipment) {
|
||||
$transactions = $shipment->transactions;
|
||||
if (!empty($transactions)) {
|
||||
$shipmentModel = $remaining[$shipment->id];
|
||||
|
||||
$transaction = current($transactions);
|
||||
if ($transaction['status'] !== 'success') {
|
||||
$this->addOrderError(
|
||||
$shipmentModel->getOrder()->reference,
|
||||
$this->getTransactionError($transaction)
|
||||
);
|
||||
} else {
|
||||
$shipmentModel->status = $shipment->status;
|
||||
$shipmentModel->tracking_number = $shipment->tracking_number;
|
||||
$shipmentModel->update();
|
||||
$shipmentModel->updateOrderTrackingNumber();
|
||||
}
|
||||
|
||||
unset(
|
||||
$remaining[$shipmentModel->shipx_shipment_id],
|
||||
$shipmentIds[$shipmentModel->shipx_shipment_id]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function addOrderError($reference, $error)
|
||||
{
|
||||
return $this->addError(sprintf(
|
||||
$this->module->l('Order "%s": %s', self::TRANSLATION_SOURCE),
|
||||
$reference,
|
||||
$error
|
||||
));
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user