1

我有一个 Magento 网站,其类别结构如下(大写字母是类别,小写字母是产品):

ROOT CATEGORY
     APPARELS
          SHOP BY SIZE
               product1
               product2
               product3
          SHOP BY COLLECTION
               product4
               product5
          SHOP BY DESIGN
               product6
               product7
               product8
               product9

我想将我的导航菜单显示为按尺寸购物、按系列购物和按设计购物。我不希望导航从 APPARELS 级别开始。有没有办法做到这一点?

注意:根据 Magento 设计,ROOT CATEGORY 不能显示在导航菜单中。导航菜单从第 2 级的类别开始,在这种情况下为服装。

4

2 回答 2

2

看一下navigation.php,您可以更改核心功能,但可以使用带有重写的模块(永远不要直接更改核心文件!)。当我需要自定义导航功能时,我总是从那里开始。

http://freegento.com/doc/db/d56/_catalog_2_block_2_navigation_8php-source.html

编辑,虽然我经常使用这种方法,我建议尽可能避免重写,我认为在这种情况下它不可能很难,因为我们正在谈论将 lvl 2 类别显示为主要导航

于 2013-01-04T17:54:45.657 回答
2

如果你真的想使用设计 Root -> Apparels -> Shop By * 你可以通过一个单一的覆盖和修改来做到这一点

config.xml - 这显然是一个高度简化的文件,您需要为该文件提供一个帮助程序重写。

<?xml version="1.0"?>
<config>
    <helpers>
        <catalog>
            <rewrite>
                <category>Namespace_Module_Helper_Catalog_Category</category>
            </rewrite>
        </catalog>
    </helpers>
</config>

Category.php 这假设您要使用站点根类别下的第一个子类别。在您的情况下,它将是“服装”。此修改考虑到使用平面或非平面类别表。还有其他选择 ID 的选项,一个是系统配置,将类别列表作为源,从而允许您直接选择导航根类别。

该文件的关键是让父 ID 成为您要作为导航基础的“根类别”。同样,对于您的情况,父 ID 将设置为“服装”类别的 ID。

class Namespace_Module_Helper_Catalog_Category extends Mage_Catalog_Helper_Category {
    public function getStoreCategories($sorted=false, $asCollection=false, $toLoad=true)
    {
        $parent     = Mage::app()->getStore()->getRootCategoryId();
        $cacheKey   = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad);
        if (isset($this->_storeCategories[$cacheKey])) {
            return $this->_storeCategories[$cacheKey];
        }

        /**
         * Check if parent node of the store still exists
         */
        $category = Mage::getModel('catalog/category');
        /* @var $category Mage_Catalog_Model_Category */
        if (!$category->checkId($parent)) {
            if ($asCollection) {
                return new Varien_Data_Collection();
            }
            return array();
        }

        /* Change ian on 1/4/13 at 11:16 AM - Description: Here we capture the id of first child for use as the 'root' */
        $category->load($parent);
        /** @var $collection Mage_Catalog_Model_Resource_Category_Collection */
        $collection = $category->getChildrenCategories();
        if (is_array($collection)) {
            $category = array_shift($collection); //get the first category in the array.  Unknown key.
            $parent = $category->getId();
        } else {
            $parent = $collection->getFirstItem()->getId();
        }

        $recursionLevel  = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth'));
        $storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);

        $this->_storeCategories[$cacheKey] = $storeCategories;
        return $storeCategories;
    }
}
于 2013-01-04T18:30:48.350 回答