2014-01-28 2 views
0

Я использую какие-то настройки навигационной Magento, который отображает категории и продукты в главном нав: http://oi41.tinypic.com/317d4t4.jpgMagento категории и продукты в навигации - ребенок

но есть проблема: в моей категории у меня есть:

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

и проблема с подкатегории «Лето», отображается следующим образом: http://oi41.tinypic.com/166he80.jpg

Как отобразить это по-другому, как и другие категории? Как это:

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; 
} 


} 

ответ

0

Я думаю this is basically what you're looking for. Я столкнулся с этим в проекте несколько лет назад, и именно так я решил это. Это позволяет легко добавлять категории и их соответствующие продукты с изображениями в раскрывающемся меню.

Update

Я думаю вы хотите удалить эти строки, но я не уверен:

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

да, это круто, но один маленький вопрос, посмотрите: HTTP : //oi42.tinypic.com/20870i8.jpg Мне не нужна эта дополнительная коробка, какие изменения в коде для ее удаления? –

+0

Похоже, что окно появляется при наведении курсора мыши/наведите правильно? Если да, см. Мой обновленный ответ. –

+0

Да, это на мыши на сезонные и каждый продукт под. Удаление кода из вашего редактирования ничего не делает :( –

Смежные вопросы