I need to change product as out of stock without changing its Quantity. I mean if a product having quantity 5, It will be same but product would be changed to OUT OF STOCK. Is it possible in magento?


1 Answer 1


Try with this

public function __construct(
    \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
    \Magento\Catalog\Model\Product $product,
) {
    $this->_stockRegistry = $stockRegistry;
    $this->_product = $product;

And after

$product=$this->_product->load($productId); //load product which you want to update stock
$stockItem=$this->_stockRegistry->getStockItem($item['product_id']); // load stock of that product

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.