Skip to main content
edited
Source Link
Prasanta Hatui
  • 1.8k
  • 1
  • 10
  • 16

If you see the method declaration in StockRegistryInterface.php

/**
 * @param string $productSku
 * @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
 * @return int
 * @throws \Magento\Framework\Exception\NoSuchEntityException
 */
public function updateStockItemBySku($productSku, \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem);

With help of this itemId magento instantiates the object of

 \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem

then passing this object as parameter in updateStockItemBySku() method.

If we provide wrong ItemId, the inventory will be updated it default website only. If we look at the method updateStockItemBySku() in Magento\CatalogInventory\Model\StockRegistry, the code

$websiteId = $stockItem->getWebsiteId() ?: null;

So, itemId make significance to define the scope of website to update inventory.

If you see the method declaration in StockRegistryInterface.php

/**
 * @param string $productSku
 * @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
 * @return int
 * @throws \Magento\Framework\Exception\NoSuchEntityException
 */
public function updateStockItemBySku($productSku, \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem);

With help of this itemId magento instantiates the object of

 \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem

then passing this object as parameter in updateStockItemBySku() method.

If you see the method declaration in StockRegistryInterface.php

/**
 * @param string $productSku
 * @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
 * @return int
 * @throws \Magento\Framework\Exception\NoSuchEntityException
 */
public function updateStockItemBySku($productSku, \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem);

With help of this itemId magento instantiates the object of

 \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem

then passing this object as parameter in updateStockItemBySku() method.

If we provide wrong ItemId, the inventory will be updated it default website only. If we look at the method updateStockItemBySku() in Magento\CatalogInventory\Model\StockRegistry, the code

$websiteId = $stockItem->getWebsiteId() ?: null;

So, itemId make significance to define the scope of website to update inventory.

Source Link
Prasanta Hatui
  • 1.8k
  • 1
  • 10
  • 16

If you see the method declaration in StockRegistryInterface.php

/**
 * @param string $productSku
 * @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
 * @return int
 * @throws \Magento\Framework\Exception\NoSuchEntityException
 */
public function updateStockItemBySku($productSku, \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem);

With help of this itemId magento instantiates the object of

 \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem

then passing this object as parameter in updateStockItemBySku() method.