I am using module setup script to add new attributes group, attribute set and attributes. I am able to create attribute set, attribute group and add products to group/set. But I am having hard time setting is_filterable, is_visible, is_visible_on_front and is_html_allowed_on_front parameters.
$installer->addAttribute('catalog_product', 'offer_type', array(
'backend' => '',
'frontend' => '',
'class' => '',
'default' => '',
'label' => 'Offer type',
'input' => 'text',
'type' => 'int',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => 1,
'required' => 1,
'searchable' => 0,
'filterable' => 1,
'unique' => 0,
'comparable' => 0,
'visible_on_front' => 1,
'is_html_allowed_on_front' => 1,
'user_defined' => 1,
));
$installer->addAttributeToSet('catalog_product', $sSetId, $groupName, 'offer_type');
I see offer_type getting added to Magento and to attribute set($sSetID) and to group ($groupname). Though when I look at attribute from magento admin UI (Catalog->attributes->Manage Attributes), I see is_filterable, is_visible, is_visible_on_front and is_html_allowed_on_front parameters set to No. I have tried various combinations but no luck. I'm using Magento CE 1.7.0.2. I am not sure what is missing in my setup script. I have reffered http://blog.chapagain.com.np/magento-adding-attribute-from-mysql-setup-file/ for this. Am I missing anything? Thanks in advance.
Use
'visible_on_front' => 1
, inaddAttribute
call.Do you have properly configured your installer in your config.xml ? The standard class for magento installers is
Mage_Eav_Model_Entity_Setup
but when dealing with products, you'll need to useMage_Catalog_Model_Resource_Setup
instead. Why ? look at their method_prepareValues()
and you'll understand what are the authorised attributes (products have more options than the standard eav_objects, you can see that when comparing the tableseav_attribute
andcatalog_eav_attribute
)To point to the good installer class, take a look at the standard
Mage_Catalog
config.xml
and adapt it for your module :ps: note that the
_prepareValues()
method is called only when adding an attribute... if you want to update an attribute you'll need to use the full option name ("is_visible" and not just "visible")...Another hack would be to add these attributes afterward, but it's not very beautiful: