How can we create an attribute for product programatically in magento CE 1.9? I have been trying out multiple ways for creating an attribute for product that has a boolean value by default set to false and assigned to Default attribute set, but not visible/editable by any admin panel user.
my Model/Resource/Eav/Mysql4/Setup.php
<?php
class Mofosys_Quickbuy_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup {
protected function _prepareValues($attr) {
$data = parent::_prepareValues($attr);
$data = array_merge($data, array(
'apply_to' => $this->_getValue($attr, 'apply_to'),
'frontend_input_renderer' => $this->_getValue($attr, 'input_renderer'),
'is_comparable' => $this->_getValue($attr, 'comparable', 0),
'is_configurable' => $this->_getValue($attr, 'is_configurable', 0),
'is_filterable' => $this->_getValue($attr, 'filterable', 0),
'is_filterable_in_search' => $this->_getValue($attr, 'filterable_in_search', 0),
'is_global' => $this->_getValue(
$attr,
'global',
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
),
'is_html_allowed_on_front' => $this->_getValue($attr, 'is_html_allowed_on_front', 0),
'is_searchable' => $this->_getValue($attr, 'searchable', 0),
'is_used_for_promo_rules' => $this->_getValue($attr, 'used_for_promo_rules', 0),
'is_visible' => $this->_getValue($attr, 'visible', 0),
'is_visible_on_front' => $this->_getValue($attr, 'visible_on_front', 0),
'is_wysiwyg_enabled' => $this->_getValue($attr, 'wysiwyg_enabled', 0),
'is_visible_in_advanced_search' => $this->_getValue($attr, 'visible_in_advanced_search', 0),
'position' => $this->_getValue($attr, 'position', 0),
'used_for_sort_by' => $this->_getValue($attr, 'used_for_sort_by', 0),
'used_in_product_listing' => $this->_getValue($attr, 'used_in_product_listing', 0),
));
return $data;
}
}
?>
my etc/config.xml
<global>
<resources>
<mofosys_quickbuy_setup>
<setup>
<module>Mofosys_Quickbuy</module>
<class>Mofosys_Quickbuy_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
</mofosys_quickbuy_setup>
</resources>
</global>
my sql/mofosys_quickbuy_setup/install-0.0.1.php
<?php
// Installer file to create an attribute name "approved" inside Default attribute set
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
// the attribute added will be displayed under the group/tab Special Attributes in product edit page
$setup->addAttribute('catalog_product', 'approved', array(
'group' => 'Default',
'input' => 'select',
'type' => 'int',
'default' => '0',
'label' => 'Testing',
'backend' => '',
'visible' => 0,
'required' => 0,
'user_defined' => 0,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$installer->endSetup();
?>