문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top