經過一番嘗試,我已經有了這個工作!下面是新的代碼在
app/code/core/Mage/Catalog/Block/Navigation.php
function _renderCategoryMenuItemHtml
使用(交換「本地」的「核心」,如果本地化)
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);
// get products listing
$cur_category = Mage::getModel('catalog/category')->load($category->getId());
$_productCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($cur_category)->setOrder('position','ASC');
$k = 1;
$hasProduct1 = $_productCollection->count();
$phtmlChildren = '';
if ($hasProduct1 >= 1) {
$l = $level+1;
foreach ($_productCollection as $_product) {
$cur_product = Mage::getModel('catalog/product')->load($_product->getId());
if ($cur_product->getStatus()) {
$phtmlChildren .= '<li';
$phtmlChildren .= ' class="level'.$l;
$phtmlChildren .= ' nav-'.$this->_getItemPosition($l);
if ($k == $hasProduct1) {
$phtmlChildren .= ' last';
}
$phtmlChildren .= '">'."\n";
$phtmlChildren .= ' <a href="'.$cur_product->getProductUrl().'">'.$this->htmlEscape($cur_product->getName()).'</a>'."\n";
$phtmlChildren .= '</li>';
$k++;
}
}
}
// 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>';
// render 'product' children
$htmlChildren = '';
if ($hasChildren) {
$j = 0;
foreach ($children as $child) {
if ($child->getIsActive()) {
$htmlChildren .= $this->_renderCategoryMenuItemHtml($child, $level + 1, $j++ >= $k);
}
}
}
if ((!empty($htmlChildren)) || (!empty($phtmlChildren))) {
$html[] = '<ul class="level'.$level.'">'."\n".$htmlChildren.$phtmlChildren.'</ul>';
}
// 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;
}
基本上有兩種新增加的部分。第一部分構建產品收集以獲取相關信息(名稱,網址等)。第二部分在現有根類別列表項目內追加新的無序列表。希望這可以幫助某人。現在你不需要支付$ 99的擴展,就在那裏:)
測試在v.1.6.1
非常有幫助謝謝。不利的一面是,如果該文件是核心的一部分,則會更新文件。 – EasyCo 2012-02-28 01:48:18
不,它不會,只是把它放在本地文件夾。爲了清楚起見,我只列出了特定的代碼。 – 2012-02-28 02:29:29
小心請擴大一點嗎? – EasyCo 2012-02-28 02:51:02