本文整理汇总了PHP中Magento\CatalogInventory\Api\StockRegistryInterface::getStockStatus方法的典型用法代码示例。如果您正苦于以下问题:PHP StockRegistryInterface::getStockStatus方法的具体用法?PHP StockRegistryInterface::getStockStatus怎么用?PHP StockRegistryInterface::getStockStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\CatalogInventory\Api\StockRegistryInterface
的用法示例。
在下文中一共展示了StockRegistryInterface::getStockStatus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addStockStatusToProducts
/**
* Add stock status information to products
*
* @param \Magento\Catalog\Model\Resource\Collection\AbstractCollection $productCollection
* @return void
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function addStockStatusToProducts(\Magento\Catalog\Model\Resource\Collection\AbstractCollection $productCollection)
{
$websiteId = $this->storeManager->getStore($productCollection->getStoreId())->getWebsiteId();
$productIds = [];
foreach ($productCollection as $product) {
$productId = $product->getId();
$stockStatus = $this->stockRegistry->getStockStatus($productId, $websiteId);
$status = $stockStatus->getStockStatus();
$product->setIsSalable($status);
}
}
示例2: getProductStockQty
/**
* Retrieve product stock qty
*
* @param Product $product
* @return float
*/
public function getProductStockQty($product)
{
return $this->stockRegistry->getStockStatus($product->getId(), $product->getStore()->getWebsiteId())->getQty();
}
示例3: testGetStockStatusBySku
public function testGetStockStatusBySku()
{
$this->assertEquals($this->stockStatus, $this->stockRegistry->getStockStatus($this->productId, $this->websiteId));
}