Magento – Custom Product Attribute with select option

attributesmagento-1.9

I have a non-Eav table. And I want to create a custom product attribute with select options whose values will be coming from the above non-eav table column. What will be the code for the sql script.
Assume the column name is brand.

<?php

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$setup->addAttribute('catalog_product', 'brand', array(
    'group' => 'General Information',
    'input' => 'select',
    'type' => 'varchar',
    'label' => 'Brand',
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE ,
));

Best Answer

Use below code:

$setup->addAttribute('catalog_product', "brand", array(
    'type'       => 'int',
    'input'      => 'select',
    'label'      => 'Select brand',
    'sort_order' => 1000,
    'required'   => false,
    'global'     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'backend'    => 'eav/entity_attribute_backend_array',
    'option'     => array (
        'values' => array(
            0 => 'Brand 1',
            1 => 'Brand 2',
            2 => 'Brand 3',
        )
    ),

));
Related Topic