I have 3 websites, each with one store and one store view.
I have all products' collections based on store in hand, i'm doing a price change for each product using the magento' API within a script, but to do that i need to use the price stored at "all store views" scope to a calculation.
I get all products collection from each store with below function:
protected function getProductCollectionByStoreId($storeId)
{
$productCollection = $this->objectManager
->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollection->create()
->addAttributeToSelect('*')
->addStoreFilter($storeId)
->load();
return $collection;
}
And then I update the prices for each collection of products based on store:
protected function setProductPricesBasedOnStoreWithoutRest($stores){
foreach($stores as $storeData){
$storeId = $storeData[0];
$storeCode = $storeData[1];
$multiplier = $storeData[3];
$currencyRate = $storeData[4];
$productCollection = $this->getProductCollectionByStoreId($storeId);
foreach($productCollection as $product){
// ...
$price = $product->getPrice();
$newPrice = round(ceil(($price * $multiplier) / $currencyRate), 2);
// ...
}
}
}
$price
needs to get the value stored in "all store views" price (showed in the image) and not the price in the product' storeview scope. What's the easyest way to get that value?