New answers tagged

0

Please follow the following code to save the stock value. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->create('Magento\Catalog\Model\Product')->load(); $qty = 10; $product->setStockData( [ 'manage_stock' => '1', 'is_in_stock' => '1', 'qty' => $qty ] ); Thanks.


0

public function __construct( \Magento\InventoryApi\Api\StockRepositoryInterface $productStockRepository ) { $this->productStockRepository = $productStockRepository; } $productStock = $productStockRegistry->getStockItem($entity->getId()); $productStock = $productStockRepository->get($entity->getId()); $productStock->setIsInStock(true); $...


0

This works for me: public function __construct( \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry ) { $this->stockRegistry = $stockRegistry; parent::__construct(); } public function yourMethod() { $sku = 'XYZ'; $qty = 70; $stockItem = $this->stockRegistry->getStockItemBySku($sku); $stockItem->setQty($...


0

Product Attribute You can get product attribute with below code - $product = $this->getProduct(); $ressource = $product->getResource(); $store = $this->_storeManager->getStore(); $ressource->getAttributeRawValue($product->getId(),'attribute_code',$store->getId()); Product Availability public function __construct( \Magento\...


Top 50 recent answers are included