Magento-在分层导航中设置类别
每当我使用搜索框搜索产品时,在左侧有一个按类别的过滤器。创建此筛选器的代码如下所示:Magento-在分层导航中设置类别,magento,magento-1.7,layered-navigation,Magento,Magento 1.7,Layered Navigation,每当我使用搜索框搜索产品时,在左侧有一个按类别的过滤器。创建此筛选器的代码如下所示: <dl id="narrow-by-list"> <?php $_filters = $this->getFilters() ?> <?php foreach ($_filters as $_filter): ?> <?php if($_filter->getItemsCount()): ?> <?php if($_f
<dl id="narrow-by-list">
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>
<?php if($_filter->getName() != "Category"){ ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd>
<?php echo $_filter->getHtml() ?>
</dd>
<?php } endif; ?>
<?php endforeach; ?>
</dl>
这只显示过滤器中的主类别,我想显示它的子类别。我尝试使用以下代码以编程方式设置另一个类别:
<?php
$layer = Mage::getSingleton('catalog/layer');
$_categ = Mage::getModel('catalog/category')->load(5);
$layer->setCurrentCategory($_categ);
?>
。。。但一切都没有改变。有什么想法吗?当您试图从模板中设置层singleton上的其他类别时,已经太迟了,因为所有处理都已应用 您可以做的是将文件
app/code/core/Mage/CatalogSearch/Model/Layer.php
复制到app/code/local/Mage/CatalogSearch/Model/
中,并添加基本Mage\u Catalog\u Model\u Layer::getCurrentCategory()
方法的修改版本,如下所示:
public function getCurrentCategory()
{
$category = $this->getData('current_category');
if (is_null($category)) {
if ($category = Mage::registry('current_category')) {
$this->setData('current_category', $category);
}
else {
$category = Mage::getModel('catalog/category')->load(5); // Put here the ID of the category you want to use as basis for category filtering
$this->setData('current_category', $category);
}
}
return $category;
}
当您尝试从模板中设置层singleton上的其他类别时,为时已晚,因为所有处理都已应用 您可以做的是将文件
app/code/core/Mage/CatalogSearch/Model/Layer.php
复制到app/code/local/Mage/CatalogSearch/Model/
中,并添加基本Mage\u Catalog\u Model\u Layer::getCurrentCategory()
方法的修改版本,如下所示:
public function getCurrentCategory()
{
$category = $this->getData('current_category');
if (is_null($category)) {
if ($category = Mage::registry('current_category')) {
$this->setData('current_category', $category);
}
else {
$category = Mage::getModel('catalog/category')->load(5); // Put here the ID of the category you want to use as basis for category filtering
$this->setData('current_category', $category);
}
}
return $category;
}