Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I add an option to attribute option set? 
 
alex2b
Member
 
Total Posts:  53
Joined:  2008-12-19
 

How do I add an option to attribute option set? Using SOAP api it’s only possible to fetch options for attribute, but I need to add options.

 
Magento Community Magento Community
Magento Community
Magento Community
 
retif
Sr. Member
 
Total Posts:  171
Joined:  2008-08-16
Odessa, Ukraine
 

option is a model also...so you need to create a model, set id of attribute, set value and save that model

 
Magento Community Magento Community
Magento Community
Magento Community
 
retif
Sr. Member
 
Total Posts:  171
Joined:  2008-08-16
Odessa, Ukraine
 

here are options and their values for different stores are stored

<attribute_option><table>eav_attribute_option</table></attribute_option>
<
attribute_option_value><table>eav_attribute_option_value</table></attribute_option_value>

$attribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
$attribute->load($id);
now you have
$opt = $attribute->getOption(); //array of attribute options as associative array of values

//when you saving attribute model
$attribute->save();
//this function executed also:
//protected function _saveOption(Mage_Core_Model_Abstract $object) in Mage_Eav_Model_Mysql4_Entity_Attribute 244
it creates/changes/deletes values of options

i attached the image with structure of options array

to save custom values you just need append this array with more elements, but following one simple rule:
new values have key in that array of string type(few letters which means nothing),
and already exist options you want to change has key as integer which is id of that value

$opt = array('value'=>array('new_opt1'=>array(0=>'val1 for first store',1=>'this value for second store')));
$attribute->setData('option',$opt);
$attribute->save();
this code creates new option of some attribute and saves it

the model for attribute option is not implemented

Image Attachments
img.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top