本文整理汇总了PHP中Magento\Catalog\Model\Resource\Product\Collection::getItemById方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::getItemById方法的具体用法?PHP Collection::getItemById怎么用?PHP Collection::getItemById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Resource\Product\Collection
的用法示例。
在下文中一共展示了Collection::getItemById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* {@inheritdoc}
*/
public function run()
{
$this->logger->log('Installing MAP:');
$this->configWriter->save('sales/msrp/enabled', 1);
$fixtureFile = 'Msrp/products_msrp.csv';
$fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
/** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
$csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
foreach ($csvReader as $row) {
$productId = $this->getProductIdBySku($row['sku']);
if (!$productId) {
continue;
}
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->productCollection->getItemById($productId);
$product->setMsrpDisplayActualPriceType(\Magento\Msrp\Model\Product\Attribute\Source\Type::TYPE_ON_GESTURE);
if (!empty($row['msrp'])) {
$price = $row['msrp'];
} else {
$price = $product->getPrice() * 1.1;
}
$product->setMsrp($price);
$product->save();
$this->logger->logInline('.');
}
}
示例2: addStockStatusToProducts
/**
* Add information about stock status to product collection
*
* @param \Magento\Catalog\Model\Resource\Product\Collection $productCollection
* @param int|null $websiteId
* @param int|null $stockId
* @return $this
*/
public function addStockStatusToProducts($productCollection, $websiteId = null, $stockId = null)
{
if ($stockId === null) {
$stockId = Stock::DEFAULT_STOCK_ID;
}
if ($websiteId === null) {
$websiteId = $this->_storeManager->getStore()->getWebsiteId();
if ((int) $websiteId == 0 && $productCollection->getStoreId()) {
$websiteId = $this->_storeManager->getStore($productCollection->getStoreId())->getWebsiteId();
}
}
$productIds = array();
foreach ($productCollection as $product) {
$productIds[] = $product->getId();
}
if (!empty($productIds)) {
$stockStatuses = $this->getProductStockStatus($productIds, $websiteId, $stockId);
foreach ($stockStatuses as $productId => $status) {
if ($product = $productCollection->getItemById($productId)) {
$product->setIsSalable($status);
}
}
}
return $this;
}