Add InPost Pay integration to admin templates
- Created a new template for the cart rule form with custom label, switch, and choice widgets. - Implemented the InPost Pay block in the order details template for displaying delivery method, APM, and VAT invoice request. - Added legacy support for the order details template to maintain compatibility with older PrestaShop versions.
This commit is contained in:
59
modules/inpostizi/src/Event/Adapter/EventDispatcher.php
Normal file
59
modules/inpostizi/src/Event/Adapter/EventDispatcher.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace izi\prestashop\Event\Adapter;
|
||||
|
||||
use izi\prestashop\Event\Event;
|
||||
use izi\prestashop\Event\EventDispatcherInterface as ModuleEventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* @mixin EventDispatcherInterface
|
||||
*/
|
||||
final class EventDispatcher implements ModuleEventDispatcher
|
||||
{
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
private $dispatcher;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isLegacyDispatcher;
|
||||
|
||||
public function __construct(EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->isLegacyDispatcher = !$this->dispatcher instanceof ContractsEventDispatcherInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function dispatch(Event $event, ?string $eventName = null): Event
|
||||
{
|
||||
$eventName = $eventName ?? get_class($event);
|
||||
|
||||
return $this->isLegacyDispatcher
|
||||
? $this->dispatcher->dispatch($eventName, $event)
|
||||
: $this->dispatcher->dispatch($event, $eventName);
|
||||
}
|
||||
|
||||
public function addListener(string $eventName, callable $listener, int $priority = 0): void
|
||||
{
|
||||
$this->dispatcher->addListener($eventName, $listener, $priority);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards calls to the inner dispatcher.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call(string $name, array $arguments)
|
||||
{
|
||||
return $this->dispatcher->$name(...$arguments);
|
||||
}
|
||||
}
|
||||
23
modules/inpostizi/src/Event/CartUpdatedEvent.php
Normal file
23
modules/inpostizi/src/Event/CartUpdatedEvent.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace izi\prestashop\Event;
|
||||
|
||||
final class CartUpdatedEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var \Cart
|
||||
*/
|
||||
private $cart;
|
||||
|
||||
public function __construct(\Cart $cart)
|
||||
{
|
||||
$this->cart = $cart;
|
||||
}
|
||||
|
||||
public function getCart(): \Cart
|
||||
{
|
||||
return $this->cart;
|
||||
}
|
||||
}
|
||||
35
modules/inpostizi/src/Event/CreateShipmentRequestEvent.php
Normal file
35
modules/inpostizi/src/Event/CreateShipmentRequestEvent.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace izi\prestashop\Event;
|
||||
|
||||
use AdminInPostConfirmedShipmentsController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
final class CreateShipmentRequestEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var AdminInPostConfirmedShipmentsController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
private $request;
|
||||
|
||||
public function __construct(Request $request, AdminInPostConfirmedShipmentsController $controller)
|
||||
{
|
||||
$this->controller = $controller;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function getController(): AdminInPostConfirmedShipmentsController
|
||||
{
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
public function getRequest(): Request
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace izi\prestashop\Event;
|
||||
|
||||
use AdminInPostConfirmedShipmentsController;
|
||||
|
||||
final class CreateShipmentRequestProcessedEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var AdminInPostConfirmedShipmentsController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function __construct(AdminInPostConfirmedShipmentsController $controller)
|
||||
{
|
||||
$this->controller = $controller;
|
||||
}
|
||||
|
||||
public function getController(): AdminInPostConfirmedShipmentsController
|
||||
{
|
||||
return $this->controller;
|
||||
}
|
||||
}
|
||||
18
modules/inpostizi/src/Event/Event.php
Normal file
18
modules/inpostizi/src/Event/Event.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace izi\prestashop\Event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event as LegacyEvent;
|
||||
use Symfony\Contracts\EventDispatcher\Event as BaseEvent;
|
||||
|
||||
if (class_exists(LegacyEvent::class)) {
|
||||
class Event extends LegacyEvent
|
||||
{
|
||||
}
|
||||
} else {
|
||||
class Event extends BaseEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
95
modules/inpostizi/src/Event/EventDispatcherFactory.php
Normal file
95
modules/inpostizi/src/Event/EventDispatcherFactory.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace izi\prestashop\Event;
|
||||
|
||||
use izi\prestashop\Analytics\EventListener\UpdateBasketAnalyticsListener;
|
||||
use izi\prestashop\DependencyInjection\ServiceSubscriberInterface;
|
||||
use izi\prestashop\EventListener\CartListener;
|
||||
use izi\prestashop\EventListener\CreateShipmentListener;
|
||||
use izi\prestashop\EventListener\OrderListener;
|
||||
use izi\prestashop\EventListener\ShipmentListener;
|
||||
use izi\prestashop\Form\BasketAppClientProvider;
|
||||
use izi\prestashop\HotProduct\EventListener\UpdateHotProductsListener;
|
||||
use izi\prestashop\Mail\EventListener\ReplaceOrderNotificationRecipientListener;
|
||||
use izi\prestashop\MerchantApi\EventListener\UpdateCartRulesListener;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EventDispatcherFactory implements ServiceSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $locator;
|
||||
|
||||
public function __construct(ContainerInterface $locator)
|
||||
{
|
||||
$this->locator = $locator;
|
||||
}
|
||||
|
||||
public static function getSubscribedServices(): array
|
||||
{
|
||||
return [
|
||||
CartListener::class,
|
||||
OrderListener::class,
|
||||
ShipmentListener::class,
|
||||
UpdateHotProductsListener::class,
|
||||
ReplaceOrderNotificationRecipientListener::class,
|
||||
UpdateBasketAnalyticsListener::class,
|
||||
'?' . BasketAppClientProvider::class,
|
||||
'?' . UpdateCartRulesListener::class,
|
||||
'?' . CreateShipmentListener::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function create(): EventDispatcherInterface
|
||||
{
|
||||
$dispatcher = new EventDispatcher();
|
||||
|
||||
foreach (self::getSubscribedServices() as $serviceId) {
|
||||
$className = '?' === $serviceId[0] ? \Tools::substr($serviceId, 1) : $serviceId;
|
||||
|
||||
$this->addListeners($dispatcher, $className);
|
||||
}
|
||||
|
||||
return $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<EventSubscriberInterface> $className
|
||||
*/
|
||||
private function addListeners(EventDispatcherInterface $dispatcher, string $className): void
|
||||
{
|
||||
foreach ($className::getSubscribedEvents() as $eventName => $parameters) {
|
||||
foreach ($this->normalizeListeners($parameters) as $listener) {
|
||||
[$method, $priority] = $listener;
|
||||
|
||||
$dispatcher->addListener($eventName, function ($event) use ($className, $method) {
|
||||
return $this->locator->get($className)->{$method}($event);
|
||||
}, $priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizeListeners($parameters): array
|
||||
{
|
||||
if (is_string($parameters)) {
|
||||
return [[$parameters, 0]];
|
||||
}
|
||||
|
||||
if (is_string($parameters[0])) {
|
||||
return [[$parameters[0], $parameters[1] ?? 0]];
|
||||
}
|
||||
|
||||
return array_map(static function ($listener) {
|
||||
return [$listener[0], $listener[1] ?? 0];
|
||||
}, $parameters);
|
||||
}
|
||||
}
|
||||
21
modules/inpostizi/src/Event/EventDispatcherInterface.php
Normal file
21
modules/inpostizi/src/Event/EventDispatcherInterface.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace izi\prestashop\Event;
|
||||
|
||||
/**
|
||||
* @method addListener(string $eventName, callable $listener, int $priority = 0)
|
||||
*/
|
||||
interface EventDispatcherInterface
|
||||
{
|
||||
/**
|
||||
* @template T of Event $event
|
||||
*
|
||||
* @param T $event
|
||||
* @param string|null $eventName if null, the supplied event's class name will be used
|
||||
*
|
||||
* @return T the passed event
|
||||
*/
|
||||
public function dispatch(Event $event, ?string $eventName = null): Event;
|
||||
}
|
||||
26
modules/inpostizi/src/Event/OrderEvent.php
Normal file
26
modules/inpostizi/src/Event/OrderEvent.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace izi\prestashop\Event;
|
||||
|
||||
final class OrderEvent extends Event
|
||||
{
|
||||
public const BEFORE_UPDATE = 'inpostizi.order.before_update';
|
||||
public const UPDATED = 'inpostizi.order.updated';
|
||||
|
||||
/**
|
||||
* @var \Order
|
||||
*/
|
||||
private $order;
|
||||
|
||||
public function __construct(\Order $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
public function getOrder(): \Order
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
}
|
||||
34
modules/inpostizi/src/Event/OrderStatusUpdatedEvent.php
Normal file
34
modules/inpostizi/src/Event/OrderStatusUpdatedEvent.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace izi\prestashop\Event;
|
||||
|
||||
final class OrderStatusUpdatedEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $orderId;
|
||||
|
||||
/**
|
||||
* @var \OrderState
|
||||
*/
|
||||
private $newOrderStatus;
|
||||
|
||||
public function __construct(int $orderId, \OrderState $newOrderStatus)
|
||||
{
|
||||
$this->orderId = $orderId;
|
||||
$this->newOrderStatus = $newOrderStatus;
|
||||
}
|
||||
|
||||
public function getOrderId(): int
|
||||
{
|
||||
return $this->orderId;
|
||||
}
|
||||
|
||||
public function getNewOrderStatus(): \OrderState
|
||||
{
|
||||
return $this->newOrderStatus;
|
||||
}
|
||||
}
|
||||
27
modules/inpostizi/src/Event/ShipmentEvent.php
Normal file
27
modules/inpostizi/src/Event/ShipmentEvent.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace izi\prestashop\Event;
|
||||
|
||||
final class ShipmentEvent extends Event
|
||||
{
|
||||
public const CREATED = 'inpostizi.shipment.created';
|
||||
public const BEFORE_UPDATE = 'inpostizi.shipment.before_update';
|
||||
public const UPDATED = 'inpostizi.shipment.updated';
|
||||
|
||||
/**
|
||||
* @var \InPostShipmentModel
|
||||
*/
|
||||
private $shipment;
|
||||
|
||||
public function __construct(\InPostShipmentModel $shipment)
|
||||
{
|
||||
$this->shipment = $shipment;
|
||||
}
|
||||
|
||||
public function getShipment(): \InPostShipmentModel
|
||||
{
|
||||
return $this->shipment;
|
||||
}
|
||||
}
|
||||
21
modules/inpostizi/src/Event/ValidateOrderEvent.php
Normal file
21
modules/inpostizi/src/Event/ValidateOrderEvent.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace izi\prestashop\Event;
|
||||
|
||||
final class ValidateOrderEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var \Order
|
||||
*/
|
||||
private $order;
|
||||
|
||||
public function __construct(\Order $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
public function getOrder(): \Order
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user