From e17cf2060699f1d65ce2c2e0fdeb8a17e25f05e8 Mon Sep 17 00:00:00 2001 From: Denis Protassoff Date: Tue, 22 Nov 2022 15:50:55 +0300 Subject: [PATCH 1/4] 5312 Fixed backorders --- src/Model/Resolver/Products/DataPostProcessor/Stocks.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Model/Resolver/Products/DataPostProcessor/Stocks.php b/src/Model/Resolver/Products/DataPostProcessor/Stocks.php index 749d4a5..4bb286f 100644 --- a/src/Model/Resolver/Products/DataPostProcessor/Stocks.php +++ b/src/Model/Resolver/Products/DataPostProcessor/Stocks.php @@ -227,8 +227,6 @@ public function process( continue; } - $inStock = $qty > 0; - if ($inStock) { $productSalableQty = $this->getProductSalableQty->execute($sku, $stockId); From 165ebc6175b577fe9e7cffb4bff36aeb6c362181 Mon Sep 17 00:00:00 2001 From: Denis Protassoff Date: Tue, 22 Nov 2022 17:57:57 +0300 Subject: [PATCH 2/4] 5312 Added support for unlimited backorders --- .../Products/DataPostProcessor/Stocks.php | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Model/Resolver/Products/DataPostProcessor/Stocks.php b/src/Model/Resolver/Products/DataPostProcessor/Stocks.php index 4bb286f..4955136 100644 --- a/src/Model/Resolver/Products/DataPostProcessor/Stocks.php +++ b/src/Model/Resolver/Products/DataPostProcessor/Stocks.php @@ -22,6 +22,7 @@ use Magento\InventoryApi\Api\GetStockSourceLinksInterface; use Magento\InventoryApi\Api\Data\StockSourceLinkInterface; use Magento\InventoryCatalog\Model\GetStockIdForCurrentWebsite; +use Magento\InventoryConfigurationApi\Api\Data\StockItemConfigurationInterface; use Magento\InventorySalesApi\Api\GetProductSalableQtyInterface; use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface; @@ -212,7 +213,6 @@ public function process( foreach ($stockItems as $stockItem) { $leftInStock = null; $productSalableQty = null; - $qty = $stockItem->getQuantity(); $sku = $stockItem->getSku(); $inStock = $stockItem->getStatus() === SourceItemInterface::STATUS_IN_STOCK; @@ -227,27 +227,25 @@ public function process( continue; } - if ($inStock) { - $productSalableQty = $this->getProductSalableQty->execute($sku, $stockId); + $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId); + $minQty = $stockItemConfiguration->getMinQty(); + $isUnlimitedBackorders = $stockItemConfiguration->getBackorders() + !== StockItemConfigurationInterface::BACKORDERS_NO + && $minQty >= 0; - if ($productSalableQty > 0) { - $stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId); - $minQty = $stockItemConfiguration->getMinQty(); + if ($inStock && !$isUnlimitedBackorders) { + $productSalableQty = $this->getProductSalableQty->execute($sku, $stockId); - if ($productSalableQty >= $minQty) { - $stockLeft = $productSalableQty - $minQty; - $thresholdQty = $stockItemConfiguration->getStockThresholdQty(); + if ($productSalableQty >= $minQty) { + $stockLeft = $productSalableQty - $minQty; + $thresholdQty = $stockItemConfiguration->getStockThresholdQty(); - if ($thresholdQty != 0) { - $leftInStock = $stockLeft <= $thresholdQty ? (float)$stockLeft : null; - } - } else { - $inStock = false; + if ($thresholdQty != 0) { + $leftInStock = $stockLeft <= $thresholdQty ? (float)$stockLeft : null; } } else { $inStock = false; } - } if (isset($formattedStocks[$sku]) From 6c61c8653a672ff55b2399065d0fe048fa6efed0 Mon Sep 17 00:00:00 2001 From: Denis Protassoff Date: Tue, 22 Nov 2022 18:05:55 +0300 Subject: [PATCH 3/4] 5312 Fixed in_stock condition --- src/Model/Resolver/Products/DataPostProcessor/Stocks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Resolver/Products/DataPostProcessor/Stocks.php b/src/Model/Resolver/Products/DataPostProcessor/Stocks.php index 4955136..dec6194 100644 --- a/src/Model/Resolver/Products/DataPostProcessor/Stocks.php +++ b/src/Model/Resolver/Products/DataPostProcessor/Stocks.php @@ -236,7 +236,7 @@ public function process( if ($inStock && !$isUnlimitedBackorders) { $productSalableQty = $this->getProductSalableQty->execute($sku, $stockId); - if ($productSalableQty >= $minQty) { + if ($productSalableQty > 0 && $productSalableQty >= $minQty) { $stockLeft = $productSalableQty - $minQty; $thresholdQty = $stockItemConfiguration->getStockThresholdQty(); @@ -285,4 +285,4 @@ public function process( } }; } -} +} \ No newline at end of file From e452dcac8edbbccfd9c8dd8663d72337564ffcbe Mon Sep 17 00:00:00 2001 From: Denis Protassoff Date: Tue, 22 Nov 2022 18:07:51 +0300 Subject: [PATCH 4/4] 5312 Added newline --- src/Model/Resolver/Products/DataPostProcessor/Stocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Resolver/Products/DataPostProcessor/Stocks.php b/src/Model/Resolver/Products/DataPostProcessor/Stocks.php index dec6194..f4ee85c 100644 --- a/src/Model/Resolver/Products/DataPostProcessor/Stocks.php +++ b/src/Model/Resolver/Products/DataPostProcessor/Stocks.php @@ -285,4 +285,4 @@ public function process( } }; } -} \ No newline at end of file +}