问题描述
我正在使用某种magento导航调整,它在主导航中显示类别和产品:
I'm using some kind of magento nav tuning, which displays categories and products in main nav:
但是有一个问题:在我的类别中,我有:
but there's a problem: in my categories I have:
Theme supplies
-VIP Sparklers (2)
-UV / Glow (12)
-Seasonal (6)
--Summer (6)
-Confetti Cannons (7)
-Props (2)
,问题出在夏季"子类别中,它以这种方式显示:
and the problem is with "Summer" subcategory, it displays in this way:
如何像其他类别一样以其他方式显示它?像这样:
How to display it in another way, like other categories? Like this:
SEASONAL
SUMMER
Product1
2
3
4
5
6
这是我的navigation.php
:
<?php
/**
* @version 1.0 12.0.2012
* @author Olegnax http://www.olegnax.com <[email protected]>
* @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;
}
}
推荐答案
我认为.几年前,我在一个项目中遇到了这个问题,这就是我解决它的方法.它使您可以在下拉菜单中轻松添加带有图像的类别及其各自的产品.
I think this is basically what you're looking for. I ran into this on a project a few years ago and this is how I solved it. It allows for easily adding categories and their respective products with images in a drop-down menu.
更新
我认为,您想删除以下几行,但我并不肯定:
I think you want to remove these lines but I'm not positive:
if ($hasActiveChildren && !$noEventAttributes) {
$attributes['onmouseover'] = 'toggleMenu(this,1)';
$attributes['onmouseout'] = 'toggleMenu(this,0)';
}
这篇关于Magento导航中的类别和产品-儿童的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!