';
}
}
if (!empty($htmlChildren)) {
if ($childrenWrapClass) {
$html[] = '
';
}
$html[] = '
';
$html[] = $htmlChildren;
$html[] = '
';
if ($childrenWrapClass) {
$html[] = '
';
}
}
$html[] = '';
$html = implode("\n", $html);
return $html;
}
/**
* Render categories menu in selectbox element
*
* @param int Level number for list item class to start from
* @param string Extra class of outermost list items
* @param string If specified wraps children list in div with this class
* @return string
*/
public function renderCategoriesSelectOptions($level = 0, $outermostItemClass = '', $childrenWrapClass = '')
{
$activeCategories = array();
foreach ($this->getStoreCategories() as $child) {
if ($child->getIsActive()) {
$activeCategories[] = $child;
}
}
$activeCategoriesCount = count($activeCategories);
$hasActiveCategoriesCount = ($activeCategoriesCount > 0);
if (!$hasActiveCategoriesCount) {
return '';
}
$html = '';
$j = 0;
foreach ($activeCategories as $category) {
$html .= $this->_renderCategorySelectOption(
$category,
$level,
($j == $activeCategoriesCount - 1),
($j == 0),
true,
$outermostItemClass,
$childrenWrapClass,
true
);
$j++;
}
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 _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[] = '';
// 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;
}
}