dongre6404 2012-12-24 07:46
浏览 38

Magento在类别下拉菜单中添加品牌列表

I am trying to add a listing of brands inside each category drop down list from the main menu. I believe this would be considered as a 'mega menu'.

For example - if i hover over a main category it will not only show sub categories in the drop down menu, but also all the different brands inside this category.

The brands are set up in two ways:

  1. All products have an attribute 'brand'. Therefore we could try to get all the products inside the category and display a list of all the brands associated with the products in this category. This would need to incorporate layered navigation so that when that menu item is selected, it will show a filter of items from that category AND that brand attribute.

  2. I think this method would be easier - Each brand already has it's own category created as well, and each product is in both the main category, as well as it's relevant brand category. This was originally done so we could show a big listing of all brands. Is there function in Magento inside the navigation loop to get 'other chosen categories'? E.g. If an item is in Category A, the drop down list shows all sub-categories, but also any other related top level categories which are selected on the products.

I have tried various solutions which involved modifying Navigation.php (magento 1.6) but I could only get it to display ALL brands in the shop, not just brands inside a particular category. See code below:

// Navigation.php code
// 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;

    // My modifications start here

    $product = Mage::getModel('catalog/product');
    $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
    ->setEntityTypeFilter($product->getResource()->getTypeId())
    ->addFieldToFilter('attribute_code', 'brands');
    $attribute = $attributes->getFirstItem()->setEntity($product->getResource());
    $manufacturers = $attribute->getSource()->getAllOptions(false);
    $html[] = '<ol id="nav-drop-brands">';
    foreach ($manufacturers as $manufacturer) {
    $html[] = '<li><a href="http://www.domain.com/catalogsearch/advanced/result?manufacturer[]=';
    $html[] = $manufacturer['value'];
    $html[] = '">';
    $html[] = $manufacturer['label'];
    $html[] = '</a></li>';
    }
    $html[] = '</ol>';

    // end of my modifications 

    $html[] = '</ul>';
    if ($childrenWrapClass) {
    $html[] = '</div>';
    }
    }

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

    $html = implode("
", $html);
    return $html;
    }
  • 写回答

1条回答 默认 最新

  • doulangchao8934 2012-12-24 08:01
    关注

    You can go by this :
    Add category
    Then add sub category
    Then add sub-sub category
    (This will be your all brands name,which is nothing but category only)

    To retrieve these categories you can visit this link.

    Hope this help you .

    评论

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码