Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento-在分层导航中设置类别_Magento_Magento 1.7_Layered Navigation - Fatal编程技术网

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;
}