当您查看Mage_Eav_Model_Entity_Setup 类中此方法的定义时,您将看到以下代码:
$data = array_merge(
array(
'entity_type_id' => $entityTypeId,
'attribute_code' => $code
),
$this->_prepareValues($attr)
);
此代码为属性准备数据。在_prepareValues() 方法中,您可以看到返回的数组不包含used_in_product_listing 键。因此,即使您在数组中提供它,它也不会传递给方法。
要解决此问题,您必须在 config.xml 中声明您自己的资源设置模型
<resources>
<company_module_setup>
<setup>
<module>Company_Module</module>
<class>Company_Module_Model_Resource_Setup</class>
</setup>
</company_module_setup>
</resources>
然后创建类并像这样覆盖_prepareValues() 方法
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;
}
}
它将允许您将其余选项添加到属性中