I need to update the attribute value of all products (80.000+). How can I fix this using a script?

The attribute that should be updated is the following:

Attributecode: eboekhouden_grootboekrekening
Attributetype: dropdown
The value that should be selected: 8000 - Omzet Shop

Is the following code right?


ini_set('display_errors', 'On');

require('app/Mage.php'); // this is assuming your script is located in the Magento root dir
Mage::app(); // initiate the Magento engine

$products = Mage::getModel('catalog/product')->getCollection();

foreach($products as $product)
    $product->setEboekhoudenGrootboekrekening('8000 - Omzet Shop');
    // this line might not be required - compare results with & without it 
    $product->getResource()->saveAttribute($product, 'eboekhouden_grootboekrekening');
  • provide more information with example. Mar 28, 2017 at 10:44
  • @GopalPatel Thanks for your reply. What kind of information do you need?
    – JGeer
    Mar 28, 2017 at 10:45
  • What is currently in your system and what you want to achieve Mar 28, 2017 at 10:49
  • @GopalPatel Currently there is not a value selected in the dropdown. So I want to select the value 8000 - Omzet Shop from the dropdown and save it. I added my current code, what I currently have.
    – JGeer
    Mar 28, 2017 at 10:56

1 Answer 1


EDIT: actually I think the fact that it's a dropdown attribute will cause issues. You probably want to test that first on a single product to see how it behaves because I'm pretty sure the dropdown attribute values are option ids and not the text values.

Apart from that, your code is definitely correct, however it won't save the second attribute eboekhouden_grootboekrekening_is_formated

You'll need to add the following line if you want to save that attribute too:

$product->getResource()->saveAttribute($product, 'eboekhouden_grootboekrekening_is_formated');
  • Thanks a lot Raphael. I already removed the eboekhouden_grootboekrekening_is_formated part, that is not needed. But how do I need to edit the value for the dropdown? Do I need to change the text to the option id? So that it will become $product->setEboekhoudenGrootboekrekening('8000');
    – JGeer
    Mar 28, 2017 at 11:01
  • @HenkZ no I reckon you should use some code to find out what's the option id of this value. SOmething like this: magento.stackexchange.com/questions/17780/… Mar 28, 2017 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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