Skip to content

Commit

Permalink
Added functionality to work with Salable Qty on mage 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
broopdias committed Jun 18, 2019
1 parent eb67938 commit ecfe1f6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Block/Product/View/Type/Configurable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Locale\Format;
use Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory;
use Magento\InventorySalesApi\Api\GetProductSalableQtyInterface;

/**
* Class Configurable
Expand Down Expand Up @@ -52,6 +53,10 @@ class Configurable extends SwatchConfigurable
* @var StockItemInterfaceFactory
*/
private $stockItemInterfaceFactory;
/**
* @var GetProductSalableQtyInterface
*/
private $getProductSalableQtyInterface;

/**
* @param Context $context
Expand All @@ -69,6 +74,7 @@ class Configurable extends SwatchConfigurable
* @param SwatchAttributesProvider $swatchAttributesProvider
* @param Format|null $localeFormat
* @param StockItemInterfaceFactory $stockItemInterfaceFactory
* @param GetProductSalableQtyInterface $getProductSalableQtyInterface
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -86,7 +92,8 @@ public function __construct(
array $data = [],
SwatchAttributesProvider $swatchAttributesProvider = null,
Format $localeFormat = null,
StockItemInterfaceFactory $stockItemInterfaceFactory
StockItemInterfaceFactory $stockItemInterfaceFactory,
GetProductSalableQtyInterface $getProductSalableQtyInterface
){
$this->swatchHelper = $swatchHelper;
$this->swatchMediaHelper = $swatchMediaHelper;
Expand All @@ -111,6 +118,7 @@ public function __construct(
);
$this->context = $context;
$this->stockItemInterfaceFactory = $stockItemInterfaceFactory;
$this->getProductSalableQtyInterface = $getProductSalableQtyInterface;
}

/**
Expand Down Expand Up @@ -146,9 +154,17 @@ public function getProductStock()

foreach ($allProducts as $product) {
if ($product->isSaleable() || $skipSaleableCheck) {
$stock[$product->getId()] = $this->getStockItem($product->getId());

//Check salable quantity
$salableQty = $this->getProductSalableQtyInterface->execute($product->getSku(), 1);
if ($salableQty >= 1) {
$stock[$product->getId()] = $this->getStockItem($product->getId());
} else {
$stock[$product->getId()]['out_stock'] = 1;
}
}
}

return $stock;
}

Expand Down Expand Up @@ -191,4 +207,4 @@ public function getAllowProducts()
return $this->getData('allow_products');
}

}
}

0 comments on commit ecfe1f6

Please sign in to comment.