题
如何使分层导航可用文本属性?
在管理员中,如果不是下拉或价格类型,则不可能将属性设置为可过滤。
我可以担心此的前端含义,但想知道将其打开到文本字段的最佳方法,并使文本属性可以加载到过滤器列表中。
解决方案
参考 Mage_Catalog_Model_Resource_Eav_Attribute::isIndexable()
, ,EAV索引使用该索引是否可以在分层导航索引中包含一个给定的属性。
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;
}
要使其他输入类型可索引,您需要重写此属性资源模型(或指定一个自定义模型,该模型是指在 eav_attribute.attribute_model
属性的属性。
EAV索引具有此限制的原因是因为它只知道如何处理整数值。分层导航属性过滤器模型也是如此。
如果您的值可铸造到整数,则可以使用VARCHAR或文本值逃脱。
否则,您将必须重写属性过滤器模型以正确处理您的值,或实现自己的自定义过滤模型。
其他提示
应该可以在产品保存上添加观察者,然后扩展多个选择以添加可能的新属性值,以便用户可以选择现有的属性值或添加新的属性值。并在保存上将其添加到属性值中。