2012-08-14 112 views
0

有没有办法通过安装文件和资源文件过滤自定义magento产品属性?使magento自定义属性可过滤

我可以创建属性,我甚至可以设置它进入的组,但无法手动进入管理员和调整属性的可过滤选项,我不能让它被设置为可过滤(尤其是可过滤 - 我尝试了w/true/false和0,1,2)。我试着调整每个有意义的选项。

即:

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(); 
+0

是否应该有一个'option'键来使这个属性使用Multiple Select? – 2012-08-15 03:16:03

+0

可以肯定的是,创建后清除缓存和重建索引? – 2012-08-15 03:17:40

+0

不需要'option'标签 - 它不是多选,我已经清除了缓存并重新编制了所需的内容。不过,我可以保证索引不是可过滤的问题。当我运行我的更新属性设置为离开'catalog_eav_attribute'表记录w /'is_filterable = 0'。为了解决这个问题,我需要在我的资源文件中添加'$ this-> updateAttribute('catalog_product','attribute_name','is_fiterable',1);'。现在我只是好奇,如果我可以在Setup.php文件中做到这一点或不是?感觉像调整可筛选选项应该工作。 – veilig 2012-08-15 04:14:33

回答

2

您可以通过以下方式添加属性:

module_name\sql\machinesearch_setup 

创建模块在这样一个SQL安装文件。

<?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(); 
?> 
+0

伟大的一个Darshanbhai! – 2012-09-05 06:43:19