I am doing a small external script site for my magento to get informations and do small tasks without navigationg through the magento backend (eg. show qty of all products). What I want to do now is list a specified attribute value for all products and change it (so I don't have to go to all products and change it by hand). Everything seems to work fine but when saving the new attribute value it updates the attribute on ALL Products. Via Ajax I pass an array (sku,attr_key,attr_value). Here my code:
public function newAttributesBySku($data){
$products = Mage::getModel('catalog/product');
$errors = array();
foreach ($data as $array) {
$product = $products->loadByAttribute('sku',$array['sku']);
$save = $product->setData($array['attr_key'], $array['attr_array'])->getResource()->saveAttribute($product, $array['attr_key']);
if(!$save) $errors[] = $save;
}
}
I also tried with
$product->setData($array['attr_key'],$array['attr_value'])->save();
Which has the same effect. The attribute value gets saved, but now every product has the new value in the specified attribute.
Can anyone explain to me what I am doing wrong? Thanks alot!