5

When I create a dropdown attribute, Magento is always setting the "Use To Create Configurable Product" as Yes.

While in the install script I added in the options array to the Mage_Eav_Model_Entity_Setup::addAttribute() method:

"in_configurable" => false

This option is still not working.

Sample code to add an attribute from an install script:

$options = array(
    'type'                       => 'int',
    'label'                      => 'Color',
    'input'                      => 'select',
    'required'                   => false,
    'user_defined'               => true,
    'searchable'                 => true,
    'filterable'                 => true,
    'comparable'                 => true,
    'visible_in_advanced_search' => true,
    'is_configurable'            => false,
);
$this->addAttribute(
    Mage_Catalog_Model_Product::ENTITY,
    'size',
    $options
);

After I go into the Admin Panel and view the attribute data, the is_configurable attribute is set still set as Yes.

  • try like this format 'is_configurable' => '0' – DRAJI Oct 7 '14 at 12:44
  • @DRAJI does not work, same result. – Dan Oct 7 '14 at 12:50
2

You should actually use Mage_Catalog_Model_Resource_Setup::addAttribute()
instead of Mage_Eav_Model_Entity_Setup::addAttribute()

As you have found out in the code, Mage_Eav_Model_Entity_Setup::addAttribute() only allows the following options:

backend
type
table
frontend
input
label
frontend_class
source
required
user_defined
default
unique
note
global

Whereas Mage_Catalog_Model_Resource_Setup::addAttribute() allows all of the above, plus the following options:

input_renderer
global
visible
searchable
filterable
comparable
visible_on_front
wysiwyg_enabled
is_html_allowed_on_front
visible_in_advanced_search
filterable_in_search
used_in_product_listing
used_for_sort_by
apply_to
position
is_configurable
used_for_promo_rules

You can use this class even if you have defined another setup class in your config.xml:

$installer = $this;
$installer->startSetup();

// Create your tables, etc

$catalogInstaller = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$catalogInstaller->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'size', array(
    'type'                       => 'int',
    'label'                      => 'Color',
    'input'                      => 'select',
    'required'                   => false,
    'user_defined'               => true,
    'searchable'                 => true,
    'filterable'                 => true,
    'comparable'                 => true,
    'visible_in_advanced_search' => true,
    'is_configurable'            => false,
));

$installer->endSetup();
  • Thanks for this! Just a small improvement though, you can tell Magento to use the Mage_Catalog_Model_Resource_Setup class instead of the EAV one in the config.xml file of a module. This way, $this would be an instance of Mage_Catalog_Model_Resource_Setup, so you won't have to create a new instance of a resource setup in the update/install script. – Dan Apr 27 '17 at 19:42
  • @Dan Indeed, the "normal" way would be to specify <class>Mage_Catalog_Model_Resource_Setup</class> in the config.xml file. I used a different technique because I needed to add product attributes (Mage_Catalog_Model_Resource_Setup::addAttribute()) as well as order attributes (Mage_Sales_Model_Resource_Setup::addAttribute()) in the same install script. – user3409662 Apr 28 '17 at 12:37
5

If you go through the Mage_Eav_Model_Entity_Setup::addAttribute() method, you can find that the options are getting filtered in the Mage_Eav_Model_Entity_Setup::_prepareValues() method.

The _prepareValues method only allows the following options to go through:

'backend_model', 'backend_type', 'backend_table', 'frontend_model',
'frontend_input', 'frontend_label', 'frontend_class',
'source_model', 'is_required', 'is_user_defined', 'default_value',
'is_unique', 'note', 'is_global'

Any option that needs to be set, and is not in previous list, cannot be passed into the addAttribute method.

The only exception to those are: sort_order, group, user_defined and option. Those are used independently from the _prepareValues method.

One way to work around this issue, is to update the attribute after it is created, using the Mage_Eav_Model_Entity_Setup::updateAttribute() method.

$this->updateAttribute(
    Mage_Catalog_Model_Product::ENTITY,
    'size',
    'is_configurable',
    false
)

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.