Magento – Adding Attributes from Extension Solved

attribute-setPHP

i am trying to insert some attributes (drop-down) into the magento. The creation of the attribute with option is completed successfully. I also create an attribute set based on that attribute successfully.
The problem is that when i add a product based on that attribute set the product is not visible on the website.

Here is my configuration for the dropdown attribute:

    $data = array(
                    'is_global'                     => '1',
                    'frontend_input'                => 'select',
                    'default_value_text'            => '',
                    'default_value_yesno'           => '0',
                    'default_value_date'            => '',
                    'default_value_textarea'        => '',
                    'is_unique'                     => '0',
                    'is_required'                   => '1',
                    'frontend_class'                => '',
                    'is_searchable'                 => '0',
                    'is_visible_in_advanced_search' => '0',
                    'is_comparable'                 => '0',
                    'is_used_for_promo_rules'       => '0',
                    'is_html_allowed_on_front'      => '1',
                    'is_visible_on_front'           => '0',
                    'used_in_product_listing'       => '0',
                    'used_for_sort_by'              => '0',
                    'is_configurable'               => '1',
                    'is_filterable'                 => '0',
                    'is_filterable_in_search'       => '0',
                    'backend_type'                  => 'varchar',
                    'default_value'                 => '',
                    'option'                        => ''
                );

i 've changed the above array to this one:

    $data = array(

                    'is_global'                     => true,
                    'frontend_input'                => 'select',
                    'is_required'                   => true,
                    'visible'                       => true,
                    'is_html_allowed_on_front'      => true,
                    'is_visible_on_front'           => true,
                    'is_configurable'               => true,
                    'is_filterable'                 => true,
                    'backend_type'                  => 'varchar',
                    'apply_to'                      => array('simple'),
                    'default_value'                 => '',
                    'position'                      => 1,
                    'visible_on_front'              => true,
                    'option'                        => ''
                );

but i still have the same problem. i think that i am missing something here.

Best Answer

Here is what I used recently in my project and successfully created it programatically. I see that your apply_to is using array, though I think you don't need array and can pass multiple product types comma-separated.

$model = Mage::getResourceModel('catalog/setup','catalog_setup');

$data=array(
'type'=>'int',
'input'=>'boolean', //for Yes/No dropdown
'sort_order'=>50,
'label'=>'CUSTOM ATTRIBUTE CODE LABEL',
'global'=>Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'required'=>'0',
'comparable'=>'0',
'searchable'=>'0',
'is_configurable'=>'1',
'user_defined'=>'1',
'visible_on_front' => 0, //want to show on frontend?
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'required'=> 0,
'unique'=>false,
'apply_to' => 'configurable', //simple,configurable,bundled,grouped,virtual,downloadable
'is_configurable' => false
);

$model->addAttribute('catalog_product','CUSTOM_ATTRIBUTE_CODE',$data);

$model->addAttributeToSet(
    'catalog_product', 'Default', 'General', 'CUSTOM_ATTRIBUTE_CODE'
); //Default = attribute set, General = attribute group
Related Topic