分层导航中的多选过滤器

发布于 2024-12-07 08:32:42 字数 141 浏览 1 评论 0原文

我有一个自定义多选属性,我想参与产品过滤。该属性设置为分层导航中使用的,但不会出现在可用过滤器列表中。可能是由于自定义模型实现所致? 有人有一些提示可以在哪里检查它为什么不出现吗?为多个产品设置属性 使用的 Magento 版本是 EE 1.11

谢谢

I have a custom multi select attribute which I'd like to take part in filtering of products. The attribute is set as used in Layered Navigation however doesn't appear in the list of available filters. Could be due to custom model implementation?
Anyone have some tips where to check why it doesn't appear? Attribute is set for several products
Magento version used is EE 1.11

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半﹌身腐败 2024-12-14 08:32:42

对于那些将来会遇到这个问题的人:问题出在 Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source 文件的第 191 行。默认情况下,多选属性值是从 eav_attribute_option 中提取的,如果您的自定义属性使用自定义源模型,该属性不会被索引。

我还不知道它是否是有意的,但我找不到比在 local pull 中覆盖该模型并在 $options 数组中添加所需值更好的解决方案。

希望有一天这可以帮助某人

For those who will struggle with this in the future: the problem is in Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source file on line 191. By default multi select attribute values are being pulled from eav_attribute_option and if your custom attribute uses custom source model the attribute will not be indexed.

I don't know as of yet if it's intended but I couldn't find a better solution than overriding that model in local pull and adding required values in $options array.

Hope this helps someone, someday

拥醉 2024-12-14 08:32:42

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() 方法是否在自定义源模型中实现?< br>
这实际上只需要构建和更新平面目录产品表(因此需要设置used_in_product_listing 或is_filterable 属性以便Magento 获取该属性)。
检查类 Mage_Eav_Model_Entity_Attribute_Source_Table 作为这些方法应该返回的内容的参考。

What is the backend_type. i.e. are the values stored in the catalog_product_entity_varchar or catalog_product_entity_text table?
The backend_type has to match the checks in Mage_Catalog_Model_Resource_Eav_Attribute::isIndexable(), so text wouldn't work without rewriting the attribute model.

Is the is_filterable and/or is_filterable_in_search attribute property set?
The Mage_Catalog_Model_Product_Indexer_Eav::_registerCatalogAttributeSaveEvent() checks for those when updating the index for the layered navigation.

Are the methods getFlatColums(), getFlatIndexes() and getFlatUpdateSelect() implemented in the custom source model?
This actually is only required for building and updating the flat catalog product tables (so the used_in_product_listing or is_filterable property needs to be set in order for Magento to pick up the attribute).
Check the class Mage_Eav_Model_Entity_Attribute_Source_Table as a reference on what these there methods are supposed to return.

ㄟ。诗瑗 2024-12-14 08:32:42

注意:我将其添加到新答案中以使用代码格式。

怎么说呢,问题在于使用自定义源模型的多选属性。

解决方案:
重写类

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;
    }

我找不到一种侵入性较小的方法来解决此问题。

NOTE: I'm adding this in a new answer to use the code format.

How it was said, the problem is with multiselect attributes using a custom source model.

Solution:
Rewrite the class

Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source

Override the method:

_prepareMultiselectIndex

add this code after the $options array is filled with the default code (check line 200 in original file)

foreach($attrIds as $attId){
            if( ! isset($options[$attId])){
                $options[$attId] = $this->_getOptionsFromSourceModel($attId);
            }
        }

add this method too:

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;
    }

I couldn't find a less intrusive way to fix this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文