Get Qty Increments value by product SKU Magento 2.

Get Product Qty Increments value programmatically by product id or SKU in Magento.

Qty Increments Value will be set from the Admin Panel and used to add qty in multiply of that value. If you have set value equals 5, You must have to add multiple of 5 in qty field to add a product. (Allowed Value 5, 10, 15, 20, etc…)

Go To Catalog -> Products -> Add/Edit Product,
Click on Advanced Inventory,
Select Options as Yes from the Enable Qty Increments dropdown and a new input field will be visible.
Now, Set Qty Increments Value as per your choice.
Save Product. Continue reading “Get Qty Increments value by product SKU Magento 2.”

How to get stock status by SKU Magento 2?

Magento 2, You can get stock status by Product SKU. If you want to load Stock details using SKU, you can get the details of the Stock related information.

You need to use Magento\CatalogInventory\Model\StockRegistry to fetch stock status.

Using Stock Status Data, You can get the stock related info at the Website level, Stock is in stock, Backorder status, Qty, ProductId, Min. Qty, Manage Stock and many other stock field data.

<?php
namespace Jesadiya\StockStatus\Model;

use Psr\Log\LoggerInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\CatalogInventory\Model\StockRegistry;

class StockStatus
{
    /** @var LoggerInterface */
    protected $logger;

    /**
     * @var StoreManagerInterface
     */
    private $storeManager;

    /**
     * @var StockRegistry
     */
    private $stockRegistry;

    public function __construct(
        LoggerInterface $logger,
        StoreManagerInterface $storeManager,
        StockRegistry $stockRegistry,
    ) {
        $this->logger = $logger;
        $this->stockRegistry = $stockRegistry;
        $this->storeManager = $storeManager;
    }

    /**
     * country full name
     *
     * @return string
     */
    public function getStockStatus($sku)
    {
        $stockData = null;
        try {
            $stockStatus = $this->stockRegistry->getStockStatusBySku(
                $sku,
                $this->storeManager->getWebsite()->getId()
            );

            $stockData = $stockStatus->getStockItem();

        } catch (\Exception $exception) {
            $this->logger->error($exception->getMessage());
        }
        return $stockData;
    }
}

Get the stock status using SKU value as a method parameter,

$sku = '111A1234';
$stockData = $this->getStockStatus($sku);
var_dump($stockData->debug());

When you debug the Stock data you got all the required information of the Product Stock.

Get list of Inventory Stock in MSI Magento 2.

Inventory Stock in the Multi-Source (MSI) module are used for mapping a sales channel to source locations in Magento 2.

You can see a list of available Stocks from the Stores -> Inventory -> Stocks link. Continue reading “Get list of Inventory Stock in MSI Magento 2.”