Skip to content

Commit

Permalink
Merge pull request #31 from denisprotassoff/issue-5312
Browse files Browse the repository at this point in the history
5312 Fixed backorders
  • Loading branch information
AleksandrsKondratjevs authored Nov 23, 2022
2 parents 3db8dea + e452dca commit 304fd8d
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/Model/Resolver/Products/DataPostProcessor/Stocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -227,29 +227,25 @@ public function process(
continue;
}

$inStock = $qty > 0;
$stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
$minQty = $stockItemConfiguration->getMinQty();
$isUnlimitedBackorders = $stockItemConfiguration->getBackorders()
!== StockItemConfigurationInterface::BACKORDERS_NO
&& $minQty >= 0;

if ($inStock) {
if ($inStock && !$isUnlimitedBackorders) {
$productSalableQty = $this->getProductSalableQty->execute($sku, $stockId);

if ($productSalableQty > 0) {
$stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);
$minQty = $stockItemConfiguration->getMinQty();
if ($productSalableQty > 0 && $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])
Expand Down

0 comments on commit 304fd8d

Please sign in to comment.