Magento – Add attribute programmatically

attributesmagento-1.9product-attribute

It code from */*/sql/*_setup/install-1.0.0.php

$installer = $this;

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();

$setup->addAttribute('catalog_product', 'product_label_attribute', array(
'group'         => 'Product labels',
'input'         => 'select',
'type'          => 'int',
'label'         => 'Labels',
'source'        => 'productlabels/source_labels',
'visible'       => true,
'visible_on_front' => true,
'required'      => false,
'user_defined'  => true,
'searchable'    => true,
'filterable'    => true,
'comparable'    => true,
'used_in_product_listing' => true,
'visible_on_front' => true,
'visible_in_advanced_search'  => true,
'is_html_allowed_on_front' => false,
'unique'        => false,
'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

Why when after create attriute i got

enter image description here
enter image description here

Why all attributes selected 'No'?

Best Answer

Try to use this code in your sql setup file

$installer = $this;
$installer->startSetup();
$installer->addAttribute("catalog_product", "product_label_attribute",  
    array(
    "type"     => "int",
    "backend"  => "",
    "frontend" => "",
    "label"    => "Labels",
    "input"    => "select",
    "class"    => "",
    "source"   => "productlabels/source_labels",
    "global"   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    "visible"  => true,
    "required" => false,
    "user_defined"  => true,
    "default" => "",
    "searchable" => true,
    "filterable" => true,
    "comparable" => true,
    "group"         => "Product labels",
    "visible_on_front"  => true,
    "used_in_product_listing" => true,
    "unique"     => false,
    "visible_in_advanced_search"  => true,
    "is_html_allowed_on_front"   => false,
    "note"       => ""
  ));
$installer->endSetup();