1

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?

0
0

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
$stockItem->setData('is_in_stock',0);       
$stockItem->save();
$product->save();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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