Last active
August 29, 2015 14:01
-
-
Save uabassguy/e61f474d5e9749df5475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = fopen('csv/import.csv','r'); | |
$data = fgetcsv($file, null, ","); | |
$fields = $data; | |
$i = 0; | |
$j = 0; | |
while (($data = fgetcsv($file, 1000, ",")) !== FALSE) { | |
foreach($data as $value){ | |
$f = $fields[$i]; | |
$parsed[$j][$f] = $value; | |
$i++; | |
} | |
$j++; | |
$i = 0; | |
} | |
fclose($file); | |
//die(print_r($parsed)); | |
require_once '../app/Mage.php'; | |
Mage::app(); | |
$storeId = 1; | |
$idsByPrice = array(); | |
foreach ($parsed as $item) { | |
$id = Mage::getSingleton('catalog/product')->getIdBySku($item['sku']); | |
if ($id) { //if the product exists | |
$price = $item['price']; | |
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),... | |
//) | |
//die(print_r($idsByPrice)); | |
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 | |
); | |
} |
Hello, are you able to set different prices at Store View Level (not Store Level)? I can do it at the Website Level, but the price also gets updated in ALL the Store Views of the same website. I ask because I noticed your comments at SO, and it seems to me that you were able to set the price at Store View Level.
This should do it at the store level you just need to set $storeId to match the desired store. 1 would be the default which affects all scopes which inherit it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup:
place file in shell/
create csv folder in shell,
place import.csv in csv folder.
set price scope in magento to 'website' in Configuration > Catalog > Catalog > Price
Based on SO answer: http://magento.stackexchange.com/questions/19322/update-price-attribute-and-save-attribute/19330?noredirect=1#19330