4

How can i make a text attribute available to the layered navigation?

In the admin it is not possible to set an attribute to filterable if it is not a dropdown or price type.

I can worry about the frontend implications of this, but would like to know the best approach to open this up to text fields and make it possible for the text attribute to be loaded with the list of filters.

7

Reference Mage_Catalog_Model_Resource_Eav_Attribute::isIndexable(), which is used by the EAV indexer to check if a given attribute may be included in the layered navigation index.

public function isIndexable()
{
    // exclude price attribute
    if ($this->getAttributeCode() == 'price') {
        return false;
    }

    if (!$this->getIsFilterableInSearch() && !$this->getIsVisibleInAdvancedSearch() && !$this->getIsFilterable()) {
        return false;
    }

    $backendType    = $this->getBackendType();
    $frontendInput  = $this->getFrontendInput();

    if ($backendType == 'int' && $frontendInput == 'select') {
        return true;
    } else if ($backendType == 'varchar' && $frontendInput == 'multiselect') {
        return true;
    } else if ($backendType == 'decimal') {
        return true;
    }

    return false;
}

To make other input types indexable, you need to rewrite this attribute resource model (or specify a custom model that refers to a custom resource model in the eav_attribute.attribute_model property for your attribute.

The reason why the EAV indexer has this limitation, is because it only knows how to process integer values. The same is true for the layered navigation attribute filter model.
If your values are castable to integers, you will be able to get away with using a varchar or text value.
Otherwise you will have to rewrite the attribute filter model to correctly process your values, or implement your own custom filter model.

  • 1
    If i want to make a text field filterable it has to also be indexable? And therefore I will need a custom indexer to handle text values? Sounds like a ton of work. Is there a simpler workaround – Marty Wallace Jun 18 '13 at 22:06
  • If you want to have a text field filterable in the layered navigation, then yes. For performance reasons, all results for the layered navigation are pre-calculated. – Vinai Jun 18 '13 at 22:13
  • and that would mean every text field would have to be indexed? resulting in a lot of indexing when in reality this is to be used for only a few specific text attributes. Would a completely custom attribute type be better? – Marty Wallace Jun 18 '13 at 22:34
  • No, you only index the attribute you need - you don't have to apply it to every attribute. I suggest you study the native attribute indexer, then it will be clearer. Mage_Catalog_Model_Product_Indexer_Eav and Mage_Catalog_Model_Resource_Layer_Filter_Attribute and Mage_Catalog_Model_Layer_Filter_Attribute – Vinai Jun 19 '13 at 7:26
0

It should be possible to add an observer on product save and then extend multiple select to add text field with possible new attribute value so user then can either choose existing attribute value or add new one. And on save it is added to attribute values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.