1
votes

I have added this code in the installer in my custom magento module.

    $installer->addAttribute('catalog_product','size_guide',array(
    'group' => 'General',
    'type' =>  'tinyint',
    'label' => 'Enable Sizechart',
    'input' => 'boolean',
    'source' => 'eav/entity_attribute_source_table',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
    'user_defined' => true,
    'used_in_product_listing' => true,
    'default' => '',
    'unique' => false,enter code here
    'apply_to' => ''
    ));
    
After installing the module attribute "size_guide" is added but "Used in product listing" dropdown in attribute still set as no but as you seen in my code i have set the used in product listing true.

'used_in_product_listing' => true,

I appreciate your help.

Thanks in advance.

2

2 Answers

3
votes

Try using

$_installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
2
votes

When you look at the definition of this method in Mage_Eav_Model_Entity_Setup class you will the following code:

$data = array_merge(
        array(
            'entity_type_id' => $entityTypeId,
            'attribute_code' => $code
        ),
        $this->_prepareValues($attr)
     );

This code prepares data for attribute. In _prepareValues() method you can see that the returning array does not contain used_in_product_listing key. So even if you are providing it in your array it is not passed to the method. To resolve the issue you must declare your own resource setup model in config.xml

<resources>
  <company_module_setup>
    <setup>
      <module>Company_Module</module>
      <class>Company_Module_Model_Resource_Setup</class>
    </setup>
  </company_module_setup>
</resources>    

then create the class and override _prepareValues() method like this

class Company_Module_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup {

  protected function _prepareValues($attr) {
    $data = parent::_prepareValues($attr);
    $data = array_merge($data, array(
        'frontend_input_renderer'       => $this->_getValue($attr, 'input_renderer'),
        'is_global'                     => $this->_getValue(
            $attr,
            'global',
            Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
        ),
        'is_visible'                    => $this->_getValue($attr, 'visible', 1),
        'is_searchable'                 => $this->_getValue($attr, 'searchable', 0),
        'is_filterable'                 => $this->_getValue($attr, 'filterable', 0),
        'is_comparable'                 => $this->_getValue($attr, 'comparable', 0),
        'is_visible_on_front'           => $this->_getValue($attr, 'visible_on_front', 0),
        'is_wysiwyg_enabled'            => $this->_getValue($attr, 'wysiwyg_enabled', 0),
        'is_html_allowed_on_front'      => $this->_getValue($attr, 'is_html_allowed_on_front', 0),
        'is_visible_in_advanced_search' => $this->_getValue($attr, 'visible_in_advanced_search', 0),
        'is_filterable_in_search'       => $this->_getValue($attr, 'filterable_in_search', 0),
        'used_in_product_listing'       => $this->_getValue($attr, 'used_in_product_listing', 0),
        'used_for_sort_by'              => $this->_getValue($attr, 'used_for_sort_by', 0),
        'apply_to'                      => $this->_getValue($attr, 'apply_to'),
        'position'                      => $this->_getValue($attr, 'position', 0),
        'is_configurable'               => $this->_getValue($attr, 'is_configurable', 1),
        'is_used_for_promo_rules'       => $this->_getValue($attr, 'used_for_promo_rules', 0)
    ));
    return $data;
  }

}

It will allow you to add the rest of the options to the attribute