Skip to content

Commit

Permalink
Release V1.0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
roerlemans committed Sep 21, 2021
1 parent f435927 commit a38e2fd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions Observer/AutoShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use DHLParcel\Shipping\Model\Service\Printing as PrintingService;
use DHLParcel\Shipping\Model\Service\Shipment as ShipmentService;
use Magento\Framework\Event\ManagerInterface as EventManager;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;

class AutoShipment implements \Magento\Framework\Event\ObserverInterface
{
Expand All @@ -21,9 +23,11 @@ class AutoShipment implements \Magento\Framework\Event\ObserverInterface
protected $presetService;
protected $eventManager;
protected $productMetadata;
protected $orderRepository;

public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
OrderRepositoryInterface $orderRepository,
EventManager $eventManager,
Data $helper,
OrderService $orderService,
Expand All @@ -33,6 +37,7 @@ public function __construct(
PresetService $presetService
) {
$this->productMetadata = $productMetadata;
$this->orderRepository = $orderRepository;
$this->helper = $helper;
$this->orderService = $orderService;
$this->shipmentService = $shipmentService;
Expand All @@ -50,13 +55,25 @@ public function execute(\Magento\Framework\Event\Observer $observer)
return;
}

$order = $observer->getEvent()->getOrder();
$observerOrder = $observer->getEvent()->getOrder();
if (!$observerOrder || !$observerOrder->getId()) {
return;
}

if ($order->getStatus() !== $this->helper->getConfigData('usability/automation/on_order_status')) {
if ($observerOrder->getStatus() !== $this->helper->getConfigData('usability/automation/on_order_status')) {
return;
}
if (!$observerOrder->canShip() || $observerOrder->hasShipments() || $observerOrder->getShipmentsCollection()->count() > 0) {
return;
}

if (!$order->canShip() || $order->hasShipments() || !empty($order->getShipmentsCollection()->getData())) {
/**
* Force new order from database, looks like object is not always reliable
*
* @var $order Order
*/
$order = $this->orderRepository->get($observer->getEvent()->getOrder()->getId());
if (!$order->canShip() || $order->hasShipments() || $order->getShipmentsCollection()->count() > 0) {
return;
}

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.25",
"version": "1.0.26",
"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.25">
<module name="DHLParcel_Shipping" setup_version="1.0.26">
<sequence>
<module name="Magento_Shipping"/>
<module name="Magento_Checkout"/>
Expand Down

0 comments on commit a38e2fd

Please sign in to comment.