Skip to content

Getting the minimum qty allowed in a shopping cart without deprecated methods

Previously to get the minimum qty allowed in a shopping cart I would use the following code:

public function __construct(
    MagentoCatalogInventoryApiStockRegistryInterface $stockRegistry
){
    $this->stockRegistry = $stockRegistry;
}

public function getMinSaleQtyAllowed($productId): float
{
    $stockItem = $this->stockRegistry->getStockItem($productId);
    return $stockItem->getMinSaleQty();
}

However, MagentoCatalogInventoryApiStockRegistryInterface is now deprecated and I can not see how to get the minimum qty allowed without using it.

Please could someone advise?