【问题标题】:Magento categories navigationMagento 类别导航
【发布时间】:2013-01-04 17:41:24
【问题描述】:

我有一个 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 不能显示在导航菜单中。导航菜单从第二级的类别开始,在这种情况下是服装。

【问题讨论】:

  • 服装是该级别的唯一类别吗?

标签: web-services magento web e-commerce magento-1.7


【解决方案1】:

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

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

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

【讨论】:

    【解决方案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>
    

    类别.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;
        }
    }
    

    【讨论】:

    • 当他只需要一个自定义导航时,你为什么要调整类别助手?这将改变对这个助手的所有调用......
    • 他指定他希望导航基于第三级类别而不是第二级。这实现了这一点。现在,从这一点而不是根类别呈现菜单的负担留给了主题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多