我想從主菜單中的每個類別下拉列表中添加品牌列表。我相信這將被視爲一個'超級菜單'。Magento在類別下拉菜單中添加品牌列表
例如 - 如果我將鼠標懸停在主類別上,它不僅會在下拉菜單中顯示子類別,還會顯示此類別中的所有不同品牌。
的品牌建立在兩個方面:
所有產品都具有的屬性「品牌」。因此,我們可以嘗試獲取該類別中的所有產品,並顯示與此類別中的產品相關的所有品牌的列表。這將需要合併分層導航,以便當選擇該菜單項時,它將顯示來自該類別和該品牌屬性的項目的過濾器。
我認爲這種方法會更容易 - 每個品牌都已經創建了自己的類別,並且每個產品都屬於主類別以及相關品牌類別。這是最初完成的,所以我們可以展示所有品牌的大名單。導航循環中的Magento中是否有函數來獲取「其他選擇的類別」?例如。如果項目位於類別A中,則下拉列表將顯示所有子類別,但也會顯示在產品上選擇的任何其他相關頂級類別。
我已經試過這涉及修改Navigation.php(Magento的1.6)的各種解決方案,但我只能把它顯示在店鋪所有的品牌,而不僅僅是品牌的特定類別內。請參見下面的代碼:
// 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("\n", $html);
return $html;
}
嗨尼希爾 - 非常感謝您的回答。目前,品牌已經建立在兩個方面(我已經更新了我的問題以上給你更多的信息)。我認爲我們不能將它們全部設置好,並且將它們作爲子分類來使用,因爲商店已經有超過1000個商品。 – ronnz
這是一個不好的解決方案!您應該使用製造商屬性並使用它來創建菜單。 看到這個:http://www.magentocommerce.com/wiki/5_-_modules_and_development/navigation/add_dropdown_list_of_manufactures_or_another_attribute – karantan
@karantan添加菜單後,下一步將是什麼..? –