/** * {@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('.'); } }
/** * 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; }