public function BuildBranch(Varien_Data_Tree_Node $node) { $buildString = '<li style="padding-left: 16px;">'; $buildString .= '<div class="tree-level-' . $node->getLevel() . '">'; if ($node->getChildrenCount() != 0) { $buildString .= '<div class="opener" id="opener' . $node->getId() . '" OnClick="OpenMe(this)"></div>'; } else { $buildString .= '<div class="child"></div>'; } $buildString .= ' <input type="checkbox" class="inputcb" id="inputcb' . $node->getId() . '" OnClick="Decide(this)" enabled="false"/> <div class="folder"></div> <a tabindex="1" href="#" hidefocus="on" id="linkItem"><span unselectable="on" id="extdd-' . $node->getLevel() . '">' . $node->getName() . '</a> '; $buildString .= '</div>'; if ($node->getChildrenCount() != 0) { $buildString .= '<ul id="ToOpen' . $node->getId() . '">'; foreach ($node->getChildren() as $child) { $buildString .= $this->BuildBranch($child); } $buildString .= '</ul>'; } $buildString .= '</li>'; return $buildString; }
/** * @param Varien_Data_Tree_Node $menuTree * @param string $childrenWrapClass * * @return string */ protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass) { $html = ''; $counter = 1; $children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1; $childrenCount = $children->count(); $parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-'; foreach ($children as $child) { $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter); $outermostClassCode = ''; $outermostClass = $menuTree->getOutermostClass(); if ($childLevel == 0 && $outermostClass) { $outermostClassCode = ' class="' . $outermostClass . '" '; $child->setClass($outermostClass); } $blockName = $childLevel == 0 ? 'bennoislost.easy-navigation.renderer.with-children' : 'bennoislost.easy-navigation.renderer.single'; $html .= $this->_renderBlockItem($blockName, $childrenWrapClass, $child, $outermostClassCode); $counter++; } return $html; }
/** * {@inheritDoc} */ protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass) { $html = ''; $children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1; $counter = 1; $childrenCount = $children->count(); $parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-'; foreach ($children as $child) { $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter); $outermostClassCode = ''; $outermostClass = $menuTree->getOutermostClass(); if ($childLevel == 0 && $outermostClass) { $outermostClassCode = ' class="' . $outermostClass . '" '; $child->setClass($outermostClass); } if ($child->hasChildren()) { $outermostClassCode .= ' data-toggle="dropdown" '; } $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>'; $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'; $html .= $this->escapeHtml($child->getName()); if ($child->hasChildren()) { $html .= ' <b class="caret"></b>'; } $html .= '</span></a>'; if ($child->hasChildren()) { if (!empty($childrenWrapClass)) { $html .= '<div class="' . $childrenWrapClass . '">'; } $html .= '<ul class="level' . $childLevel . ' dropdown-menu">'; if (Mage::getStoreConfig('catalog/navigation/top_in_dropdown') && $childLevel == 0) { $prefix = Mage::getStoreConfig('catalog/navigation/top_in_dropdown_prefix'); $suffix = Mage::getStoreConfig('catalog/navigation/top_in_dropdown_suffix'); $html .= '<li class="level1 level-top-in-dropdown">'; $html .= '<a href="' . $child->getUrl() . '"><span>'; $html .= $this->escapeHtml($this->__($prefix) . ' ' . $child->getName() . ' ' . $suffix); $html .= '</span></a>'; $html .= '</li>'; $html .= '<li class="divider"></li>'; } $html .= $this->_getHtml($child, $childrenWrapClass); $html .= '</ul>'; if (!empty($childrenWrapClass)) { $html .= '</div>'; } } $html .= '</li>'; $counter++; } return $html; }
/** * Convert node to array with path information. * Path information skips the 'Root Catalog' (level=0) and 'Default Category' (level=1) levels. * * @param Varien_Data_Tree_Node $node * @return array */ protected function _nodeToArrayPath(Varien_Data_Tree_Node $node, $parentPath) { // Only basic category data $categories = array(); $category = array(); $category['category_id'] = $node->getId(); $category['parent_id'] = $node->getParentId(); $category['name'] = $node->getName(); $category['path'] = !empty($parentPath) && $node->getLevel() > 2 ? $parentPath . '/' . $node->getName() : $node->getName(); $category['is_active'] = $node->getIsActive(); $category['position'] = $node->getPosition(); $category['level'] = $node->getLevel(); $categories[] = $category; foreach ($node->getChildren() as $child) { $children = $this->_nodeToArrayPath($child, $category['path']); $categories = array_merge($categories, $children); } return $categories; }
/** * Recursively generates top menu html from data that is specified in $menuTree * * @param Varien_Data_Tree_Node $menuTree * @param string $childrenWrapClass * @return string */ protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass) { $html = ''; $children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1; $counter = 1; $childrenCount = $children->count(); $parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-'; $brandCategoryId = Mage::getStoreConfig('brand/brand/category_id'); $_helperBrands = Mage::helper('brand'); $brandUrl = Mage::getUrl($_helperBrands->getBrandsUrl()); foreach ($children as $child) { $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter); $outermostClassCode = ''; $outermostClass = $menuTree->getOutermostClass(); if ($childLevel == 0 && $outermostClass) { $outermostClassCode = ' class="' . $outermostClass . '" '; $child->setClass($outermostClass); } $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>'; $categoryId = str_replace("category-node-", "", $child->getId()); //$url=($categoryId==$brandCategoryId)?$brandUrl:$child->getUrl(); $url = $child->getUrl(); $html .= '<a href="' . $url . '" ' . $outermostClassCode . '><span>' . $this->escapeHtml($child->getName()) . '</span></a>'; if ($child->hasChildren()) { if (!empty($childrenWrapClass)) { $html .= '<div class="' . $childrenWrapClass . '">'; } $html .= '<ul class="level' . $childLevel . '">'; /*if($childLevel==0) { $html .= '<div class="submenu">'; }*/ $html .= $this->_getHtml($child, $childrenWrapClass); /*if($childLevel==0) { $html .= '</div>'; }*/ $html .= '</ul>'; if (!empty($childrenWrapClass)) { $html .= '</div>'; } } $html .= '</li>'; $counter++; } return $html; }
function nodeToArray(Varien_Data_Tree_Node $node) { $result = array(); $result['category_id'] = $node->getId(); $result['parent_id'] = $node->getParentId(); $result['name'] = $node->getName(); $result['is_active'] = $node->getIsActive(); $result['position'] = $node->getPosition(); $result['level'] = $node->getLevel(); $result['children'] = array(); foreach ($node->getChildren() as $child) { $result['children'][] = $this->nodeToArray($child); } return $result; }
private function nodeToArray(Varien_Data_Tree_Node $node) { $result = array(); $category = Mage::getModel('catalog/category')->load($node->getId()); if ($category->getAvailableForSupplier() == 1) { $result['category_id'] = $node->getId(); $result['parent_id'] = $node->getParentId(); $result['name'] = $node->getName(); $result['is_active'] = $node->getIsActive(); $result['position'] = $node->getPosition(); $result['level'] = $node->getLevel(); } $result['children'] = array(); foreach ($node->getChildren() as $child) { $result['children'][] = $this->nodeToArray($child); } return $result; }
protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass) { $html = ''; $children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1; $counter = 1; $childrenCount = $children->count(); $parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-'; foreach ($children as $child) { $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter); $outermostClassCode = ''; $outermostClass = $menuTree->getOutermostClass(); if ($childLevel == 0 && $outermostClass) { $outermostClassCode = ' class="' . $outermostClass . '" '; $child->setClass($outermostClass); } $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>'; $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . ' class="nav-link">' . $this->escapeHtml($child->getName()) . '</a>'; if ($child->hasChildren()) { if (!empty($childrenWrapClass)) { $html .= '<div class="' . $childrenWrapClass . '">'; } $html .= '<ul class="level' . $childLevel . '">'; $html .= $this->_getHtml($child, $childrenWrapClass); $html .= '</ul>'; if (!empty($childrenWrapClass)) { $html .= '</div>'; } $html .= '<span class="subnav-toggle"><i class="icon icon-angle-down"></i><i class="icon icon-angle-up"></i></span>'; } $html .= '</li>'; $counter++; } return $html; }
protected function _getMenuItemClasses(Varien_Data_Tree_Node $item) { $classes = array(); $classes[] = 'level' . $item->getLevel(); $classes[] = $item->getPositionClass(); if ($item->getIsFirst()) { $classes[] = 'first'; } if ($item->getIsActive()) { $classes[] = 'li_on'; } if ($item->getIsLast()) { $classes[] = 'last'; } if ($item->getClass()) { $classes[] = $item->getClass(); } if ($item->hasChildren()) { $classes[] = 'parent'; } return $classes; }
protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass = null) { $css = ''; $children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1; $counter = 1; $childrenCount = $children->count(); $parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-'; foreach ($children as $child) { $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter); if ($child->getId() == 'home-link') { ++$counter; continue; } if ($child->getHeaderBgColor()) { $css .= "li.{$child->getPositionClass()} {\n"; $css .= " background-color: {$child->getHeaderBgColor()} !important;\n"; $css .= "}\n"; } if ($child->getHeaderBgHoverColor()) { $css .= "li.{$child->getPositionClass()}:hover {\n"; $css .= " background-color: {$child->getHeaderBgHoverColor()} !important;\n"; $css .= "}\n"; } $css .= "#wpmm-nav li.{$child->getPositionClass()} > a {\n"; if ($child->getTitleColor()) { $css .= " color: {$child->getTitleColor()} !important;\n"; } $css .= "}\n"; if ($child->getTitleHoverColor()) { $css .= "#wpmm-nav li.{$child->getPositionClass()} > a:hover {\n"; $css .= " color: {$child->getTitleHoverColor()} !important;\n"; $css .= "}\n"; } if ($child->getLevel() == 0) { $css .= "li.{$child->getPositionClass()} > .wpmm-nav-content {\n"; if ($child->getContentBgColor()) { $css .= " background-color: {$child->getContentBgColor()} !important;\n"; } if ($child->getContentBgImage()) { $css .= " background-image: url({$child->getContentBgImage()}) !important;\n"; } switch ($child->getContentBgImgDm()) { case WeltPixel_MegaMenu_Model_Category_Attribute_Source_Display::REPEAT: $css .= " background-repeat: repeat;\n"; break; case WeltPixel_MegaMenu_Model_Category_Attribute_Source_Display::STRETCH: $css .= " background-size: cover;\n"; break; } $css .= "}\n"; } if ($child->hasChildren()) { $css .= $this->_getHtml($child); } ++$counter; } if ($childLevel == 0) { if ($this->getDisplayMode() == WeltPixel_Selector_Model_Adminhtml_System_Config_Displaymode::BOXED) { $css .= "#wpmm-nav {\n"; $css .= " position: relative;\n"; $css .= "}\n"; } } return $css; }
/** * Convert tree node to dropdown option * * @return array */ protected function _treeNodeToOption(Varien_Data_Tree_Node $node, $without) { $option = array(); $option['label'] = $node->getName(); if ($node->getLevel() < 2) { $option['value'] = array(); foreach ($node->getChildren() as $childNode) { if (!in_array($childNode->getId(), $without)) { $option['value'][] = $this->_treeNodeToOption($childNode, $without); } } } else { $option['value'] = $node->getId(); } return $option; }
/** * Move tree node * * @todo Use adapter for generate conditions * @param Varien_Data_Tree_Node $node * @param Varien_Data_Tree_Node $newParent * @param Varien_Data_Tree_Node $prevNode */ public function move($node, $newParent, $prevNode = null) { $position = 1; $oldPath = $node->getData($this->_pathField); $newPath = $newParent->getData($this->_pathField); $newPath = $newPath . '/' . $node->getId(); $oldPathLength = strlen($oldPath); $newLevel = $newParent->getLevel() + 1; $levelDisposition = $newLevel - $node->getLevel(); $data = array($this->_levelField => new Zend_Db_Expr("{$this->_levelField} + '{$levelDisposition}'"), $this->_pathField => new Zend_Db_Expr("CONCAT('{$newPath}', RIGHT({$this->_pathField}, LENGTH({$this->_pathField}) - {$oldPathLength}))")); $condition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$oldPath}(/|\$)"); $this->_conn->beginTransaction(); $reorderData = array($this->_orderField => new Zend_Db_Expr("{$this->_orderField} + 1")); try { if ($prevNode && $prevNode->getId()) { $reorderCondition = "{$this->_orderField} > {$prevNode->getData($this->_orderField)}"; $position = $prevNode->getData($this->_orderField) + 1; } else { $reorderCondition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$newParent->getData($this->_pathField)}/[0-9]+\$"); $select = $this->_conn->select()->from($this->_table, new Zend_Db_Expr("MIN({$this->_orderField})"))->where($reorderCondition); $position = (int) $this->_conn->fetchOne($select); } $this->_conn->update($this->_table, $reorderData, $reorderCondition); $this->_conn->update($this->_table, $data, $condition); $this->_conn->update($this->_table, array($this->_orderField => $position, $this->_levelField => $newLevel), $this->_conn->quoteInto("{$this->_idField} = ?", $node->getId())); $this->_conn->commit(); } catch (Exception $e) { $this->_conn->rollBack(); throw new Exception("Can't move tree node due to error: " . $e->getMessage()); } }
protected function _nodeToArray(Varien_Data_Tree_Node $node) { if (empty($node)) { return array(); } $result = $node->debug(); $result['category_id'] = $node->getId(); $result['parent_id'] = $node->getParentId(); $result['name'] = $node->getName(); $result['is_active'] = $node->getIsActive(); $result['is_anchor'] = $node->getIsAnchor(); $result['url_key'] = $node->getUrlKey(); $result['url'] = $node->getRequestPath(); $result['position'] = $node->getPosition(); $result['level'] = $node->getLevel(); $result['products'] = $node->getProducts(); $result['children'] = array(); foreach ($node->getChildren() as $child) { $result['children'][] = $this->_nodeToArray($child); } return $result; }
/** * Returns array of menu item's classes * * @param Varien_Data_Tree_Node $item * @return array */ protected function _getMenuItemClasses(Varien_Data_Tree_Node $item) { if (Mage::getStoreConfig('mpanel/general/enabled')) { $classes = array(); $classes[] = 'level' . $item->getLevel(); $classes[] = $item->getPositionClass(); if ($item->getIsFirst()) { $classes[] = 'first'; } if ($item->getIsActive()) { $classes[] = 'active'; } if ($item->getIsLast()) { $classes[] = 'last'; } if ($item->getClass()) { $classes[] = $item->getClass(); } if ($item->hasChildren()) { if ($item->getLevel() == 0) { $classes[] = 'dropdown'; } else { $classes[] = 'dropdown-submenu'; } } return $classes; } else { $classes = array(); if ($item->getIsFirst()) { $classes[] = ''; } if ($item->getIsActive()) { $classes[] = 'active'; } if ($item->getIsLast()) { $classes[] = ''; } if ($item->getClass()) { $classes[] = $item->getClass(); } if ($item->hasChildren()) { $classes[] = 'dropdown'; } return $classes; } }
/** * Recursively generates top menu html from data that is specified in $menuTree * * @param Varien_Data_Tree_Node $menuTree * @param string $childrenWrapClass * @return string */ protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass) { $html = ''; $children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1; $counter = 1; $childrenCount = $children->count(); $parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-'; foreach ($children as $child) { $childClass = ''; $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter); $outermostClassCode = ''; $outermostClass = $menuTree->getOutermostClass(); $megamenuData = array('type' => '', 'layout' => 'menu', 'menu' => 1, 'top' => '', 'bottom' => '', 'right' => '', 'percent' => 0); if ($childLevel == 0) { if ($outermostClass) { $childClass .= ' ' . $outermostClass; } $category = Mage::getModel('catalog/category')->load(str_replace('category-node-', '', $child->getId())); $childClass .= ' ' . $category->getOlegnaxmegamenuType(); $megamenuData['type'] = $category->getOlegnaxmegamenuType(); $megamenuData['layout'] = $category->getOlegnaxmegamenuLayout(); $megamenuData['menu'] = $category->getOlegnaxmegamenuMenu(); $megamenuData['top'] = $category->getOlegnaxmegamenuTop(); $megamenuData['bottom'] = $category->getOlegnaxmegamenuBottom(); $megamenuData['right'] = $category->getOlegnaxmegamenuRight(); $megamenuData['percent'] = $category->getOlegnaxmegamenuRightPercent(); if ($megamenuData['menu'] == '') { $megamenuData['menu'] = 1; } if ($megamenuData['percent'] == '') { $megamenuData['percent'] = 0; } if (empty($megamenuData['layout'])) { $megamenuData['layout'] = 'menu'; } } $showChildren = false; $leftClass = $rightClass = $top = $bottom = $right = $menu = ''; if ($child->hasChildren() || $childLevel == 0 && $megamenuData['type'] == 'wide' && (!empty($megamenuData['top']) || !empty($megamenuData['bottom']) || !empty($megamenuData['right']) && $megamenuData['percent'] != 0)) { $showChildren = true; if ($megamenuData['type'] == 'wide') { $leftClass = 'megamenu-block-col-' . (6 - $megamenuData['percent']); $rightClass = 'megamenu-block-col-' . $megamenuData['percent']; $top = $this->_drawMenuBlock('top', $megamenuData['top']); $bottom = $this->_drawMenuBlock('bottom', $megamenuData['bottom']); $right = $this->_drawMenuBlock('right', $megamenuData['right']); } if ($megamenuData['menu'] == 1 || $megamenuData['type'] != 'wide') { $menu .= '<ul class="level' . $childLevel . '">'; $menu .= $this->_getHtml($child, $childrenWrapClass); $menu .= '</ul>'; $menu .= '<div class="clear"></div>'; } if (!$child->hasChildren() || $megamenuData['menu'] != 1) { $childClass .= ' parent parent-fake'; } } $child->setClass($childClass); $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>'; $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>' . $this->escapeHtml($child->getName()) . '</span></a>'; if ($showChildren) { if (!empty($childrenWrapClass)) { $html .= '<div class="' . $childrenWrapClass . '">'; } if ($childLevel == 0 && $megamenuData['type'] == 'wide') { switch ($megamenuData['layout']) { case 'top_menu': $html .= '<div class="megamenu-block-col ' . $leftClass . '">'; $html .= $top; $html .= $menu; $html .= '</div>'; $html .= '<div class="megamenu-block-col ' . $rightClass . '">'; $html .= $right; $html .= '</div>'; $html .= '<div class="clear"></div>'; $html .= $bottom; break; case 'top_menu_bottom': $html .= '<div class="megamenu-block-col ' . $leftClass . '">'; $html .= $top; $html .= $menu; $html .= $bottom; $html .= '</div>'; $html .= '<div class="megamenu-block-col ' . $rightClass . '">'; $html .= $right; $html .= '</div>'; $html .= '<div class="clear"></div>'; break; case 'menu': default: $html .= $top; $html .= '<div class="megamenu-block-col ' . $leftClass . '">'; $html .= $menu; $html .= '</div>'; $html .= '<div class="megamenu-block-col ' . $rightClass . '">'; $html .= $right; $html .= '</div>'; $html .= '<div class="clear"></div>'; $html .= $bottom; } } else { $html .= $menu; } if (!empty($childrenWrapClass)) { $html .= '</div>'; } } $html .= '</li>'; $counter++; } return $html; }
/** * Returns string of menu item's classes * * @param Varien_Data_Tree_Node $item * @return string */ protected function _getMenuItemClasses(Varien_Data_Tree_Node $item) { $classes = 'level' . $item->getLevel() . ' '; if ($item->getIsFirst()) { $classes .= 'first '; } if ($item->getIsActive()) { $classes .= 'active '; } if ($item->getIsLast()) { $classes .= 'last '; } if (!$item->getFullUrl()) { $classes .= 'title '; } if ($item->getCssClass()) { $classes .= $item->getCssClass(); } if ($item->hasChildren()) { $classes .= ' parent'; } return $classes; }
protected function _getMenuItemClasses(Varien_Data_Tree_Node $item) { $classes = array(); $classes[] = 'level' . $item->getLevel(); $classes[] = $item->getPositionClass(); if ($item->getIsFirst()) { $classes[] = 'first'; } if ($item->getIsActive()) { $classes[] = 'active'; } if (Mage::helper('core/url')->getCurrentUrl() == str_replace(Mage::helper('catalog/product')->getProductUrlSuffix(), "", $item->getUrl())) { $classes[] = 'custom-active'; } if ($item->getIsLast()) { $classes[] = 'last'; } if ($item->getClass()) { $classes[] = $item->getClass(); } if ($item->hasChildren()) { $classes[] = 'parent'; } return $classes; }
protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass) { $html = ''; if (Mage::getStoreConfig('meigee_categoriesenhanced/options/status')) { $childrenWrapClass = 'menu-wrapper'; $children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1; $counter = 1; $childrenCount = $children->count(); $parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-'; foreach ($children as $child) { $catId = explode("category-node-", $child->getId()); $categoryComplete = Mage::getModel('catalog/category')->load($catId[1]); if ($categoryComplete->getMeigeeCatCustomlink()) { if ($categoryComplete->getMeigeeCatCustomlink() == '/') { $itemUrl = Mage::getBaseUrl(); } elseif ($categoryComplete->getMeigeeCatCustomlink() == '#') { $itemUrl = '#'; } else { $itemUrl = $categoryComplete->getMeigeeCatCustomlink(); } } else { $itemUrl = $child->getUrl(); } // Get ratio value $ratio = explode("/", $categoryComplete->getMeigeeCatRatio()); $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter); $outermostClassCode = ''; $outermostClass = $menuTree->getOutermostClass(); if ($childLevel == 0 && $outermostClass) { $outermostClassCode = ' class="' . $outermostClass . '" '; $child->setClass($outermostClass); } if ($childLevel == 1) { $html .= '<li class="level1 grid_2 alpha">'; } else { $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>'; } $subTitle = ''; if ($childLevel == 1) { $subTitle = ' class="subtitle"'; } if ($categoryComplete->getMeigeeCatBlockTop() && $childLevel > 0) { $html .= '<div class="top-content">' . $this->helper('cms')->getBlockTemplateProcessor()->filter($categoryComplete->getMeigeeCatBlockTop()) . '</div><div class="clear"></div>'; } if (!$categoryComplete->getMeigeeCatSubcontent()) { $html .= '<a href="' . $itemUrl . '" ' . $outermostClassCode . '><span' . $subTitle . '>' . $this->escapeHtml($child->getName()) . '</span></a>'; } elseif ($categoryComplete->getMeigeeCatSubcontent() && $childLevel == 0) { $html .= '<a href="' . $itemUrl . '" ' . $outermostClassCode . '><span' . $subTitle . '>' . $this->escapeHtml($child->getName()) . '</span></a>'; } if ($child->hasChildren()) { if (!empty($childrenWrapClass) && $childLevel == 0) { $html .= '<div class="' . $childrenWrapClass . '">'; } if ($categoryComplete->getMeigeeCatSubcontent()) { $html .= '<div class="sub-content">' . $this->helper('cms')->getBlockTemplateProcessor()->filter($categoryComplete->getMeigeeCatSubcontent()) . '</div>'; } else { if ($categoryComplete->getMeigeeCatBlockTop() && $childLevel == 0) { $html .= '<div class="top-content">' . $this->helper('cms')->getBlockTemplateProcessor()->filter($categoryComplete->getMeigeeCatBlockTop()) . '</div><div class="clear"></div>'; } if ($categoryComplete->getMeigeeCatBlockRight()) { $html .= '<div class="grid_' . $ratio[0] . ' alpha omega">'; } $html .= '<ul class="level' . $childLevel . '">'; $html .= $this->_getHtml($child, $childrenWrapClass); $html .= '</ul>'; if (!empty($childrenWrapClass) && $childLevel == 0) { if ($categoryComplete->getMeigeeCatBlockRight()) { $html .= '</div>'; $html .= '<div class="grid_' . $ratio[1] . ' alpha omega right-content">' . $this->helper('cms')->getBlockTemplateProcessor()->filter($categoryComplete->getMeigeeCatBlockRight()) . '</div>'; } $html .= '<div class="clear"></div>'; } if ($categoryComplete->getMeigeeCatBlockBottom()) { $html .= '<div class="bottom-content">' . $this->helper('cms')->getBlockTemplateProcessor()->filter($categoryComplete->getMeigeeCatBlockBottom()) . '</div><div class="clear"></div>'; } } if (!empty($childrenWrapClass) && $childLevel == 0) { $html .= '</div>'; } } $html .= '</li>'; $counter++; } } else { $children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1; $counter = 1; $childrenCount = $children->count(); $parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-'; foreach ($children as $child) { $catId = explode("category-node-", $child->getId()); $categoryComplete = Mage::getModel('catalog/category')->load($catId[1]); if ($categoryComplete->getMeigeeCatCustomlink()) { if ($categoryComplete->getMeigeeCatCustomlink() == '/') { $itemUrl = Mage::getBaseUrl(); } if ($categoryComplete->getMeigeeCatCustomlink() == '#') { $itemUrl = '#'; } else { $itemUrl = $categoryComplete->getMeigeeCatCustomlink(); } } else { $itemUrl = $child->getUrl(); } $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter); $outermostClassCode = ''; $outermostClass = $menuTree->getOutermostClass(); if ($childLevel == 0 && $outermostClass) { $outermostClassCode = ' class="' . $outermostClass . '" '; $child->setClass($outermostClass); } $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>'; $html .= '<a href="' . $itemUrl . '" ' . $outermostClassCode . '><span>' . $this->escapeHtml($child->getName()) . '</span></a>'; if ($child->hasChildren()) { if (!empty($childrenWrapClass)) { $html .= '<div class="' . $childrenWrapClass . '">'; } $html .= '<ul class="level' . $childLevel . '">'; $html .= $this->_getHtml($child, $childrenWrapClass); $html .= '</ul>'; if (!empty($childrenWrapClass)) { $html .= '</div>'; } } $html .= '</li>'; $counter++; } } return $html; }
/** * Convert categories tree to array recursively * * @param Varien_Data_Tree_Node $node * @return array */ protected function _getNodesArray($node) { $result = array('id' => (int) $node->getId(), 'parent_id' => (int) $node->getParentId(), 'children_count' => (int) $node->getChildrenCount(), 'is_active' => (bool) $node->getIsActive(), 'name' => $node->getName(), 'level' => (int) $node->getLevel(), 'product_count' => (int) $node->getProductCount()); if (is_array($this->_allowedCategoryIds) && !in_array($result['id'], $this->_allowedCategoryIds)) { $result['disabled'] = true; } if ($node->hasChildren()) { $result['children'] = array(); foreach ($node->getChildren() as $childNode) { $result['children'][] = $this->_getNodesArray($childNode); } } $result['cls'] = ($result['is_active'] ? '' : 'no-') . 'active-category'; $result['expanded'] = !empty($result['children']); return $result; }
protected function _getMenuItemClasses(Varien_Data_Tree_Node $item) { Mage::log('hi', null, 'nil.log'); $classes = array(); $classes[] = 'level' . $item->getLevel(); $classes[] = $item->getPositionClass(); if ($item->getIsFirst()) { $classes[] = 'first'; } if ($item->getIsActive()) { $classes[] = 'active'; } if ($item->getIsLast()) { $classes[] = 'last'; } if ($item->getClass()) { $classes[] = $item->getClass(); } if ($item->hasChildren()) { $classes[] = 'dropdown'; } return $classes; }