Your shopping cart is empty. Browse our Store

Magento

Open Source eCommerce Evolved

Adding a new attribute option

Last modified by Bojan Hrnkas on Wed, May 14, 2008 11:52
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.




 

Popular Wiki Tags  |  View all

Professional Services from the Magento Team

Professional Installation from the Magento Team

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien