Skip to content

Commit 5f265a6

Browse files
committed
Add compatibility for core inventory API inconsistency across Magento versions.
1 parent e239171 commit 5f265a6

File tree

6 files changed

+41
-16
lines changed

6 files changed

+41
-16
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Ometria_AbandonedCarts" setup_version="2.5.1"/>
3+
<module name="Ometria_AbandonedCarts" setup_version="2.5.2"/>
44
</config>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Ometria_Api" setup_version="2.5.1"/>
3+
<module name="Ometria_Api" setup_version="2.5.2"/>
44
</config>

app/code/Ometria/Core/Plugin/OrderManagementPlugin.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,33 @@ private function sendPushNotifications(OrderInterface $order)
6868
}
6969

7070
foreach ($order->getItems() as $orderItem) {
71+
if ($orderItem->getHasChildren() == true) {
72+
// Skip parent items (configurable product parents etc)
73+
continue;
74+
}
75+
7176
// Retrieve the salable qty of the product based on configured scope
7277
$salableQty = $this->getSalableQty(
7378
$orderItem->getProduct(),
7479
$stockPushScope
7580
);
7681

77-
// if salable qty is set and not already 0, check if push is required (null infers manage stock is disabled)
78-
if ($salableQty !== null && $salableQty > 0) {
79-
// Calculate new salabale quantity (after order placement)
80-
$salableQtyAfterOrder = $salableQty - $orderItem->getQtyOrdered();
81-
if ($salableQtyAfterOrder <= 0) {
82-
$stockData = $this->inventoryService->getPushApiStockData(
83-
(int)$orderItem->getProductId(),
84-
false
85-
);
86-
87-
$this->pushApiService->pushRequest($stockData);
88-
}
82+
if ($this->inventoryService->isReservationsAfter()) {
83+
/*
84+
* Adjust salable qty to compensate for a core API inconsistency across Magento versions
85+
* which affects the salable quantity calculation based on the order in which reservations are deducted.
86+
*/
87+
$salableQty = $salableQty - $orderItem->getQtyOrdered();
88+
}
89+
90+
// if salable qty is set, check if push is required for zero stock (null implies manage stock is disabled)
91+
if ($salableQty !== null && $salableQty <= 0) {
92+
$stockData = $this->inventoryService->getPushApiStockData(
93+
(int)$orderItem->getProductId(),
94+
false
95+
);
96+
97+
$this->pushApiService->pushRequest($stockData);
8998
}
9099
}
91100
}

app/code/Ometria/Core/Service/Product/Inventory.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Module\Manager as ModuleManager;
1414
use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface;
1515
use Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException;
16+
use Magento\InventorySales\Plugin\Sales\OrderManagement\AppendReservationsAfterOrderPlacementPlugin;
1617
use Magento\InventorySalesAdminUi\Model\ResourceModel\GetAssignedStockIdsBySku;
1718
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
1819
use Magento\InventorySalesApi\Api\GetProductSalableQtyInterface;
@@ -132,6 +133,21 @@ public function addLegacyStockFilterToCollection(ProductCollection $collection)
132133
}
133134
}
134135

136+
/**
137+
* This function checks which implementation exists in the AppendReservations plugin to determine
138+
* whether the salable qty of a product will reflect the ordered amount inclusive of reservation or not.
139+
*
140+
* As of magento/[email protected] the afterPlace() function was replaced with an aroundPlace()
141+
* function, resulting in the reservations being applied before the order placement (despite the plugin
142+
* being named "AfterOrderPlacement").
143+
*
144+
* @return bool
145+
*/
146+
public function isReservationsAfter()
147+
{
148+
return method_exists(AppendReservationsAfterOrderPlacementPlugin::class, 'afterPlace');
149+
}
150+
135151
/**
136152
* @param ProductInterface $product
137153
* @param $stockId
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Ometria_Core" setup_version="2.5.1"/>
3+
<module name="Ometria_Core" setup_version="2.5.2"/>
44
</config>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ometria/magento2",
33
"type": "magento2-module",
4-
"version": "2.5.1",
4+
"version": "2.5.2",
55
"description": "Dev composer package for Ometria Extension",
66
"authors": [
77
{

0 commit comments

Comments
 (0)