开发者

Multi select filter in layered navigation

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 av开发者_如何学编程ailable 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


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜