From f41c21e06a6bb5ed2e4fe4398c369cdc52e31cda Mon Sep 17 00:00:00 2001 From: Shin Ho Date: Thu, 18 Nov 2021 22:06:32 +0000 Subject: [PATCH] Release V1.0.31 --- Model/Registry/CurrentAutoShipment.php | 18 ++++++++++++++++++ Observer/AutoShipment.php | 14 +++++++++++++- composer.json | 2 +- etc/module.xml | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 Model/Registry/CurrentAutoShipment.php diff --git a/Model/Registry/CurrentAutoShipment.php b/Model/Registry/CurrentAutoShipment.php new file mode 100644 index 0000000..ad90e07 --- /dev/null +++ b/Model/Registry/CurrentAutoShipment.php @@ -0,0 +1,18 @@ +orderId = $id; + } + + public function getOrderId() + { + return isset($this->orderId) ? $this->orderId : null; + } +} diff --git a/Observer/AutoShipment.php b/Observer/AutoShipment.php index 747e48f..04ef52d 100644 --- a/Observer/AutoShipment.php +++ b/Observer/AutoShipment.php @@ -9,6 +9,7 @@ use DHLParcel\Shipping\Model\Service\Preset as PresetService; use DHLParcel\Shipping\Model\Service\Printing as PrintingService; use DHLParcel\Shipping\Model\Service\Shipment as ShipmentService; +use DHLParcel\Shipping\Model\Registry\CurrentAutoShipment; use Magento\Framework\Event\ManagerInterface as EventManager; use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Sales\Model\Order; @@ -24,6 +25,7 @@ class AutoShipment implements \Magento\Framework\Event\ObserverInterface protected $eventManager; protected $productMetadata; protected $orderRepository; + protected $currentAutoShipment; public function __construct( \Magento\Framework\App\ProductMetadataInterface $productMetadata, @@ -34,7 +36,8 @@ public function __construct( ShipmentService $shipmentService, LabelService $labelService, PrintingService $printingService, - PresetService $presetService + PresetService $presetService, + CurrentAutoShipment $currentAutoShipment ) { $this->productMetadata = $productMetadata; $this->orderRepository = $orderRepository; @@ -45,6 +48,7 @@ public function __construct( $this->printingService = $printingService; $this->presetService = $presetService; $this->eventManager = $eventManager; + $this->currentAutoShipment = $currentAutoShipment; } public function execute(\Magento\Framework\Event\Observer $observer) @@ -81,6 +85,14 @@ public function execute(\Magento\Framework\Event\Observer $observer) return; } + // Check if current autoShipment is already initiated + if ($this->currentAutoShipment === $order->getId()) { + // Skip auto shipment, it's already underway + return; + } else { + $this->currentAutoShipment->setOrderId($order->getId()); + } + $shipment = $this->orderService->createShipment($order->getId()); if (boolval($this->helper->getConfigData('usability/automation/print'))) { diff --git a/composer.json b/composer.json index ce5fe25..4982d22 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "dhlparcel/magento2-plugin", "description": "DHL Parcel plugin for Magento 2", "type": "magento2-module", - "version": "1.0.30", + "version": "1.0.31", "license": [ "OSL-3.0" ], diff --git a/etc/module.xml b/etc/module.xml index 6504a24..49fc5f1 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -18,7 +18,7 @@ - +