我有一个自定义多选属性,我想参与过滤产品。该属性设置为在分层导航中使用,但不会出现在可用过滤器列表中。可能是由于自定义模型实现?任何人都有一些提示可以检查为什么它没有出现?为几个产品设置了属性 Magento 使用的版本是 EE 1.11
谢谢
我有一个自定义多选属性,我想参与过滤产品。该属性设置为在分层导航中使用,但不会出现在可用过滤器列表中。可能是由于自定义模型实现?任何人都有一些提示可以检查为什么它没有出现?为几个产品设置了属性 Magento 使用的版本是 EE 1.11
谢谢
对于那些将来会为此苦苦挣扎的人:问题Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source
在第 191 行的文件中。默认情况下,多选属性值是从中提取的eav_attribute_option
,如果您的自定义属性使用自定义源模型,则该属性将不会被索引。
我还不知道它是否是有意的,但我找不到比在local
拉取中覆盖该模型并在$options
数组中添加所需值更好的解决方案。
希望有一天这对某人有所帮助
什么是backend_type。即是存储在catalog_product_entity_varchar 或catalog_product_entity_text 表中的值吗?
backend_type 必须匹配 Mage_Catalog_Model_Resource_Eav_Attribute::isIndexable() 中的检查,因此如果不重写属性模型,文本将无法工作。
是否设置了is_filterable和/或is_filterable_in_search属性属性?
Mage_Catalog_Model_Product_Indexer_Eav::_registerCatalogAttributeSaveEvent() 在更新分层导航的索引时检查那些。
方法getFlatColums()、getFlatIndexes()和getFlatUpdateSelect()是否在自定义源模型中实现?
这实际上仅在构建和更新平面目录产品表时需要(因此需要设置 used_in_product_listing 或 is_filterable 属性以便 Magento 获取该属性)。
检查类 Mage_Eav_Model_Entity_Attribute_Source_Table 作为这些方法应该返回的参考。
注意:我将其添加到使用代码格式的新答案中。
怎么说呢,问题在于使用自定义源模型的多选属性。
解决方案:重写类
Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source
覆盖方法:
_prepareMultiselectIndex
在 $options 数组填充默认代码后添加此代码(检查原始文件中的第 200 行)
foreach($attrIds as $attId){
if( ! isset($options[$attId])){
$options[$attId] = $this->_getOptionsFromSourceModel($attId);
}
}
也添加此方法:
protected function _getOptionsFromSourceModel($attId)
{
$options = array();
/** @var Mage_Eav_Model_Entity_Attribute_Abstract $attribute */
$attribute = Mage::getResourceSingleton('catalog/product')->getAttribute($attId);
/** @var Mage_Eav_Model_Entity_Attribute_Source_Abstract $source */
$source = $attribute->getSource();
$sourceOptions = $source->getAllOptions();
if($sourceOptions){
foreach($sourceOptions as $sourceOption){
if(isset($sourceOption['value'])){
$options[$sourceOption['value']] = true;
}
}
}
return $options;
}
我找不到一种侵入性较小的方法来解决这个问题。