Adding a new attribute option

Last modified by Bojan Hrnkas on Fri, June 25, 2010 09:16
Source|Old Revisions  

If you want to add a new option to an existing attribute using backend, here’s how you can do it:

// initialize magento environment for 'default' store
require_once 'app/Mage.php';
Mage::app('default');

//add new manufacturer
$option['attribute_id'] = 102; //manufacturer
$option['value']['any_key_that_resolves_to_zero'][0] = 'Mitsubishi';
$option['value']['other_key_that_resolves_to_zero'][0] = 'Volkswagen';

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttributeOption($option);

Key for the second dimension of the $option array has to evaluate to zero when casted to integer. You can just put 0, or in case you have multiple options you want to add at once, use string that doesn’t start with a number (i.e. ‘option1’, ‘option2’,... ). Third dimension is for different stores, where 0 is default and must be set. You can use other keys to set different value for different stores.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs