导航中的 Magento 类别和产品 - 子项

     2023-04-13     189

关键词:

【中文标题】导航中的 Magento 类别和产品 - 子项【英文标题】:Magento categories and products in navigation - child 【发布时间】:2014-02-19 03:09:57 【问题描述】:

我正在使用某种 magento 导航调整,它在主导航中显示类别和产品:

但有一个问题:在我的类别中:

Theme supplies
 -VIP Sparklers (2)
 -UV / Glow (12)
 -Seasonal (6)
 --Summer (6)
 -Confetti Cannons (7)
 -Props (2)

问题在于“夏季”子类别,它以这种方式显示:

如何以其他方式显示它,就像其他类别一样?像这样:

SEASONAL
SUMMER
Product1
2
3
4
5
6

这是我的navigation.php

<?php
/**
 * @version   1.0 12.0.2012
 * @author    Olegnax http://www.olegnax.com <mail@olegnax.com>
 * @copyright Copyright (C) 2010 - 2012 Olegnax
 */

class Olegnax_Navigation_Block_Navigation extends Mage_Catalog_Block_Navigation


    /**
     * columns html
     *
     * @var array
     */
    protected $_columnHtml;

    /**
     * Render category to html
     *
     * @param Mage_Catalog_Model_Category $category
     * @param int Nesting level number
     * @param boolean Whether ot not this item is last, affects list item class
     * @param boolean Whether ot not this item is first, affects list item class
     * @param boolean Whether ot not this item is outermost, affects list item class
     * @param string Extra class of outermost list items
     * @param string If specified wraps children list in div with this class
     * @param boolean Whether ot not to add on* attributes to list item
     * @return string
     */
   protected function _renderCategoryMenuItemHtml($category, $level = 0, $isLast = false, $isFirst = false,
    $isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false)

    if (!$category->getIsActive()) 
        return '';
    
    $html = array();

    // get all children
    if (Mage::helper('catalog/category_flat')->isEnabled()) 
        $children = (array)$category->getChildrenNodes();
        $childrenCount = count($children);
     else 
        $children = $category->getChildren();
        $childrenCount = $children->count();
    
    $hasChildren = ($children && $childrenCount);

    // select active children
    $activeChildren = array();
    foreach ($children as $child) 
        if ($child->getIsActive()) 
            $activeChildren[] = $child;
        
    
    $activeChildrenCount = count($activeChildren);
    $hasActiveChildren = ($activeChildrenCount > 0);

    // prepare list item html classes
    $classes = array();
    $classes[] = 'level' . $level;
    $classes[] = 'nav-' . $this->_getItemPosition($level);
    if ($this->isCategoryActive($category)) 
        $classes[] = 'active';
    
    $linkClass = '';
    if ($isOutermost && $outermostItemClass) 
        $classes[] = $outermostItemClass;
        $linkClass = ' class="'.$outermostItemClass.'"';
    
    if ($isFirst) 
        $classes[] = 'first';
    
    if ($isLast) 
        $classes[] = 'last';
    
    if ($hasActiveChildren) 
        $classes[] = 'parent';
    

    // prepare list item attributes
    $attributes = array();
    if (count($classes) > 0) 
        $attributes['class'] = implode(' ', $classes);
    
    if ($hasActiveChildren && !$noEventAttributes) 
         $attributes['onmouseover'] = 'toggleMenu(this,1)';
         $attributes['onmouseout'] = 'toggleMenu(this,0)';
    

    // assemble list item with attributes
    $htmlLi = '<li';
    foreach ($attributes as $attrName => $attrValue) 
        $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
    
    $htmlLi .= '>';
    $html[] = $htmlLi;

    $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
    $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
    $html[] = '</a>';

    // Grabbing the products for the category if it's level is 1
    if ($level == 1) 

        $catId = $category->getId();
        $categorie = new Mage_Catalog_Model_Category();
        $categorie->load($catId); // this is category id
        $collection = $categorie->getProductCollection()->addAttributeToSort('name', 'asc');
        $html[] = '<ul>';

        foreach ($collection as $pc)
        
            $p = new Mage_Catalog_Model_Product();
            $p->load($pc->getId());

            $data = $p->_data;
            $html[] = '<li><a href="/shop/'.$data['url_path'].'">'.$data['name'] .'</a></li>';
        

        $html[] = "</ul>\n";

    
    // Done

    // render children
    $htmlChildren = '';
    $j = 0;
    foreach ($activeChildren as $child) 
        $htmlChildren .= $this->_renderCategoryMenuItemHtml(
            $child,
            ($level + 1),
            ($j == $activeChildrenCount - 1),
            ($j == 0),
            false,
            $outermostItemClass,
            $childrenWrapClass,
            $noEventAttributes
        );
        $j++;
    
    if (!empty($htmlChildren)) 
        if ($childrenWrapClass) 
            $html[] = '<div class="' . $childrenWrapClass . '">';
        
        $html[] = '<ul class="level' . $level . '">';
        $html[] = $htmlChildren;
        $html[] = '</ul>';
        if ($childrenWrapClass) 
            $html[] = '</div>';
        
    

    $html[] = '</li>';

    $html = implode("\n", $html);
    return $html;




【问题讨论】:

【参考方案1】:

我认为this is basically what you're looking for。几年前我在一个项目中遇到了这个问题,这就是我解决它的方法。它允许在下拉菜单中使用图片轻松添加类别及其各自的产品。

更新

认为你想删除这些行,但我不肯定:

if ($hasActiveChildren && !$noEventAttributes) 
     $attributes['onmouseover'] = 'toggleMenu(this,1)';
     $attributes['onmouseout'] = 'toggleMenu(this,0)';

【讨论】:

是的,这很酷,但是 1 个小问题,看看:oi42.tinypic.com/20870i8.jpg 我不需要这个额外的框,你的代码有什么变化来删除它? 看起来该框出现在鼠标悬停/悬停时正确吗?如果是这样,请参阅我的更新答案。 是的,鼠标悬停在季节性和每个产品上。从您的编辑中删除代码什么都不做:( 哦,我看到如果启用此脚本,它会使页脚下的整个页面高度非常非常长,我在 css 检查器中看不到它,我更改为默认导航文件,页面高度为很好 我无法对此进行测试,因此您需要尝试删除代码块。我怀疑它是 cmets render children 下的最后两个主要块之一。

所有产品(类别和子类别产品)都计入 magento 中的类别列表页面

】所有产品(类别和子类别产品)都计入magento中的类别列表页面【英文标题】:Allproducts(categoryandsubcategoryproducts)countoncategorylistpageinmagento【发布时间】:2014-03-1607:00:34【问题描述】:我想显示类别和子类别下所有产品的计数。... 查看详情

Magento 主题例外不适用于类别和产品页面

】Magento主题例外不适用于类别和产品页面【英文标题】:Magentothemeexceptionsnotworkingonthecategoryandproductpages【发布时间】:2014-11-1307:44:09【问题描述】:我正在尝试为我的magento商店制作iphone和ipad版本。我按照以下步骤实现了回退:... 查看详情

Magento 类别页面未包含属性过滤器中的所有产品

】Magento类别页面未包含属性过滤器中的所有产品【英文标题】:Magentocategorypageisnotincludingallproductsintheattributefilters【发布时间】:2012-05-0123:07:09【问题描述】:我发现产品并不总是包含在***类别列表页面的属性过滤器中。我有一... 查看详情

Magmi 覆盖产品在类别中的位置

...11-2712:59:15【问题描述】:我正在使用Magmi将产品导入我的Magento商店。动态创建类别并导入产品。一切正常。除了一件事:每次我运行Magmi导入时,产品在Magento类别中的位置设置为0。这样我就无法按位置对产品进行排序。我在Magm... 查看详情

如何在 Magento 中使用产品 URL 附加类别和子类别 slug

】如何在Magento中使用产品URL附加类别和子类别slug【英文标题】:HowtoappendcategoryandsubcategoryslugwithproductURLsinMagento【发布时间】:2018-06-0713:02:38【问题描述】:我当前的产品网址是这种格式:example.com/product_slug。我需要将类别和子... 查看详情

Magento 试图在产品展示和类别页面上根据“尺寸属性”显示产品价格范围?

】Magento试图在产品展示和类别页面上根据“尺寸属性”显示产品价格范围?【英文标题】:Magentotryingtodisplayproductpricerangebasedon"sizeattribute"onProductdisplayandcategorypages?【发布时间】:2015-07-2604:42:56【问题描述】:我有可配置... 查看详情

无法在 magento 2.4.3 中查看类别下的产品

】无法在magento2.4.3中查看类别下的产品【英文标题】:Cantviewproductsundercategoriesinmagento2.4.3【发布时间】:2021-10-2420:24:56【问题描述】:我正在尝试在暂存环境中将我们的magento商务网站从2.4.1升级到2.4.3-我几乎可以正常工作,但我... 查看详情

从magento中的分层导航取消设置类别

...hthisXMLdefinitiontoremovethecategoryfiltersfromtheleft-layerednavigationinMagento.<referencename="catalog.leftnav"><actionmethod="unsetChild"><alias>category_filter</alias></action></reference> 查看详情

sql查询以检索magento中的所有产品id及其所属的类别。(代码片段)

查看详情

如何使magento过滤器像类别一样工作

】如何使magento过滤器像类别一样工作【英文标题】:howtomakemagentofilterworkslikecategory【发布时间】:2015-07-0106:20:10【问题描述】:我想让magento中的类别使用属性/过滤器。假设我有一个属性“CupAttr”,它不用于分层导航。然后我... 查看详情

Magento:如何在主导航菜单的下拉菜单中添加活动产品

】Magento:如何在主导航菜单的下拉菜单中添加活动产品【英文标题】:Magento:HOW-TOaddactiveproductsinadrop-downinMainNavigationMenu【发布时间】:2012-02-2308:30:11【问题描述】:我希望产品出现在类似于lowes.com的下拉导航菜单中,而不是类... 查看详情

控制 magento 左侧导航的渲染位置

】控制magento左侧导航的渲染位置【英文标题】:controlwheremagentoleftnavrenders【发布时间】:2015-06-0313:10:20【问题描述】:我想更改magento左侧导航的渲染位置,以便将其放置在给定类别上设置的静态CMS块之后,但在实际类别产品之... 查看详情

Magento 类别按属性排序

】Magento类别按属性排序【英文标题】:Magentocategorysortingbyattributes【发布时间】:2010-09-2409:14:22【问题描述】:我目前正在尝试为Magento类别页面制作特殊的排序功能。我有几个属性需要用于排序:第一个属性是命名设计师。此属... 查看详情

如何从magento 2中的可配置产品中获取简单产品

】如何从magento2中的可配置产品中获取简单产品【英文标题】:Howtogetsimpleproductfromconfigurableproductinmagento2【发布时间】:2021-12-2217:48:25【问题描述】:我想从产品详细信息和类别页面中的可配置产品中获取所选样本的产品ID。【... 查看详情

Magento 中的子类别列表

】Magento中的子类别列表【英文标题】:SubcategorylistinginMagento【发布时间】:2013-11-2917:58:24【问题描述】:我环顾四周,发现了很多关于提取父ID和子猫列表的信息,但这略有不同,我似乎无法找到答案,我还不是PHP专家(还)所... 查看详情

Magento - 按属性分类产品

】Magento-按属性分类产品【英文标题】:Magento-categoryproductsbyattribute【发布时间】:2013-06-2922:11:58【问题描述】:当我在Magento中创建类别时,我目前手动添加所有产品。问题是我们的产品越来越多,而且我们的一些产品经常更换... 查看详情

Magento 将产品批量分配到类别

】Magento将产品批量分配到类别【英文标题】:Magentomass-assignproductstocategory【发布时间】:2012-05-1809:23:23【问题描述】:正如标题所说,我需要将产品批量分配到一个类别,并且从管理员那里我一次只能编辑一个产品;我不知道... 查看详情

magento 1.9 新添加的产品没有显示在分类页面?

】magento1.9新添加的产品没有显示在分类页面?【英文标题】:magento1.9Newlyaddedproductsarenotshowingincategorypage?【发布时间】:2015-12-2910:32:34【问题描述】:产品已启用:是可见性:目录、搜索产品图片:很好可用数量:9999999库存情... 查看详情