0

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!

0

So, after a full day going almost nuts, I found the error was in my view. The data the view was getting was wrong and so it seemed that after save every product was updated, but it really all worked, I just saw a faulty view. Shame on me and next time I better make sure what I see is what is right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.