1

In one of the modules we are developing we require to create a multi-select attribute with several options. It's highly important that these options are given a certain order by default.

This is the current code for adding the attribute:

$installer->addAttribute('catalog_product', 'tariffplan_sms_slider', array(
 'attribute_set' => 'Randomattributeset',
 'group' => 'Sample',
 'type' => 'varchar',
 'default' => 0,
 'required' => false,
 'visible' => true,
 'backend' => 'eav/entity_attribute_backend_array',
 'frontend' => '',
 'label' => 'Random label',
 'note' => '',
 'input' => 'multiselect',
 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
 'option' => array ('value' => 
 array(
 'one' => array("Low"),
 'two' => array("Medium"),
 'three' => array('High'),
 'four' => array('Unlimited')
 )
 ),
 'visible' => true,
 'required' => false,
 'user_defined' => true,
 'default' => 0,
 'visible_on_front' => false,
 'used_in_product_listing' => false,
 'unique' => false
));

As you can see I'm giving an array of options for this attribute that will be created. On top of that I would like to set the order (see Position input fields in the backend) of each option.

I have tried the following below but it isn't working:

 'option' => array (
 'value' => array(
 'one' => array("Don't care"),
 'two' => array("Low"),
 'three' => array('High'),
 'four' => array('Unlimited')
 ),
 'order' => array(
 'one' => 0,
 'two' => 1,
 'three' => 2,
 'four' => 3
 )
 ),

Version: Magento ver. 1.7.0.1

Anyone got an idea?

dotancohen
1,1306 silver badges21 bronze badges
asked Feb 19, 2013 at 13:36
3
  • 1
    You can change this a little bit, add a source-model, then you can implement it to your own wishes :-) Commented Feb 19, 2013 at 13:44
  • btw, what is the order? Or what is the exact problem? :) Commented Feb 19, 2013 at 14:13
  • Fixed it already ;) Gotta love learning from the core ;) Commented Feb 19, 2013 at 14:17

1 Answer 1

3

Fixed it myself by looking at the addAttributeOption() method inside Mage_Eav_Model_Entity_Setup:

Result:

$installer->addAttribute('catalog_product', 'tariffplan_sms_slider', array(
 'attribute_set' => 'Randomattributeset',
 'group' => 'Sample',
 'type' => 'varchar',
 'default' => 0,
 'required' => false,
 'visible' => true,
 'backend' => 'eav/entity_attribute_backend_array',
 'frontend' => '',
 'label' => 'Random label',
 'note' => '',
 'input' => 'multiselect',
 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
 'option' => array (
 'values' => array(
 '1' => 'Low',
 '2' => 'Medium',
 '3' => 'High',
 '4' => 'Unlimited'
 )
 ),
 'visible' => true,
 'required' => false,
 'user_defined' => true,
 'default' => 0,
 'visible_on_front' => false,
 'used_in_product_listing' => false,
 'unique' => false
));

For those that don't see it immediately you basically just needed to change the value you give to the "option" key from:

'option' => array ('value' => 
 array(
 'one' => array("Low"),
 'two' => array("Medium"),
 'three' => array('High'),
 'four' => array('Unlimited')
 )
 ),

TO (see how value changed ito into values):

'option' => array (
 'values' => array(
 '1' => 'Low',
 '2' => 'Medium',
 '3' => 'High',
 '4' => 'Unlimited'
 )
 ),
answered Feb 19, 2013 at 14:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.