Save select attribute options magento

This tutorial explains how to create custom attribute and save select attribute options in magento. This module create the custom dropdown attribute and adds the options automatically.

In the previous tutorial I have explained how to create custom product dropdown attribute using the install script. Please check the above link for the file structure and step by step explanation.

Here I am creating custom select attribute ‘Burn Time’ and add options to it using install script. The script creates the attribute ‘Burn Time’ as shown below.

Save select attribute options magento

The code below creates the attribute ‘Burn Time’ with four options. Please refer this link for the file structure.

$this->addAttribute(catalog_product, 'product_burntime', array(
    'group'         => 'General',
    'type'          => 'text',
    'input'         => 'select',
    'label'         => 'Burn Time',
    'backend'       => '',
    'visible'       => true,
    'required'      => false,
    'visible_on_front' => true,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'source' => 'eav/entity_attribute_source_table',
    'option' => array(
        'values'=> array(
            1 => 'Large - upto 120 hrs burn time, Silver Lid',
            2 => 'Medium - upto 60 hrs burn time, Silver Lid',
            3 => 'Travel Candle - upto 20 hrs burn time',
            4 => 'Pail Candle - upto 30 hrs burn time'

Attibute options Table

The above code adds the option to the eav_attribute_option_value table as shown below.
If you do not want to add the option to the database please refer this tutorial.You can get the options dynamically from the model.

Share this Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *