Skip to content

Commit

Permalink
Release V1.0.31
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinCode committed Nov 18, 2021
1 parent 95a5379 commit f41c21e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
18 changes: 18 additions & 0 deletions Model/Registry/CurrentAutoShipment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace DHLParcel\Shipping\Model\Registry;

class CurrentAutoShipment
{
protected $orderId;

public function setOrderId($id)
{
$this->orderId = $id;
}

public function getOrderId()
{
return isset($this->orderId) ? $this->orderId : null;
}
}
14 changes: 13 additions & 1 deletion Observer/AutoShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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'))) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="DHLParcel_Shipping" setup_version="1.0.30">
<module name="DHLParcel_Shipping" setup_version="1.0.31">
<sequence>
<module name="Magento_Shipping"/>
<module name="Magento_Checkout"/>
Expand Down

0 comments on commit f41c21e

Please sign in to comment.