Skip to main content
Updated
Source Link
Suresh Chikani
  • 15.9k
  • 11
  • 63
  • 99

Can you please try below code for? It will save inventory data.

$stockData = $this->getTotalStock($productId);//Load product stock.
        $product=$this->_product->load($productId); //load product which you want to update stock
        $product->setStockData(['qty' => $stockData, 'is_in_stock' => $stockData]);
        $product->setQuantityAndStockStatus(['qty' => $stockData, 'is_in_stock' => $stockData]);
        $product->save();

Can you please try below code for save inventory data

$stockData = $this->getTotalStock($productId);//Load product stock.
        $product=$this->_product->load($productId); //load product which you want to update stock
        $product->setStockData(['qty' => $stockData, 'is_in_stock' => $stockData]);
        $product->setQuantityAndStockStatus(['qty' => $stockData, 'is_in_stock' => $stockData]);
        $product->save();

Can you please try below code? It will save inventory data.

$product->setStockData(['qty' => $stockData, 'is_in_stock' => $stockData]);
$product->setQuantityAndStockStatus(['qty' => $stockData, 'is_in_stock' => $stockData]);
$product->save();
Source Link
Suresh Chikani
  • 15.9k
  • 11
  • 63
  • 99

Can you please try below code for save inventory data

$stockData = $this->getTotalStock($productId);//Load product stock.
        $product=$this->_product->load($productId); //load product which you want to update stock
        $product->setStockData(['qty' => $stockData, 'is_in_stock' => $stockData]);
        $product->setQuantityAndStockStatus(['qty' => $stockData, 'is_in_stock' => $stockData]);
        $product->save();