I want to display Magento product qty in the popup. when the customer clicks on add to cart button the popup shows the product available in stock and if the product is not available popup displays the product not available in stock.
1 Answer
First, you have to get stockItem with product id. So you have to add the getStockItem function in Helper.
public function __construct(...
\Magento\CatalogInventory\Api\StockRegistryInterface $stockItemRepository,
...){
...
$this->stockItemRepository = $stockItemRepository;
...
}
public function getStockItem($productId)
{
return $this->stockItemRepository->getStockItem($productId);
}
And get the Qty with product Id.
$qty = $yourHelper->getStockItem($_product->getId())->getQty();
OK
andCancel
? Or just a popup message on the top right corner? Should the customer see the exact available QTY or just info if product is available? What about products with Backorders or not managable by Stocks (if You have any in the shop). What if a product has multiple Stock Managements / Werhauses? Do You have implemented anything so far and you are stuck? Or just want the whole solution?^^ Yo can always look for extension to install$product->isSaleable()
method as default. But I guess You will need to include some specific project logic and we wont help You with that, cause noone knows that here ;)