Let's assume you have an array like this with the sku and prices.
$prices = array(
'sku1' => '12.99',
'sku2' => '15.00',
....
);
and you only need to change the price for store view 2.
Here is a fast way to do it.
Since the price can be global or has the website scope, you will also need to change the price for all the store views in the same website as the store view with id 2. The next script will do that for you, just make sure that prior to running it, you set the price scope to 'website'.
$storeId = 2;
$idsByPrice = array();
foreach ($prices as $sku=>$price) {
$id = Mage::getSingleton('catalog/product')->getIdBySku($sku);
if ($id) { //if the product exists
if (!isset($idsByPrice[$price])) {
$idsByPrice[$price] = array();
}
//group all skus by price so you will have less updates.
$idsByPrice[$price][] = $id;
}
}
//now you have an array of product ids grouped by price
//$idsByPrice = array(
// '12.99' => array(2,3,7,12),
// '15.00' => array(9,44,22),...
//)
foreach ($idsByPrice as $price=>$ids) {
Mage::getSingleton('catalog/product_action')->updateAttributes(
$ids, //ids to update
array('price'=>$price), //attributes to update
$storeId //store view to update the attribtues
);
}
Include Mage.php
at the top of the script and run it. back up your db first, just in case. And your indexes may need rebuilding when you are done.
You usually would do something like that with an observer on catalog_product_prepare_save
, this event is triggered in Mage_Adminhtml_Catalog_ProductController::_initProductSave()
.
But you cannot set prices per store, prices can only be set per website. Changing the allowed scope of the price attributes would require significant changes in the core, especially the price index. So if you need different prices on different sites, create separate websites, not only separate stores.
Best Answer
If you want to use SQL approach, You can use the following standalone script which can be run either via Web or CLI
And the sample CSV can be used as:
Source: http://bit.ly/M2-Bulk-Price-Update