在magento中隐藏或显示某些类别中的过滤器
在我们的最高级别类别中,大约有50个shop by选项,我试图在自定义类别布局中使用xml代码隐藏属性过滤器。使用此代码在magento中隐藏或显示某些类别中的过滤器,magento,attributes,categories,Magento,Attributes,Categories,在我们的最高级别类别中,大约有50个shop by选项,我试图在自定义类别布局中使用xml代码隐藏属性过滤器。使用此代码 <reference name="em.catalog.leftnav"> <action method="setData"> <instruction>hide_attribute_code</instruction> <value>1</value> </action>
<reference name="em.catalog.leftnav">
<action method="setData">
<instruction>hide_attribute_code</instruction>
<value>1</value>
</action>
隐藏属性代码
1.
但不要隐藏该类别中的过滤器属性,请在catalog.xml中的image上检查它
<catalog_category_layered translate="label">
<label>Catalog Category (Anchor)</label>
<reference name="left">
<block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
<catalog_category_layered translate="label">
目录类别(锚定)
遵循模板。。。catalog/layer/view.phtml
打开此文件,并按名称或id设置在前端显示过滤器的条件
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getName() == 'Price' || $_filter->getName() == 'Category' || $_filter->getName() == 'Manufacturer' ): ?>
<?php if($_filter->getItemsCount()): ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
您需要在视图层上取消设置属性名称,因此查找此文件:
magento/app/design/frontend/base/default/template/catalog/layer/view.phtml
编辑:
decorateDataList(‘按列表缩小’)
希望你现在能开始工作 我不知道您的扩展对于分层导航是可靠的,但这应该可以工作:
<reference name="em.catalog.leftnav">
<action method="hideAttributes">
<code>hide_attribute_code</code>
</action>
</reference>
转到app/code/POOL/YOUR/MODULE/Blocks/…
中构建过滤器的文件。如果您的模板有类似于getFilters()
的内容,您可以尝试echo get\u class($this)
来获取正确的类/文件。在这里,你必须做两件事:
1.)添加新方法(在这种情况下,可以设置逗号分隔属性代码)
2.)搜索收集过滤器的函数,例如getFilters()
并添加
$filterableAttributes = // some code
foreach ($filterableAttributes as $attribute) {
if (!in_array($attribute->getAttributeCode(), $this->getHideAttributes())) {
...
}
}
我正在尝试但没有成功对我来说很好,你能发布你尝试的代码中哪些不适合你吗?我如何隐藏选定类别产品的选定属性
public function hideAttributes($attributeCodes)
{
$attributeCodes = array_map('trim', explode(',', $attributeCodes));
$this->setData('hide_attributes', $attributeCodes);
}
$filterableAttributes = // some code
foreach ($filterableAttributes as $attribute) {
if (!in_array($attribute->getAttributeCode(), $this->getHideAttributes())) {
...
}
}