first commit
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user