/** * Checks if a category matches criteria: active && url_key not null && included in menu if it has to */ protected static function isCategoryAcceptable(Mage_Catalog_Model_Category $category = null, $mustBeIncludedInNavigation = true) { if (!$category->getIsActive() || is_null($category->getUrlKey()) || $mustBeIncludedInNavigation && !$category->getIncludeInMenu()) { return false; } return true; }
/** * @param Mage_Catalog_Model_Category $category * @param int $level * @return string */ public function drawOpenCategoryItem($category, $level = 0) { if ($this->_isExcluded($category->getId()) || !$category->getIsActive()) { return ''; } $cssClass = array('amshopby-cat', 'level' . $level); $currentCategory = $this->getDataHelper()->getCurrentCategory(); if ($currentCategory->getId() == $category->getId()) { $cssClass[] = 'active'; } if ($this->isCategoryActive($category)) { $cssClass[] = 'parent'; } if ($category->hasChildren()) { $cssClass[] = 'has-child'; } $productCount = ''; if ($this->showProductCount()) { $productCount = $category->getProductCount(); if ($productCount > 0) { $productCount = ' <span class="count">(' . $productCount . ')</span>'; } else { $productCount = ''; } } $html = array(); $html[1] = '<a href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . $productCount . '</a>'; $showAll = Mage::getStoreConfig('amshopby/advanced_categories/show_all_categories'); $showDepth = Mage::getStoreConfig('amshopby/advanced_categories/show_all_categories_depth'); $hasChild = false; $inPath = in_array($category->getId(), $currentCategory->getPathIds()); $showAsAll = $showAll && ($showDepth == 0 || $showDepth > $level + 1); if ($inPath || $showAsAll) { $childrenIds = $category->getChildren(); $children = $this->_getCategoryCollection()->addIdFilter($childrenIds); $this->_getFilterModel()->addCounts($children); $children = $this->asArray($children); if ($children && count($children) > 0) { $hasChild = true; $htmlChildren = ''; foreach ($children as $child) { $htmlChildren .= $this->drawOpenCategoryItem($child, $level + 1); } if ($htmlChildren != '') { $cssClass[] = 'expanded'; $html[2] = '<ol>' . $htmlChildren . '</ol>'; } } } $html[0] = sprintf('<li class="%s">', implode(" ", $cssClass)); $html[3] = '</li>'; ksort($html); if ($category->getProductCount() || $hasChild && $htmlChildren) { $result = implode('', $html); } else { $result = ''; } return $result; }
/** * linktoCategoryThumbnail * * wraps the category thumbnail with a link to the category * * @param Mage_Catalog_Model_Category $category * @param string $linkCss # CSS classes * @param integer|string $width # thumbnail width * @param integer|string $height # thumbnail height * @return string */ public function linktoCategoryThumbnail(Mage_Catalog_Model_Category $category, $linkCss = '', $width = 168, $height = 168) { $link = ''; if ($category->getIsActive()) { $catUrl = $category->getUrl(); $catName = $this->htmlEscape($category->getName()); $catThumbnail = self::displayCategoryThumbnail($category, $width, $height); $link = "\n <a class='{$linkCss}' href='{$catUrl}' title='{$catName}'>\n {$catThumbnail}\n <span class='category-name'>{$catName}</span>\n </a>\n "; } return $link; }
protected function exportData(Mage_Catalog_Model_Category $category, $file, $depth = 0) { $data = array('id' => $category->getId(), 'parent_id' => $category->getParentId(), 'attribute_set_id' => $category->getAttributeSetId(), 'urlPath' => $category->getUrlPath(), 'urlKey' => $category->getUrlKey(), 'path' => $category->getPath(), 'position' => $category->getPosition(), 'page_layout' => $category->getPageLayout(), 'description' => $category->getDescription(), 'display_mode' => $category->getDisplayMode(), 'is_active' => $category->getIsActive(), 'is_anchor' => $category->getIsAnchor(), 'include_in_menu' => $category->getIncludeInMenu(), 'custom_design' => $category->getCustomDesign(), 'level' => $category->getLevel(), 'name' => $category->getName(), 'metaTitle' => $category->getMetaTitle(), 'metaKeywords' => $category->getMetaKeywords(), 'metaDescription' => $category->getMetaDescription()); echo str_repeat(' ', $depth); echo '* ' . $category->getName() . sprintf(' (%s products)', $category->getProductCount()) . PHP_EOL; fputcsv($file, $data); if ($category->hasChildren()) { $children = Mage::getModel('catalog/category')->getCategories($category->getId()); foreach ($children as $child) { $child = Mage::getModel('catalog/category')->load($child->getId()); $this->exportData($child, $file, $depth + 1); } } }
/** * Enter description here... * * @param Mage_Catalog_Model_Category $category * @param int $level * @param boolean $last * @return string */ public function drawItemSingle($category, $level = 0, $last = false) { $html = ''; if (!$category->getIsActive()) { return $html; } if (!$last) { $html .= '┗'; } else { $html .= '┣'; } $html .= '<a href="' . $this->getCategoryUrl($category) . '"><span>' . $this->htmlEscape($category->getName()) . '</span></a><br/>'; return $html; }
/** * Recursively returns a value / label array of all active categories * @param Mage_Catalog_Model_Category $category * @param String $parentname * @return array */ private function getChildCategories($category, $parentname = '') { //category not active - skip it if (!$category->getIsActive()) { return ''; } //array containing all the categories to return $ret = array(); /* Add the current category to return array * Root categories shouldn't be selected */ if ($category->getLevel() > 1) { $ret[$category->getID()] = $category->getName() . $parentname; } // get all children if (Mage::helper('catalog/category_flat')->isEnabled()) { $children = (array) $category->getChildrenNodes(); $childrenCount = count($children); } else { $children = $category->getChildrenCategories(); $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; /** * Use recursion to include all children categories too */ foreach ($activeChildren as $child) { $childarray = $this->getChildCategories($child, " / " . $category->getName() . $parentname); foreach ($childarray as $k => $v) { $ret[$k] = $v; } } return $ret; }
/** * Enter description here... * * @param Mage_Catalog_Model_Category $category * @param int $level * @param boolean $last * @return string */ public function drawItemSingle($category, $level = 0, $last = false) { $html = ''; if (!$category->getIsActive()) { return $html; } if (Mage::helper('catalog/category_flat')->isEnabled()) { $children = $category->getChildrenNodes(); $childrenCount = count($children); } else { $children = $category->getChildren(); $childrenCount = $children->count(); } $hasChildren = $children && $childrenCount; $html .= '<li'; if ($hasChildren) { $html .= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"'; } $html .= ' class="level' . $level; $html .= ' nav-' . str_replace('/', '-', Mage::helper('catalog/category')->getCategoryUrlPath($category->getRequestPath())); if ($this->isCategoryActive($category)) { $html .= ' active'; } if ($last) { $html .= ' last'; } if ($hasChildren) { $cnt = 0; foreach ($children as $child) { if ($child->getIsActive()) { $cnt++; } } if ($cnt > 0) { $html .= ' parent'; } } $html .= '">' . "\n"; $html .= '<a href="' . $this->getCategoryUrl($category) . '"><span>' . $this->htmlEscape($category->getName()) . '</span></a>' . "\n"; $html .= '</li>' . "\n"; return $html; }
/** * Recursively returns a value / label array of all active categories * * @param Mage_Catalog_Model_Category $category * @param String $parentname * @return array */ private function getChildCategories($category, $parentname = '') { //category not active - skip it if (!$category->getIsActive()) { return ''; } //array containing all the categories to return $ret = array(); /* Add the current category to return array * Root categories shouldn't be selected */ if ($category->getLevel() > 1) { $ret[$category->getID()] = ltrim($parentname . " / " . $category->getName(), " / "); } // get all children $children = $category->getChildrenCategories(); $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; /** * Use recursion to include all children categories too */ foreach ($activeChildren as $child) { $childarray = $this->getChildCategories($child, $parentname . " / " . $category->getName()); foreach ($childarray as $k => $v) { $ret[$k] = ltrim($v, " / "); } } return $ret; }
/** * 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 _renderCategorySelectOption($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(); } else { $children = $category->getChildren(); } // select active children $activeChildren = array(); foreach ($children as $child) { if ($child->getIsActive()) { $activeChildren[] = $child; } } $active = ''; if ($this->isCategoryActive($category)) { $active = 'selected="selected"'; } // assemble list item with attributes $html[] = '<option value="' . $this->getCategoryUrl($category) . '" ' . $active . '>' . str_repeat(' ', $level) . $this->escapeHtml($category->getName()) . '</option>'; // render children $htmlChildren = ''; foreach ($activeChildren as $child) { $childHtml = $this->_renderCategorySelectOption($child, $level + 1, 0, 0, false, $outermostItemClass, $childrenWrapClass, $noEventAttributes); $htmlChildren .= $childHtml; } if (!empty($htmlChildren)) { $html[] = $htmlChildren; } $html = implode("\n", $html); return $html; }
/** * @param Mage_Catalog_Model_Category $category * @param int $level * @param bool $isLast * @param bool $isFirst * @param bool $isOutermost * @param string $outermostItemClass * @param string $childrenWrapClass * @param bool $noEventAttributes * @return array|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 Flat Data enabled then use it but only on frontend $flatHelper = Mage::helper('catalog/category_flat'); if ($flatHelper->isAvailable() && $flatHelper->isBuilt(true) && !Mage::app()->getStore()->isAdmin()) { $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>'; // 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; if ($this->brandmanager_category_id == $category->getId()) { $html[] = '<li class="view-all-link">'; $html[] = '<a href="' . $this->getCategoryUrl($category) . '"' . $linkClass . '>'; $html[] = '<span>View All</span>'; $html[] = '</a>'; $html[] = '</li>'; } $html[] = '</ul>'; if ($childrenWrapClass) { $html[] = '</div>'; } } $html[] = '</li>'; $html = implode("\n", $html); return $html; }
/** * Enter description here... * * @param Mage_Catalog_Model_Category $category * @return string */ public function drawOpenCategoryItem($category) { $html = ''; if (!$category->getIsActive()) { return $html; } $html .= '<li'; if ($this->isCategoryActive($category)) { $html .= ' class="active"'; } $html .= '>' . "\n"; $html .= '<a href="' . $this->getCategoryUrl($category) . '"><span>' . $this->htmlEscape($category->getName()) . '</span></a>' . "\n"; if (in_array($category->getId(), $this->getCurrentCategoryPath())) { $children = $category->getChildren(); $hasChildren = $children && $children->count(); if ($hasChildren) { $htmlChildren = ''; foreach ($children as $child) { $htmlChildren .= $this->drawOpenCategoryItem($child); } if (!empty($htmlChildren)) { $html .= '<ul>' . "\n" . $htmlChildren . '</ul>'; } } } $html .= '</li>' . "\n"; return $html; }
/** * 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(); $js = null; $expanded = null; $ulThumb = ''; $image = ''; $thumb = ''; $htmlLi = ''; // 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 $config = Mage::getModel('sidenav/config'); $thumbWidth = 14; $thumbHeight = 14; $liMarginLeft = 0; $ulMarginLeft = 5; $ulPaddingLeft = 10; // define image thumbnail variables if ($config->getThumbImageActive()) { if ($config->getThumbSize()) { $thumbWidth = $config->getThumbWidth(); $thumbHeight = $config->getThumbHeight(); } $thumbnail = $config->load($category->getId())->getThumbnailImageUrl(); $ulThumb = ' ul-thumb'; if (!empty($thumbnail)) { $image = '<img src="' . $thumbnail . '" style= "width:' . $thumbWidth . 'px; height:' . $thumbHeight . 'px; float: left;" />'; $thumb = ' thumb'; if ($config->getCollapsible() && $config->getThumbImageActive()) { $liMarginLeft = $thumbWidth + 3; $ulMarginLeft = 0; } else { $liMarginLeft = 0; $ulMarginLeft = $thumbWidth + 3; } $ulPaddingLeft = 0; } else { $thumb = ' no-thumb'; $liMarginLeft = $thumbWidth + 3; $ulMarginLeft = 0; $ulPaddingLeft = 0; } } $htmlLi .= '<li'; foreach ($attributes as $attrName => $attrValue) { $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . $thumb . '"'; } $htmlLi .= ' style="margin-left: ' . $liMarginLeft . 'px;">'; $html[] = $htmlLi; // add collapsible arrow and wrraper if ($config->getCollapsible()) { $width = 8; $height = 0; $expanded = 0; if ($hasActiveChildren) { $width = 8; $height = 10; } if ($this->isCategoryActive($category)) { $expanded = 1; } $html[] = '<span class="arrow" onClick="expandMenu(this.parentNode)" style="width: ' . $width . 'px; height: ' . $height . 'px;"></span>'; } // add thumbnail image $html[] = $image; // add wrapper if ($config->getCollapsible() || $config->getThumbImageActive()) { $wrapperMargin = $config->getCollapsible() ? 14 : 0; /*if ($config->getThumbImageActive()) { $extraMargin = !empty($thumbnail) ? $thumbWidth + 3 : 0; }*/ $extraMargin = !$config->getThumbImageActive() ? 0 : !empty($thumbnail) ? $thumbWidth + 3 : 0; $collWrapper = $wrapperMargin + $extraMargin; $html[] = '<div class="collapsible-wrapper" style="margin-left: ' . $collWrapper . 'px;">'; } $html[] = '<a href="' . $this->getCategoryUrl($category) . '"' . $linkClass . '><span class="category_name">' . $this->escapeHtml($category->getName()) . '</span></a>'; // $html[] = '<span class="category_name">' . $this->escapeHtml($category->getName()) . '</span></a>'; // $html[] = '</a>'; // add product count if ($config->getShowProductCount()) { $count = Mage::getModel('catalog/layer')->setCurrentCategory($category->getID())->getProductCollection()->getSize(); if ($config->removeZeroCount() && $count > 0 || !$config->removeZeroCount()) { $html[] = '<span class="product-count">(' . $count . ')</span>'; } } // close wrapper if ($config->getCollapsible() || $config->getThumbImageActive()) { $html[] = '</div>'; } // 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 . $ulThumb . '" style="margin-left: ' . $ulMarginLeft . 'px; padding-left: ' . $ulPaddingLeft . 'px;" expanded="' . $expanded . '">'; $html[] = $htmlChildren; $html[] = '</ul>'; if ($childrenWrapClass) { $html[] = '</div>'; } } $html[] = '</li>'; $html = implode("\n", $html); return $html; }
/** * 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 _renderAthleteCategoryMenuItemHtml($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>'; if ($level == 0) { //get category description $ca = Mage::getModel('catalog/category')->load($category->getId()); $description = $ca->getDescription(); if (empty($description) || !Mage::helper('athlete')->getCfg('header/show_description')) { $columns = 4; } else { $columns = 2; } $columnItemsNum = array_fill(0, $columns, floor($activeChildrenCount / $columns)); if ($activeChildrenCount % $columns > 0) { for ($i = 0; $i < $activeChildrenCount % $columns; $i++) { $columnItemsNum[$i]++; } } $this->_columnHtml = array(); } // render children $htmlChildren = ''; $j = 0; //child index $i = 0; //column index $itemsCount = $activeChildrenCount; if (isset($columnItemsNum[$i])) { $itemsCount = $columnItemsNum[$i]; } foreach ($activeChildren as $child) { if ($level == 0) { $isLast = $j + 1 == $itemsCount || $j == $activeChildrenCount - 1; if ($isLast) { $i++; if (isset($columnItemsNum[$i])) { $itemsCount += $columnItemsNum[$i]; } } } else { $isLast = $j == $activeChildrenCount - 1; } $childHtml = $this->_renderAthleteCategoryMenuItemHtml($child, $level + 1, $isLast, $j == 0, false, $outermostItemClass, $childrenWrapClass, $noEventAttributes); if ($level == 0) { //to fix Notice: Indirect modification of overloaded property $this->_columnHtml += array(count($this->_columnHtml) => $childHtml); } else { $htmlChildren .= $childHtml; } $j++; } if ($level == 0 && $this->_columnHtml) { $i = 0; foreach ($columnItemsNum as $columnNum) { $chunk = array_slice($this->_columnHtml, $i, $columnNum); $i += $columnNum; $htmlChildren .= '<li ' . (count($this->_columnHtml) == $i ? 'class="last"' : '') . '><ol>'; foreach ($chunk as $item) { $htmlChildren .= $item; } $htmlChildren .= '</ol></li>'; } } if (!empty($description) && !empty($htmlChildren) && Mage::helper('athlete')->getCfg('header/show_description')) { $htmlChildren .= '<li class="menu-category-description clearfix">' . $description; $htmlChildren .= '<p><button class="button" onclick="window.location=\'' . $this->getCategoryUrl($category) . '\'"><span><span>' . $this->__('learn more') . '</span></span></button></p>'; $htmlChildren .= '</li>'; } 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; }
/** * 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 ''; } $config = $this->getConfig(); $html = array(); $expanded = null; $ulThumb = ''; $image = ''; $thumb = ''; $htmlLi = ''; // get all children if (Mage::helper('catalog/category_flat')->isEnabled()) { $children = (array) $category->getChildrenNodes(); $childrenCount = count($children); } else { $children = $category->getChildren(); if (!$this->_getHelper()->isSearchResultsPage()) { $childrenCount = $children->count(); } else { if (is_string($children)) { $children = explode(',', $children); } $childrenCount = count($children); } } // 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'; } else { if (Mage::registry('current_product') !== null && $config->activeProductCategoriesInDirectAccess()) { $classes = $this->_getCategoryModel()->getProductCategoriesInDirectAccess($category, $classes); } } $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 $thumbWidth = 14; $thumbHeight = 14; $thumbPosition = $config->getThumbPosition(); $liMarginLeft = 0; $ulMarginLeft = 5; $ulPaddingLeft = 10; // define image thumbnail variables if ($config->isThumbImageActive()) { if ($config->getThumbSize()) { $thumbWidth = $config->getThumbWidth(); $thumbHeight = $config->getThumbHeight(); } $thumbnail = $this->_getCategoryModel()->load($category->getId())->getThumbnailImageUrl(); $ulThumb = ' ul-thumb'; if (!empty($thumbnail)) { $image = '<img class="thumb-img-' . $thumbPosition . '" src="' . $thumbnail . '" style= "width:' . $thumbWidth . 'px; height:' . $thumbHeight . 'px; float: ' . $thumbPosition . ';" />'; $thumb = ' thumb'; if ($thumbPosition === 'left') { if ($config->isCollapsible() && $config->isThumbImageActive()) { $liMarginLeft = $thumbWidth + 3; $ulMarginLeft = 0; } else { $liMarginLeft = 0; $ulMarginLeft = $thumbWidth + 3; } $ulPaddingLeft = 0; } } else { $thumb = ' no-thumb'; $liMarginLeft = $thumbPosition === 'right' ? 0 : $thumbWidth + 3; if ($thumbPosition === 'left') { $ulMarginLeft = 0; $ulPaddingLeft = 0; } } } $collapsibleClass = ''; if ($config->isCollapsible()) { $collapsibleClass = ' collapsible'; } // add collapsible arrow and wrraper $arrow = ''; $extraStyle = ''; $collapsibleIconPosition = $config->getCollapsibleIconPosition(); if ($config->isCollapsible()) { $width = $config->getCollapsibleIconType() === 'arrow' ? 8 : 16; $height = 0; $expanded = 0; if ($hasActiveChildren) { $width = $config->getCollapsibleIconType() === 'arrow' ? 8 : 16; $height = 16; } if ($height == 0) { $extraStyle = ' display:none;'; } if ($height == 0 && $collapsibleIconPosition === 'left') { $liMarginLeft += $width; } if ($this->isCategoryActive($category)) { $expanded = 1; } $expanded = ' expanded="' . $expanded . '"'; $spanOnclick = 'onclick="Codnitive.expandMenu(this.parentNode)'; $spanClass = $config->getCollapsibleIconType() . '-' . $collapsibleIconPosition; $arrow = '<span class="' . $spanClass . ' " ' . $spanOnclick . '" style="width: ' . $width . 'px; height: ' . $height . 'px;' . $extraStyle . '"></span>'; } $htmlLi .= '<li'; foreach ($attributes as $attrName => $attrValue) { $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . $thumb . $collapsibleClass . '"'; } $htmlLi .= ' style="margin-left: ' . $liMarginLeft . 'px;' . '">'; $html[] = $htmlLi; $html[] = $arrow; // add wrapper $aClass = ''; $aStyle = ''; $onclick = ''; if ($config->isCollapsible() || $config->isThumbImageActive()) { $wrapperMargin = $config->isCollapsible() && $collapsibleIconPosition === 'left' ? 14 : 0; $extraMargin = !$config->isThumbImageActive() ? 0 : !empty($thumbnail) && $thumbPosition === 'left' ? $thumbWidth + 3 : 0; $collWrapper = $wrapperMargin + $extraMargin; // makes parent category name clickable to open/close collapsible menus if option is enabled $collapseName = ''; if ($hasActiveChildren && $config->isCollapsible() && $config->expandByParentName()) { $onclick = ' onclick="Codnitive.expandMenu(this.parentNode);return false;"'; $collapseName = ' collapse-name'; } $aClass = 'class="collapsible-wrapper' . $collapseName . '"'; $aStyle = ' style="margin-left: ' . $collWrapper . 'px;"'; } $html[] = '<a ' . $aClass . $onclick . 'href="' . $this->getCategoryUrl($category) . '"' . $linkClass . '>' . '<span class="category_name">' . $this->escapeHtml($category->getName()) . '</span></a>'; // add thumbnail image $html[] = $image; // add product count if ($config->showProductCount()) { $count = Mage::getModel('catalog/layer')->setCurrentCategory($category->getID())->getProductCollection()->getSize(); if ($config->removeZeroCount() && $count > 0 || !$config->removeZeroCount()) { $html[] = '<span class="product-count">(' . $count . ')</span>'; } } // 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 . $ulThumb . $collapsibleClass . '" style="margin-left: ' . $ulMarginLeft . 'px; padding-left: ' . $ulPaddingLeft . 'px;"' . $expanded . '>'; $html[] = $htmlChildren; $html[] = '</ul>'; if ($childrenWrapClass) { $html[] = '</div>'; } } $html[] = '</li>'; $html = implode("\n", $html); return $html; }
/** * @param Mage_Catalog_Model_Category $category * @param $isSelected * @param int $level * @param bool $isFolded * @param bool $addCount * @return array|null */ protected function _prepareItemData($category, $isSelected, $level = 1, $isFolded = false, $addCount = false) { $row = null; /* * Display only active category and having products or being parents */ if ($category->getIsActive() && (!$addCount || $category->getProductCount())) { $row = array('label' => Mage::helper('core')->htmlEscape($category->getName()), 'value' => $this->getCategoryUrl($category), 'count' => $addCount ? $this->_getProductCount($category) : 0, 'level' => $level, 'id' => $category->getId(), 'parent_id' => $category->getParentId(), 'is_folded' => $isFolded, 'is_selected' => $isSelected); } return $row; }
/** * Fill the Field is_active in the given array * param $isRoot = false not needed here * * @param Mage_Catalog_Model_Category $category */ protected function _setIsActive($category) { $catIds = Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_HIDDEN_CATEGORIES); $catIdsArray = array(); if (!empty($cat_ids)) { $catIdsArray = explode(",", $catIds); foreach ($catIdsArray as &$catId) { $catId = trim($catId); } } $isActive = $category->getIsActive(); if (in_array($category->getId(), $catIdsArray) || array_intersect($catIdsArray, $category->getParentIds())) { $isActive = 1; } if (Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_NAVIGATION_CATEGORIES_ONLY) && !$category->getIncludeInMenu()) { $isActive = 0; } $this->_defaultRow["is_active"] = $isActive; }
/** * 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 */ public 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(); if ($level == 0) { $classes[] = 'title'; } $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'; } if ($this->isCategoryActive($category)) { $classes[] = 'current'; } $classes[] = 'collapse closed'; // 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)'; } if ($level == 0) { $category_data = Mage::getModel('catalog/category')->load($category->getId()); } if ($level == 0) { $html[] = '<li class="col"><ul>'; } // assemble list item with attributes $htmlLi = '<li'; foreach ($attributes as $attrName => $attrValue) { $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . '"'; } $htmlLi .= '>'; $html[] = $htmlLi; if ($level == 0) { if ($category_icon = $category_data->getBs_category_icon()) { $html[] = '<img class="icon" alt="" width="28" src="' . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'wysiwyg/ev_category_icons/' . $category_icon . '">'; } } $html[] = '<a class="collapse closed" href="' . $this->getCategoryUrl($category) . '">' . $this->escapeHtml($category->getName()); if ($level == 0) { $label = $category_data->getBs_category_lable(); if (!empty($label)) { $html[] = '<span class="hot"> ' . $label . ' </span>'; } } $html[] = '</a>'; if ($level != 0 && $hasChildren) { $html[] = '<span class="minus click">–</span><span class="plus click">+</span>'; } // 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 ($level != 0) { $html[] = '<ul class="nav nav-list">'; } $html[] = $htmlChildren; if ($level != 0) { $html[] = '</ul>'; } } $html[] = '</li>'; if ($level == 0) { $html[] = '</li></ul>'; } $html = implode("\n", $html); return $html; }
/** * Add project specific formatting * * @param Mage_Catalog_Model_Category $category * @param int $level * @param array $levelClass * @return string */ public function drawOpenCategoryItem($category, $level = 0, array $levelClass = NULL) { $html = array(); if ($this->_checkLoginCatalog()) { return ''; } if (!$category->getIsActive()) { return ''; } if (!$category->getIncludeInMenu()) { return ''; } if (!isset($levelClass)) { $levelClass = array(); } $combineClasses = array(); $combineClasses[] = 'level' . $level; if ($this->_isCurrentCategory($category)) { $combineClasses[] = 'active'; } else { $combineClasses[] = $this->isCategoryActive($category) ? 'parent' : 'inactive'; } $levelClass[] = implode('-', $combineClasses); if ($category->hasChildren()) { $levelClass[] = 'has-children'; } $levelClass = array_merge($levelClass, $combineClasses); $levelClass[] = $this->_getClassNameFromCategoryName($category); $productCount = ''; if ($this->displayProductCount()) { $num = Mage::getModel('catalog/layer')->setCurrentCategory($category->getId())->getProductCollection()->getSize(); $productCount = '<span class="product-count"> (' . $num . ')</span>'; } // indent HTML! $html[1] = str_pad("", $level * 2 + 4, " ") . '<span class="vertnav-cat"><a href="' . $this->getCategoryUrl($category) . '"><span>' . $this->escapeHtml($category->getName()) . '</span></a>' . $productCount . "</span>\n"; $autoMaxDepth = Mage::getStoreConfig('catalog/vertnav/expand_all_max_depth'); $autoExpand = Mage::getStoreConfig('catalog/vertnav/expand_all'); if (in_array($category->getId(), $this->getCurrentCategoryPath()) || $autoExpand && $autoMaxDepth == 0 || $autoExpand && $autoMaxDepth > $level + 1) { $children = $this->_getCategoryCollection()->addIdFilter($category->getChildren()); $children = $this->toLinearArray($children); //usort($children, array($this, '_sortCategoryArrayByName')); $childrenCount = 0; $hasChildren = $children && ($childrenCount = count($children)); if ($hasChildren) { $children = $this->toLinearArray($children); $htmlChildren = ''; foreach ($children as $i => $child) { $class = array(); if ($childrenCount == 1) { $class[] = 'only'; } else { if (!$i) { $class[] = 'first'; } if ($i == $childrenCount - 1) { $class[] = 'last'; } } if (isset($children[$i + 1]) && $this->isCategoryActive($children[$i + 1])) { $class[] = 'prev'; } if (isset($children[$i - 1]) && $this->isCategoryActive($children[$i - 1])) { $class[] = 'next'; } $htmlChildren .= $this->drawOpenCategoryItem($child, $level + 1, $class); } if (!empty($htmlChildren)) { $levelClass[] = 'open'; // indent HTML! $html[2] = str_pad("", $level * 2 + 2, " ") . '<ul>' . "\n" . $htmlChildren . "\n" . str_pad("", $level * 2 + 2, " ") . '</ul>'; } } } // indent HTML! $html[0] = str_pad("", $level * 2 + 2, " ") . sprintf('<li class="%s">', implode(" ", $levelClass)) . "\n"; // indent HTML! $html[3] = "\n" . str_pad("", $level * 2 + 2, " ") . '</li>' . "\n"; ksort($html); return implode('', $html); }
/** * Enter description here... * * @param Mage_Catalog_Model_Category $category * @param int $level * @param boolean $last * @return string */ public function drawItem($category, $level = 0, $last = false) { $html = ''; if (!$category->getIsActive()) { return $html; } if (Mage::helper('catalog/category_flat')->isEnabled()) { $children = $category->getChildrenNodes(); $childrenCount = count($children); } else { $children = $category->getChildren(); $childrenCount = $children->count(); } $hasChildren = $children && $childrenCount; $html .= '<li'; $html .= ' class="item'; $html .= ' nav-' . str_replace('/', '-', Mage::helper('catalog/category')->getCategoryUrlPath($category->getRequestPath())); if ($this->isCategoryActive($category)) { $html .= ' active'; } if ($last) { $html .= ' last'; } if ($hasChildren) { $cnt = 0; foreach ($children as $child) { if ($child->getIsActive()) { $cnt++; } } if ($cnt > 0) { $html .= ' hasChild'; } } $html .= '">' . "\n"; if ($level == 0) { if ($hasChildren) { $html .= '<a class="item" href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . '</a>' . "\n"; //$html.= '<span class="collapse">collapse</span>'; } else { $html .= '<a class="item" href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . '</a>' . "\n"; } } else { if ($hasChildren) { $html .= '<a class="item" href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . '</a>' . "\n"; //$html.= '<span class="collapse">collapse</span>'; } else { $html .= '<a class="item" href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . '</a>' . "\n"; } } if ($hasChildren) { $j = 0; $htmlChildren = ''; foreach ($children as $child) { if ($child->getIsActive()) { $htmlChildren .= $this->drawItem($child, $level + 1, ++$j >= $cnt); } } if (!empty($htmlChildren)) { $html .= '<ul class="detail-parent">' . "\n" . $htmlChildren . '</ul>'; } } $html .= '</li>' . "\n"; return $html; }
/** * 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 */ public 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'; } if ($this->_type == 'leftmenu') { if ($this->isCategoryActive($category)) { $classes[] = 'current'; } } elseif ($this->_type == 'megamenu' && $level == 1) { $classes[] = 'title'; } // 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; $flag = 'closed'; if ($this->isCategoryActive($category)) { $flag = 'opened'; } $html[] = '<label class="tree-toggler nav-header ' . $flag . '"> <a href="' . $this->getCategoryUrl($category) . '">' . $this->escapeHtml($category->getName()) . '</a></label>'; // 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="nav nav-list">'; $html[] = $htmlChildren; $html[] = '</ul>'; if ($childrenWrapClass) { $html[] = '</div>'; } } $html[] = '</li>'; $html = implode("\n", $html); return $html; }
/** * Check if a category can be shown or not. * * @param Mage_Catalog_Model_Category $category * The category to check * @return boolean TRUE if the category can be shown */ protected function _canShow(Mage_Catalog_Model_Category $category) { // check if the category is new if (!$category->getId()) { // if yes, return FALSE return false; } // check if the category is active if (!$category->getIsActive()) { // if yes, return FALSE return false; } // else return TRUE return true; }
/** * 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 ''; } $category_ids = array(); $postData = Mage::app()->getRequest()->getPost('filter_cat'); foreach ($postData as $posdata) { array_push($category_ids, $posdata); } $config = $this->getConfig(); $html = array(); $expanded = null; $ulThumb = ''; $image = ''; $thumb = ''; $htmlLi = ''; // get all children if (Mage::helper('catalog/category_flat')->isEnabled()) { $children = (array) $category->getChildrenNodes(); $childrenCount = count($children); } else { $children = $category->getChildren(); if (!$this->_getHelper()->isSearchResultsPage()) { $childrenCount = $children->count(); } else { if (is_string($children)) { $children = explode(',', $children); } $childrenCount = count($children); } } // 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'; } else { if (Mage::registry('current_product') !== null && $config->activeProductCategoriesInDirectAccess()) { $classes = $this->_getCategoryModel()->getProductCategoriesInDirectAccess($category, $classes); } } $linkClass = ''; if ($isOutermost && $outermostItemClass) { $classes[] = $outermostItemClass; $linkClass = ' class="' . $outermostItemClass . '"'; } if ($isFirst) { $classes[] = 'first'; } if ($isLast) { $classes[] = 'last'; } if ($hasActiveChildren) { $classes[] = 'parent has-sub'; } // 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 $thumbWidth = 14; $thumbHeight = 14; $thumbPosition = $config->getThumbPosition(); $liMarginLeft = 0; $ulMarginLeft = 5; $ulPaddingLeft = 10; // define image thumbnail variables if ($config->isThumbImageActive()) { if ($config->getThumbSize()) { $thumbWidth = $config->getThumbWidth(); $thumbHeight = $config->getThumbHeight(); } $thumbnail = $this->_getCategoryModel()->load($category->getId())->getThumbnailImageUrl(); $ulThumb = ' ul-thumb'; if (!empty($thumbnail)) { $image = '<img class="thumb-img-' . $thumbPosition . '" src="' . $thumbnail . '" style= "width:' . $thumbWidth . 'px; height:' . $thumbHeight . 'px; float: ' . $thumbPosition . ';" />'; $thumb = ' thumb'; if ($thumbPosition === 'left') { if ($config->isCollapsible() && $config->isThumbImageActive()) { $liMarginLeft = $thumbWidth + 3; $ulMarginLeft = 0; } else { $liMarginLeft = 0; $ulMarginLeft = $thumbWidth + 3; } $ulPaddingLeft = 0; } } else { $thumb = ' no-thumb'; $liMarginLeft = $thumbPosition === 'right' ? 0 : $thumbWidth + 3; if ($thumbPosition === 'left') { $ulMarginLeft = 0; $ulPaddingLeft = 0; } } } $collapsibleClass = ''; if ($config->isCollapsible()) { $collapsibleClass = ' collapsible'; } if ($level == 0) { $ulMarginLeft = 0; $ulPaddingLeft = 0; } // add collapsible arrow and wrraper $arrow = ''; $extraStyle = ''; $checkbox = ''; $label_start = '<span>'; $label_end = '</span>'; $collapsibleIconPosition = $config->getCollapsibleIconPosition(); if ($config->isCollapsible() && $category->getId() == 18) { $width = $config->getCollapsibleIconType() === 'arrow' ? 8 : 16; $height = 0; $expanded = 0; if ($hasActiveChildren) { $width = $config->getCollapsibleIconType() === 'arrow' ? 8 : 16; $height = 16; } if ($height == 0) { $extraStyle = ' display:none;'; } if ($height == 0 && $collapsibleIconPosition === 'left') { $liMarginLeft += $width; } if ($this->isCategoryActive($category)) { $expanded = 1; } $expanded = ' expanded="' . $expanded . '"'; $spanOnclick = 'onclick="Codnitive.expandMenu(this.parentNode)'; $spanClass = $config->getCollapsibleIconType() . '-' . $collapsibleIconPosition; $arrow = '<span class="' . $spanClass . ' " ' . $spanOnclick . '" style="width: ' . $width . 'px; height: ' . $height . 'px;' . $extraStyle . '"></span>'; } if ($category->getId() != 10 && $category->getId() != 15) { $htmlLi .= '<li'; foreach ($attributes as $attrName => $attrValue) { $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . $thumb . $collapsibleClass . '"'; } $selected = in_array($category->getId(), $category_ids) ? 'checked="checked"' : ''; $checkbox = strpos($attrValue, "level2") === false ? '' : '<input id="check' . $category->getId() . '"class="css-checkbox" type="checkbox" name="filter_cat[]" value="' . $category->getId() . '" ' . $selected . '/>'; $htmlLi .= ' style="margin-left: ' . $liMarginLeft . 'px;' . '">'; $html[] = $htmlLi; $html[] = $arrow; // add wrapper $aClass = ''; $aStyle = ''; $onclick = ''; if ($config->isCollapsible() || $config->isThumbImageActive()) { $wrapperMargin = $config->isCollapsible() && $collapsibleIconPosition === 'left' ? 14 : 0; $extraMargin = !$config->isThumbImageActive() ? 0 : !empty($thumbnail) && $thumbPosition === 'left' ? $thumbWidth + 3 : 0; $collWrapper = $wrapperMargin + $extraMargin; // makes parent category name clickable to open/close collapsible menus if option is enabled $collapseName = ''; if ($hasActiveChildren && $config->isCollapsible() && $config->expandByParentName()) { $onclick = ' onclick="Codnitive.expandMenu(this.parentNode);return false;"'; $collapseName = ' collapse-name'; } $hidebottom_line = $category->getId() == 18 ? "border-bottom: 0px!important;" : ""; $aClass = 'class="collapsible-wrapper' . $collapseName . '"'; $aStyle = ' style="margin-left: ' . $collWrapper . 'px;"' . $hidebottom_line . ''; } $cat_link = $this->getCategoryUrl($category); if ($checkbox != "") { $label_start = '<label for="check' . $category->getId() . '" class="css-label">'; $label_end = '</label>'; $cat_link = '#'; } $hide = $category->getId() == 13 ? "style='display:none;'" : ""; $html[] = '<a ' . $hidebottom_line . ' ' . $hide . ' ' . $aClass . $onclick . 'href="' . $cat_link . '"' . $linkClass . '>' . $checkbox . $label_start . '' . $this->escapeHtml($category->getName()) . $label_end . '</a>'; // add thumbnail image $html[] = $image; // add product count if ($config->showProductCount()) { $count = Mage::getModel('catalog/layer')->setCurrentCategory($category->getID())->getProductCollection()->getSize(); if ($config->removeZeroCount() && $count > 0 || !$config->removeZeroCount()) { $html[] = '<span class="product-count">(' . $count . ')</span>'; } } // 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 . '">'; } echo $ulThumb; if (strpos($htmlChildren, 'checked')) { $expanded = "display:block;expanded=1"; } //set padding and margin to 0 if level 1 -monarc $html[] = '<ul class="level' . $level . $ulThumb . $collapsibleClass . '" style="margin-left: ' . $ulMarginLeft . 'px; padding-left: ' . $ulPaddingLeft . 'px;"' . $expanded . '>'; $html[] = $htmlChildren; $html[] = '</ul>'; if ($childrenWrapClass) { $html[] = '</div>'; } } $html[] = '</li>'; if ($category->getId() == 18) { $htmlLi .= '<li > <ul class="buttons" style="margin:0px;padding:0px;"> <li><a href="#"><input type="button" value="CLEAR" name="clear_all" id="clearme"></a></li> <li><a href="#"><input type="submit" value="FILTER" name="filter"></a></li> </ul> </li>'; $html[] = $htmlLi; } } $html = implode("\n", $html); return $html; }