Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8841601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:45:35+00:00 2026-06-14T10:45:35+00:00

I want to make a new select attribute option visible in all products. I

  • 0

I want to make a new select attribute option visible in all products.

I have products that each use a select box attribute called “bracket_size”. That attribute has three options:

bracket size options

(/admin/catalog_product_attribute/edit/)

Most of the products only have two of these options selected:

product attribute config

(/admin/catalog_product/edit/)

If I select “18mm” in that screen then it shows on the frontend.

I want to create an upgrade script that will set all products to show the “18mm” option.

I had been doing it by selecting all products, fetching them and updating their attribute value:

$options = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'bracket_size')->getSource()->getAllOptions(false);
$option18mmId = $options[0]['value'];

foreach (Mage::getModel('catalog/product')->getCollection() as $product) {
    // Get a writable product
    $product = Mage::getModel('catalog/product')->load($product->getId());

    // All products in these attribute sets should have bracket sizes
    $bracketSizeValue = $product->getBracketSize(); // string containing option IDs - something like '645,345'

    if (isset($bracketSizeValue)) {
        // Get options currently selected for this product
        $optionIds = explode(',', $bracketSizeValue);

        // Check if the option is already included in this product
        if (!in_array($option18mmId, $optionIds)) {
            // If not, rebuild the attribute value to add it
            array_unshift($optionIds, $option18mmId);

            // Add it back to the product
            $product->setData('bracket_size', implode(',', $optionIds));
            $product->save();
        }
    }
}

But this doesn’t work. It throws an error:

Warning: Invalid argument supplied for foreach()  in /.../public/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 1068

at the $product->save() line.

How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:45:37+00:00Added an answer on June 14, 2026 at 10:45 am

    If you trying to save products in setup/update script then you need to disable update mode and set current store id first:

    $app = Mage::app();
    $app->setUpdateMode(false);
    $app->setCurrentStore($app::ADMIN_STORE_ID);
    

    Ideally it would be done exactly before saving and then reverted back after saving:

    $app->setCurrentStore(null);
    $app->setUpdateMode(true);
    

    Then you could also optimise your code my removing loading and saving of each product and doing it on collection items instead.

    Loading of collection with desired attribute:

    $collection = Mage::getModel('catalog/product')->getCollection();
    $collection->addAttributeToSelect('bracket_code');
    

    Saving of changes on collection items:

    $collection->save();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to POSTGRES.I want to make a SELECT and list all the
I want to make a smart keyboard that can learn and save new words
I want to make a trigger that sets the joined attribute to the current
Im new to rails and I want to make a select query based on
I want to make new stackpanal from another stackpanal already made before but if
I don't want to make a new instance of Form1 in the class, and
I am new android app developer i want make app for tablets and phone
I want to make a function for a new datatype in Standard ML, the
I am new to .NET and ideally want to make several layers of abstraction
i'm new to gooogle map developing.i want to make a map as follows. http://edition.cnn.com/SPECIALS/world/arab-unrest/index.html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.