0
votes

Is there a way to make a custom magento product attribute filterable through a setup file and resource file?

I can create the attribute, I can even set the group it goes into but w/out manually going into the admin and adjusting the filterable option on the attribute, I can't get it to be set to filterable (especially filterable - I've tried w/ true/false and 0,1,2). I've tried adjust about every option that makes sense.

ie:

app/code/local/Company/Module/Model/Resource/Eav/Mysql4/Setup.php
public function getDefaultEntities()
{
    return array(
            'catalog_product' => array(
                'entity_model'      => 'catalog/product',
                'attribute_model'   => 'catalog/resource_eav_attribute',
                'table'             => 'catalog/product',
                'additional_attribute_table' => 'catalog/eav_attribute',
                'entity_attribute_collection' => 'catalog/product_attribute
                'attributes' => array(
                    'attribute_name' => array(
                        'group'                      => 'Attribute Set Group',
                        'type'                       => 'int',
                        'backend'                    => '',
                        'frontend'                   => '',
                        'label'                      => 'Attribute Label',
                        'input'                      => 'select',
                        'class'                      => '',
                        'source'                     => 'eav/entity_attribu
                        'global'                     => Mage_Catalog_Model_
                        'visible'                    => true,
                        'required'                   => false,
                        'user_defined'               => true,
                        'default'                    => false,
                        'searchable'                 => true,
                        'filterable'                 => 1,
                        'comparable'                 => false,
                        'visible_on_front'           => true,
                        'visible_in_advanced_search' => true,
                        'used_in_product_listing'    => true,
                        'used_for_sort_by'           => true,
                        'unique'                     => false,
                    ),
                ),
            ),
        );
}


app/code/local/Company/Module/Model/sql/module_setup/mysql4-install-0.1.0.php
$this->installEntities();
1
Should there be an option key to make this attribute use a Multiple Select?Jürgen Thelen
And just to be sure, cleared caches and rebuilt indexes after creation?Jürgen Thelen
don't need the option tag - its not a multi select, and I've cleared caches and reindexed whats needed. however, I can guarantee the index is not the issue to make it filterable. when I run my update the attribute setup as is leaves the catalog_eav_attribute table record w/ is_filterable = 0. to fix this I need to add $this->updateAttribute('catalog_product', 'attribute_name', 'is_fiterable', 1); to my resource file. Now I'm just curious if I can do this in the Setup.php file or not? It feels like adjusting the filterable option should work.veilig
Afaik layered navigation filters must be of input type Dropdown, Multiple Select or Price. That's why I asked for the option key.Jürgen Thelen

1 Answers

2
votes

You can add an attribute in the following way:

module_name\sql\machinesearch_setup

Create one SQL setup file like this in your module.

<?php
    $installer = $this;
    $data= array (
        'attribute_set' =>  'Default',
        'global'    =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        'label'     => 'Year',
        'input'     => 'multiselect',
        'type'      => 'text',
        'default_value_text' => 'varchar',
        'unique'    => false,
        'required'  => false,
        'visible'   => true,
        'searchable'=> true,
        'visible_in_advanced_search'    => true,
        'html_allowed_on_front'         => true,
        'comparable'   => false,  
        'backend_type'  => 'varchar',
        'backend'   => 'eav/entity_attribute_backend_array',
        'group'     => 'General',
        'user_defined'  => true,
       );

       $installer->addAttribute('catalog_product','mmy_year',$data);


       $data= array 
        (  
        'attribute_set' =>  'Default',
        'global'  => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        'label' => 'Make',
        'input' => 'multiselect',
        'type'  => 'text',
        'default_value_text'  => 'varchar',
        'unique'=> false,
        'required'=> false,
        'visible' => true,
        'searchable'=> true,
        'visible_in_advanced_search'=> true,
        'html_allowed_on_front'  => true,
        'comparable'=> false,
        'backend_type'  => 'varchar',
        'backend'=> 'eav/entity_attribute_backend_array',
        'group'  => 'General',
        'user_defined'=> true,
        );    
        $installer->addAttribute('catalog_product','mmy_make',$data);
    $data= array (
          'attribute_set'               =>  'Default',
          'global'                          =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
          'label'                           => 'Model',
          'input'                           => 'multiselect',
          'type'                            => 'text',
          'default_value_text'            => 'varchar',
          'unique'                          => false,
          'required'                    => false,
          'visible'                     => true,
          'searchable'                  => true,
          'visible_in_advanced_search'  => true,
          'html_allowed_on_front'       => true,
          'comparable'                  => false,
          'backend_type'                  => 'varchar',
          'backend'                     => 'eav/entity_attribute_backend_array',
          'group'                           => 'General',
          'user_defined'                    => true,
          );

  $installer->addAttribute('catalog_product','mmy_model',$data);
  $installer->endSetup();
?>