本文整理汇总了PHP中Magento\CatalogInventory\Api\StockRegistryInterface::updateStockItemBySku方法的典型用法代码示例。如果您正苦于以下问题:PHP StockRegistryInterface::updateStockItemBySku方法的具体用法?PHP StockRegistryInterface::updateStockItemBySku怎么用?PHP StockRegistryInterface::updateStockItemBySku使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\CatalogInventory\Api\StockRegistryInterface
的用法示例。
在下文中一共展示了StockRegistryInterface::updateStockItemBySku方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: aroundSave
/**
* @param \Magento\Catalog\Api\ProductRepositoryInterface $subject
* @param callable $proceed
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @param bool $saveOptions
* @return \Magento\Catalog\Api\Data\ProductInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function aroundSave(\Magento\Catalog\Api\ProductRepositoryInterface $subject, \Closure $proceed, \Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false)
{
/** @var \Magento\Catalog\Api\Data\ProductInterface $result */
$result = $proceed($product, $saveOptions);
/* @var \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem */
$stockItem = $this->getStockItemToBeUpdated($product);
if ($stockItem == null) {
return $result;
}
// set fields that the customer should not care about
$stockItem->setProductId($result->getId());
$stockItem->setWebsiteId($this->storeManager->getStore($result->getStoreId())->getWebsiteId());
$this->stockRegistry->updateStockItemBySku($result->getSku(), $stockItem);
// since we just saved a portion of the product, force a reload of it before returning it
return $subject->get($result->getSku(), false, $result->getStoreId(), true);
}
示例2: testUpdateStockItemBySku
public function testUpdateStockItemBySku()
{
$itemId = 1;
$this->stockItem->expects($this->once())->method('setProductId')->willReturnSelf();
$this->stockItem->expects($this->once())->method('getData')->willReturn([]);
$this->stockItem->expects($this->once())->method('addData')->willReturnSelf();
$this->stockItem->expects($this->atLeastOnce())->method('getItemId')->willReturn($itemId);
$this->assertEquals($itemId, $this->stockRegistry->updateStockItemBySku($this->productSku, $this->stockItem));
}