diff --git a/app/code/Ometria/AbandonedCarts/etc/module.xml b/app/code/Ometria/AbandonedCarts/etc/module.xml index 231bba6..6b92671 100755 --- a/app/code/Ometria/AbandonedCarts/etc/module.xml +++ b/app/code/Ometria/AbandonedCarts/etc/module.xml @@ -1,4 +1,4 @@ - + diff --git a/app/code/Ometria/Api/etc/module.xml b/app/code/Ometria/Api/etc/module.xml index 3d28e07..70e973c 100755 --- a/app/code/Ometria/Api/etc/module.xml +++ b/app/code/Ometria/Api/etc/module.xml @@ -1,4 +1,4 @@ - + diff --git a/app/code/Ometria/Core/Plugin/OrderManagementPlugin.php b/app/code/Ometria/Core/Plugin/OrderManagementPlugin.php index 717167e..4c98e21 100644 --- a/app/code/Ometria/Core/Plugin/OrderManagementPlugin.php +++ b/app/code/Ometria/Core/Plugin/OrderManagementPlugin.php @@ -68,24 +68,33 @@ private function sendPushNotifications(OrderInterface $order) } foreach ($order->getItems() as $orderItem) { + if ($orderItem->getHasChildren() == true) { + // Skip parent items (configurable product parents etc) + continue; + } + // Retrieve the salable qty of the product based on configured scope $salableQty = $this->getSalableQty( $orderItem->getProduct(), $stockPushScope ); - // if salable qty is set and not already 0, check if push is required (null infers manage stock is disabled) - if ($salableQty !== null && $salableQty > 0) { - // Calculate new salabale quantity (after order placement) - $salableQtyAfterOrder = $salableQty - $orderItem->getQtyOrdered(); - if ($salableQtyAfterOrder <= 0) { - $stockData = $this->inventoryService->getPushApiStockData( - (int)$orderItem->getProductId(), - false - ); - - $this->pushApiService->pushRequest($stockData); - } + if ($this->inventoryService->isReservationsAfter()) { + /* + * Adjust salable qty to compensate for a core API inconsistency across Magento versions + * which affects the salable quantity calculation based on the order in which reservations are deducted. + */ + $salableQty = $salableQty - $orderItem->getQtyOrdered(); + } + + // If salable qty is set, check if push is required for zero stock (null implies manage stock is disabled) + if ($salableQty !== null && $salableQty <= 0) { + $stockData = $this->inventoryService->getPushApiStockData( + (int)$orderItem->getProductId(), + false + ); + + $this->pushApiService->pushRequest($stockData); } } } diff --git a/app/code/Ometria/Core/Service/Product/Inventory.php b/app/code/Ometria/Core/Service/Product/Inventory.php index e92fb2b..cc2063e 100644 --- a/app/code/Ometria/Core/Service/Product/Inventory.php +++ b/app/code/Ometria/Core/Service/Product/Inventory.php @@ -13,6 +13,7 @@ use Magento\Framework\Module\Manager as ModuleManager; use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface; use Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException; +use Magento\InventorySales\Plugin\Sales\OrderManagement\AppendReservationsAfterOrderPlacementPlugin; use Magento\InventorySalesAdminUi\Model\ResourceModel\GetAssignedStockIdsBySku; use Magento\InventorySalesApi\Api\Data\SalesChannelInterface; use Magento\InventorySalesApi\Api\GetProductSalableQtyInterface; @@ -132,6 +133,21 @@ public function addLegacyStockFilterToCollection(ProductCollection $collection) } } + /** + * This function checks which implementation exists in the AppendReservations plugin to determine + * whether the salable qty of a product will reflect the ordered amount inclusive of reservation or not. + * + * As of magento/module-inventory-sales@1.1.0 the afterPlace() function was replaced with an aroundPlace() + * function, resulting in the reservations being applied before the order placement (despite the plugin + * being named "AfterOrderPlacement"). + * + * @return bool + */ + public function isReservationsAfter() + { + return method_exists(AppendReservationsAfterOrderPlacementPlugin::class, 'afterPlace'); + } + /** * @param ProductInterface $product * @param $stockId diff --git a/app/code/Ometria/Core/etc/module.xml b/app/code/Ometria/Core/etc/module.xml index d58700b..b20d1d1 100755 --- a/app/code/Ometria/Core/etc/module.xml +++ b/app/code/Ometria/Core/etc/module.xml @@ -1,4 +1,4 @@ - + diff --git a/composer.json b/composer.json index 9bf785d..7554d80 100755 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ometria/magento2", "type": "magento2-module", - "version": "2.5.1", + "version": "2.5.2", "description": "Dev composer package for Ometria Extension", "authors": [ {