Bottom Category on left navigation is always openif no child categories then return categories of same levelExclude a specific categoryTop Menu cache problemCreate categories through installerScript to hide empty categories works but not with products without stockAdd category id to product item classLooking to create a Category Attribute that will allow me to change the style of my dropdown navigationMagento 2 get category count getChildCategories()Call to undefined method Collection::getData()Pagination count issue in custom varient collection

Have astronauts in space suits ever taken selfies? If so, how?

What's the output of a record cartridge playing an out-of-speed record

Why Is Death Allowed In the Matrix?

How can I make my BBEG immortal short of making them a Lich or Vampire?

What does it mean to describe someone as a butt steak?

What do you call a Matrix-like slowdown and camera movement effect?

In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?

Why doesn't H₄O²⁺ exist?

Show that if two triangles built on parallel lines, with equal bases have the same perimeter only if they are congruent.

strToHex ( string to it's hex representation as string)

Why did Neo believe he could trust the machine when he asked for peace?

Adding span tags within wp_list_pages list items

Can divisibility rules for digits be generalized to sum of digits

Is it unprofessional to ask if a job posting on GlassDoor is real?

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

Why does Kotter return in Welcome Back Kotter?

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

Is this a crack on the carbon frame?

What does "Puller Prush Person" mean?

To string or not to string

What is the offset in a seaplane's hull?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Is it important to consider tone, melody, and musical form while writing a song?

How can bays and straits be determined in a procedurally generated map?



Bottom Category on left navigation is always open


if no child categories then return categories of same levelExclude a specific categoryTop Menu cache problemCreate categories through installerScript to hide empty categories works but not with products without stockAdd category id to product item classLooking to create a Category Attribute that will allow me to change the style of my dropdown navigationMagento 2 get category count getChildCategories()Call to undefined method Collection::getData()Pagination count issue in custom varient collection






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I have a problem on my product categories page the navigation that we have going down the left side displays all the categories we need it to and also it bold a subcategory when you are on it, However when you are not on any sub categories and you are on the main categories page The bottom category is always in bold even when you are not on it.



This is my code which creates the navigation (this is a .phtml file)



<?php
ob_start();

$store_categories = $this->getLeftCategories();
if ($count = count($store_categories))

$block_title = $this->getBlockTitle();
if ( empty($block_title) ) $block_title = 'Categories';
?>
<div class="block block-left-nav">
<div class="block-title">
<strong><span><?php echo $this->__($block_title) ?></span></strong>
</div>
<div class="block-content">
<ul id="left-nav">
<?php
$i=0;
foreach ($store_categories as $_category)
$class = array();
if (!$i)
$class[] = 'first';
elseif ($i == $count)
$class[] = 'last';

echo $this->drawOpenCategoryItem($_category, 0, $class);
$i++;
?>
</ul>
</div>
</div>
<?php

// if ($count = count($store_categories)) {
$mdms_blocks = Mage::registry('mdms_blocks');
if ( !$mdms_blocks )
$mdms_blocks = array();
else
Mage::unregister('mdms_blocks');

$mdms_blocks['block_left_nav'] = ob_get_clean();
Mage::register('mdms_blocks', $mdms_blocks);


I assume that what opens the categories is the drawOpenCategoryItem function



This is the code in the navigation.php which has that function in it but i cant see anything wrong.



<?php
/**
* @version 1.0 12.0.2012
* @author
* @copyright Copyright (C) 2010 - 2012
*/

class our_ThemeSettings_Block_Navigation extends Mage_Catalog_Block_Navigation


/**
* columns html
*
* @var array
*/
protected $_columnHtml;

/*
* @var Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
protected $_leftCategories;

/**
* top level parent category for current category
*
* @var int
*/
protected $_parent;

protected function _construct()

$path = $this->getCurrentCategoryPath();
$parent = $path[count($path)-2];
if (!$parent)
$parent = Mage::app()->getStore()->getRootCategoryId();

$this->_parent = $parent;



/**
* render category html
*
* @param Mage_Catalog_Model_Category $category
* @param integer $level
* @param array $levelClass
* @return string
*/
public function drawOpenCategoryItem($category, $level = 0, array $levelClass = null)

$html = array();

if (!$category->getIsActive()) 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);
$levelClass = array_merge($levelClass, $combineClasses);
$levelClass[] = $this->_getClassNameFromCategoryName($category);

$html[1] = '<a href="' . $this->getCategoryUrl($category) . '">' . $this->escapeHtml($category->getName()) . '</a>' . "n";

if ( in_array($category->getId(), $this->getCurrentCategoryPath()) )
$children = $this->_getLeftCategoryCollection()
->addIdFilter($category->getChildren());

$hasChildren = $children && ($childrenCount = count($children));
if ($hasChildren)
$htmlChildren = '';

foreach ($children as $i => $child)

$class = array();
if ($childrenCount == 1)
$class[] = 'only';

else

if (!$i) $class[] = 'first';
if ($i == $childrenCount - 1) $class[] = 'last';

$htmlChildren .= $this->drawOpenCategoryItem($child, $level + 1, $class);


if (!empty($htmlChildren))
$levelClass[] = 'open';

$html[2] = '<ul>' . "n"
. $htmlChildren . "n"
. '</ul>';




$html[0] = sprintf('<li class="%s">', implode(" ", $levelClass)) . "n";
$html[3] = "n" . '</li>' . "n";

ksort($html);
return implode('', $html);


/**
* Convert the category name into a string that can be used as a css class
*
* @param Mage_Catalog_Model_Category $category
* @return string
*/
protected function _getClassNameFromCategoryName($category)

$name = $category->getName();
$name = preg_replace('/-2,/', '-', preg_replace('/[^a-z-]/', '-', strtolower($name)));
while ($name && $name0 == '-') $name = substr($name, 1);
while ($name && substr($name, -1) == '-') $name = substr($name, 0, -1);
return $name;


/**
* Check if the current category matches the passed in category
*
* @param Mage_Catalog_Model_Category $category
* @return bool
*/
protected function _isCurrentCategory($category)

return ($cat = $this->getCurrentCategory()) && $cat->getId() == $category->getId();


/**
* return top level category name
*
* @return string
*/
public function getBlockTitle()
if ( $this->_parent == Mage::app()->getStore()->getRootCategoryId() )
return '';
else
return Mage::getModel('catalog/category')->load($this->_parent)->getName();



/**
* Get sibling catagories
*
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
public function getLeftCategories()
$parent['include_in_menu'] == 0 )
return null;

if (!isset($this->_leftCategories))
$this->_leftCategories = $this->_getLeftCategoryCollection()
->addIdFilter($parent->getChildren());

return $this->_leftCategories;


/**
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
protected function _getLeftCategoryCollection()

$collection = Mage::getResourceModel('catalog/category_collection');
$collection->addAttributeToSelect('url_key')
->addAttributeToSelect('name')
->addAttributeToSelect('all_children')
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1)
->setOrder('position', 'ASC')
->joinUrlRewrite();
return $collection;


/**
* 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>';

$columnItemsNum = array();
if ($level == 0 && $activeChildrenCount)
$items_per_column = Mage::getStoreConfig('theme/navigation/column_items');
$columns = ceil($activeChildrenCount / $items_per_column);
$columnItemsNum = array_fill(0, $columns, $items_per_column);
$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) else
$isLast = ($j == $activeChildrenCount - 1);


$childHtml = $this->_renderCategoryMenuItemHtml(
$child,
($level + 1),
$isLast,
($j == 0),
false,
$outermostItemClass,
$childrenWrapClass,
$noEventAttributes
);
if ($level == 0)
$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($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 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 = '<option value="">' . $this->__('- Please select category -') . '</option>';
$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[] = '<option value="'.$this->getCategoryUrl($category).'" '.$active.'>' . str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;',$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;






If you can see anything which maybe causing this problem could you let me know please as i am lost with this problem.



Thank you










share|improve this question
















bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • inspect this subcategory, see if there is any supernumerary class added to the element.

    – Julien Lachal
    Oct 14 '14 at 12:02











  • The class change from inactive to active on the bottom category, same as when you are actually in the category

    – Adam Allen
    Oct 14 '14 at 12:19











  • Can you add either a image or add a url

    – Renon Stewart
    Oct 14 '14 at 14:00











  • @R.S what an screen shot of the problem? cant give out URL because the site isnt live yet and is password protected

    – Adam Allen
    Oct 14 '14 at 14:01












  • Probably the function _isCurrentCategory gets wrong category $cat = $this->getCurrentCategory(); from the registry? What does this code return?

    – Amasty
    Oct 14 '14 at 14:21

















3















I have a problem on my product categories page the navigation that we have going down the left side displays all the categories we need it to and also it bold a subcategory when you are on it, However when you are not on any sub categories and you are on the main categories page The bottom category is always in bold even when you are not on it.



This is my code which creates the navigation (this is a .phtml file)



<?php
ob_start();

$store_categories = $this->getLeftCategories();
if ($count = count($store_categories))

$block_title = $this->getBlockTitle();
if ( empty($block_title) ) $block_title = 'Categories';
?>
<div class="block block-left-nav">
<div class="block-title">
<strong><span><?php echo $this->__($block_title) ?></span></strong>
</div>
<div class="block-content">
<ul id="left-nav">
<?php
$i=0;
foreach ($store_categories as $_category)
$class = array();
if (!$i)
$class[] = 'first';
elseif ($i == $count)
$class[] = 'last';

echo $this->drawOpenCategoryItem($_category, 0, $class);
$i++;
?>
</ul>
</div>
</div>
<?php

// if ($count = count($store_categories)) {
$mdms_blocks = Mage::registry('mdms_blocks');
if ( !$mdms_blocks )
$mdms_blocks = array();
else
Mage::unregister('mdms_blocks');

$mdms_blocks['block_left_nav'] = ob_get_clean();
Mage::register('mdms_blocks', $mdms_blocks);


I assume that what opens the categories is the drawOpenCategoryItem function



This is the code in the navigation.php which has that function in it but i cant see anything wrong.



<?php
/**
* @version 1.0 12.0.2012
* @author
* @copyright Copyright (C) 2010 - 2012
*/

class our_ThemeSettings_Block_Navigation extends Mage_Catalog_Block_Navigation


/**
* columns html
*
* @var array
*/
protected $_columnHtml;

/*
* @var Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
protected $_leftCategories;

/**
* top level parent category for current category
*
* @var int
*/
protected $_parent;

protected function _construct()

$path = $this->getCurrentCategoryPath();
$parent = $path[count($path)-2];
if (!$parent)
$parent = Mage::app()->getStore()->getRootCategoryId();

$this->_parent = $parent;



/**
* render category html
*
* @param Mage_Catalog_Model_Category $category
* @param integer $level
* @param array $levelClass
* @return string
*/
public function drawOpenCategoryItem($category, $level = 0, array $levelClass = null)

$html = array();

if (!$category->getIsActive()) 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);
$levelClass = array_merge($levelClass, $combineClasses);
$levelClass[] = $this->_getClassNameFromCategoryName($category);

$html[1] = '<a href="' . $this->getCategoryUrl($category) . '">' . $this->escapeHtml($category->getName()) . '</a>' . "n";

if ( in_array($category->getId(), $this->getCurrentCategoryPath()) )
$children = $this->_getLeftCategoryCollection()
->addIdFilter($category->getChildren());

$hasChildren = $children && ($childrenCount = count($children));
if ($hasChildren)
$htmlChildren = '';

foreach ($children as $i => $child)

$class = array();
if ($childrenCount == 1)
$class[] = 'only';

else

if (!$i) $class[] = 'first';
if ($i == $childrenCount - 1) $class[] = 'last';

$htmlChildren .= $this->drawOpenCategoryItem($child, $level + 1, $class);


if (!empty($htmlChildren))
$levelClass[] = 'open';

$html[2] = '<ul>' . "n"
. $htmlChildren . "n"
. '</ul>';




$html[0] = sprintf('<li class="%s">', implode(" ", $levelClass)) . "n";
$html[3] = "n" . '</li>' . "n";

ksort($html);
return implode('', $html);


/**
* Convert the category name into a string that can be used as a css class
*
* @param Mage_Catalog_Model_Category $category
* @return string
*/
protected function _getClassNameFromCategoryName($category)

$name = $category->getName();
$name = preg_replace('/-2,/', '-', preg_replace('/[^a-z-]/', '-', strtolower($name)));
while ($name && $name0 == '-') $name = substr($name, 1);
while ($name && substr($name, -1) == '-') $name = substr($name, 0, -1);
return $name;


/**
* Check if the current category matches the passed in category
*
* @param Mage_Catalog_Model_Category $category
* @return bool
*/
protected function _isCurrentCategory($category)

return ($cat = $this->getCurrentCategory()) && $cat->getId() == $category->getId();


/**
* return top level category name
*
* @return string
*/
public function getBlockTitle()
if ( $this->_parent == Mage::app()->getStore()->getRootCategoryId() )
return '';
else
return Mage::getModel('catalog/category')->load($this->_parent)->getName();



/**
* Get sibling catagories
*
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
public function getLeftCategories()
$parent['include_in_menu'] == 0 )
return null;

if (!isset($this->_leftCategories))
$this->_leftCategories = $this->_getLeftCategoryCollection()
->addIdFilter($parent->getChildren());

return $this->_leftCategories;


/**
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
protected function _getLeftCategoryCollection()

$collection = Mage::getResourceModel('catalog/category_collection');
$collection->addAttributeToSelect('url_key')
->addAttributeToSelect('name')
->addAttributeToSelect('all_children')
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1)
->setOrder('position', 'ASC')
->joinUrlRewrite();
return $collection;


/**
* 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>';

$columnItemsNum = array();
if ($level == 0 && $activeChildrenCount)
$items_per_column = Mage::getStoreConfig('theme/navigation/column_items');
$columns = ceil($activeChildrenCount / $items_per_column);
$columnItemsNum = array_fill(0, $columns, $items_per_column);
$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) else
$isLast = ($j == $activeChildrenCount - 1);


$childHtml = $this->_renderCategoryMenuItemHtml(
$child,
($level + 1),
$isLast,
($j == 0),
false,
$outermostItemClass,
$childrenWrapClass,
$noEventAttributes
);
if ($level == 0)
$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($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 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 = '<option value="">' . $this->__('- Please select category -') . '</option>';
$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[] = '<option value="'.$this->getCategoryUrl($category).'" '.$active.'>' . str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;',$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;






If you can see anything which maybe causing this problem could you let me know please as i am lost with this problem.



Thank you










share|improve this question
















bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • inspect this subcategory, see if there is any supernumerary class added to the element.

    – Julien Lachal
    Oct 14 '14 at 12:02











  • The class change from inactive to active on the bottom category, same as when you are actually in the category

    – Adam Allen
    Oct 14 '14 at 12:19











  • Can you add either a image or add a url

    – Renon Stewart
    Oct 14 '14 at 14:00











  • @R.S what an screen shot of the problem? cant give out URL because the site isnt live yet and is password protected

    – Adam Allen
    Oct 14 '14 at 14:01












  • Probably the function _isCurrentCategory gets wrong category $cat = $this->getCurrentCategory(); from the registry? What does this code return?

    – Amasty
    Oct 14 '14 at 14:21













3












3








3








I have a problem on my product categories page the navigation that we have going down the left side displays all the categories we need it to and also it bold a subcategory when you are on it, However when you are not on any sub categories and you are on the main categories page The bottom category is always in bold even when you are not on it.



This is my code which creates the navigation (this is a .phtml file)



<?php
ob_start();

$store_categories = $this->getLeftCategories();
if ($count = count($store_categories))

$block_title = $this->getBlockTitle();
if ( empty($block_title) ) $block_title = 'Categories';
?>
<div class="block block-left-nav">
<div class="block-title">
<strong><span><?php echo $this->__($block_title) ?></span></strong>
</div>
<div class="block-content">
<ul id="left-nav">
<?php
$i=0;
foreach ($store_categories as $_category)
$class = array();
if (!$i)
$class[] = 'first';
elseif ($i == $count)
$class[] = 'last';

echo $this->drawOpenCategoryItem($_category, 0, $class);
$i++;
?>
</ul>
</div>
</div>
<?php

// if ($count = count($store_categories)) {
$mdms_blocks = Mage::registry('mdms_blocks');
if ( !$mdms_blocks )
$mdms_blocks = array();
else
Mage::unregister('mdms_blocks');

$mdms_blocks['block_left_nav'] = ob_get_clean();
Mage::register('mdms_blocks', $mdms_blocks);


I assume that what opens the categories is the drawOpenCategoryItem function



This is the code in the navigation.php which has that function in it but i cant see anything wrong.



<?php
/**
* @version 1.0 12.0.2012
* @author
* @copyright Copyright (C) 2010 - 2012
*/

class our_ThemeSettings_Block_Navigation extends Mage_Catalog_Block_Navigation


/**
* columns html
*
* @var array
*/
protected $_columnHtml;

/*
* @var Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
protected $_leftCategories;

/**
* top level parent category for current category
*
* @var int
*/
protected $_parent;

protected function _construct()

$path = $this->getCurrentCategoryPath();
$parent = $path[count($path)-2];
if (!$parent)
$parent = Mage::app()->getStore()->getRootCategoryId();

$this->_parent = $parent;



/**
* render category html
*
* @param Mage_Catalog_Model_Category $category
* @param integer $level
* @param array $levelClass
* @return string
*/
public function drawOpenCategoryItem($category, $level = 0, array $levelClass = null)

$html = array();

if (!$category->getIsActive()) 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);
$levelClass = array_merge($levelClass, $combineClasses);
$levelClass[] = $this->_getClassNameFromCategoryName($category);

$html[1] = '<a href="' . $this->getCategoryUrl($category) . '">' . $this->escapeHtml($category->getName()) . '</a>' . "n";

if ( in_array($category->getId(), $this->getCurrentCategoryPath()) )
$children = $this->_getLeftCategoryCollection()
->addIdFilter($category->getChildren());

$hasChildren = $children && ($childrenCount = count($children));
if ($hasChildren)
$htmlChildren = '';

foreach ($children as $i => $child)

$class = array();
if ($childrenCount == 1)
$class[] = 'only';

else

if (!$i) $class[] = 'first';
if ($i == $childrenCount - 1) $class[] = 'last';

$htmlChildren .= $this->drawOpenCategoryItem($child, $level + 1, $class);


if (!empty($htmlChildren))
$levelClass[] = 'open';

$html[2] = '<ul>' . "n"
. $htmlChildren . "n"
. '</ul>';




$html[0] = sprintf('<li class="%s">', implode(" ", $levelClass)) . "n";
$html[3] = "n" . '</li>' . "n";

ksort($html);
return implode('', $html);


/**
* Convert the category name into a string that can be used as a css class
*
* @param Mage_Catalog_Model_Category $category
* @return string
*/
protected function _getClassNameFromCategoryName($category)

$name = $category->getName();
$name = preg_replace('/-2,/', '-', preg_replace('/[^a-z-]/', '-', strtolower($name)));
while ($name && $name0 == '-') $name = substr($name, 1);
while ($name && substr($name, -1) == '-') $name = substr($name, 0, -1);
return $name;


/**
* Check if the current category matches the passed in category
*
* @param Mage_Catalog_Model_Category $category
* @return bool
*/
protected function _isCurrentCategory($category)

return ($cat = $this->getCurrentCategory()) && $cat->getId() == $category->getId();


/**
* return top level category name
*
* @return string
*/
public function getBlockTitle()
if ( $this->_parent == Mage::app()->getStore()->getRootCategoryId() )
return '';
else
return Mage::getModel('catalog/category')->load($this->_parent)->getName();



/**
* Get sibling catagories
*
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
public function getLeftCategories()
$parent['include_in_menu'] == 0 )
return null;

if (!isset($this->_leftCategories))
$this->_leftCategories = $this->_getLeftCategoryCollection()
->addIdFilter($parent->getChildren());

return $this->_leftCategories;


/**
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
protected function _getLeftCategoryCollection()

$collection = Mage::getResourceModel('catalog/category_collection');
$collection->addAttributeToSelect('url_key')
->addAttributeToSelect('name')
->addAttributeToSelect('all_children')
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1)
->setOrder('position', 'ASC')
->joinUrlRewrite();
return $collection;


/**
* 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>';

$columnItemsNum = array();
if ($level == 0 && $activeChildrenCount)
$items_per_column = Mage::getStoreConfig('theme/navigation/column_items');
$columns = ceil($activeChildrenCount / $items_per_column);
$columnItemsNum = array_fill(0, $columns, $items_per_column);
$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) else
$isLast = ($j == $activeChildrenCount - 1);


$childHtml = $this->_renderCategoryMenuItemHtml(
$child,
($level + 1),
$isLast,
($j == 0),
false,
$outermostItemClass,
$childrenWrapClass,
$noEventAttributes
);
if ($level == 0)
$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($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 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 = '<option value="">' . $this->__('- Please select category -') . '</option>';
$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[] = '<option value="'.$this->getCategoryUrl($category).'" '.$active.'>' . str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;',$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;






If you can see anything which maybe causing this problem could you let me know please as i am lost with this problem.



Thank you










share|improve this question
















I have a problem on my product categories page the navigation that we have going down the left side displays all the categories we need it to and also it bold a subcategory when you are on it, However when you are not on any sub categories and you are on the main categories page The bottom category is always in bold even when you are not on it.



This is my code which creates the navigation (this is a .phtml file)



<?php
ob_start();

$store_categories = $this->getLeftCategories();
if ($count = count($store_categories))

$block_title = $this->getBlockTitle();
if ( empty($block_title) ) $block_title = 'Categories';
?>
<div class="block block-left-nav">
<div class="block-title">
<strong><span><?php echo $this->__($block_title) ?></span></strong>
</div>
<div class="block-content">
<ul id="left-nav">
<?php
$i=0;
foreach ($store_categories as $_category)
$class = array();
if (!$i)
$class[] = 'first';
elseif ($i == $count)
$class[] = 'last';

echo $this->drawOpenCategoryItem($_category, 0, $class);
$i++;
?>
</ul>
</div>
</div>
<?php

// if ($count = count($store_categories)) {
$mdms_blocks = Mage::registry('mdms_blocks');
if ( !$mdms_blocks )
$mdms_blocks = array();
else
Mage::unregister('mdms_blocks');

$mdms_blocks['block_left_nav'] = ob_get_clean();
Mage::register('mdms_blocks', $mdms_blocks);


I assume that what opens the categories is the drawOpenCategoryItem function



This is the code in the navigation.php which has that function in it but i cant see anything wrong.



<?php
/**
* @version 1.0 12.0.2012
* @author
* @copyright Copyright (C) 2010 - 2012
*/

class our_ThemeSettings_Block_Navigation extends Mage_Catalog_Block_Navigation


/**
* columns html
*
* @var array
*/
protected $_columnHtml;

/*
* @var Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
protected $_leftCategories;

/**
* top level parent category for current category
*
* @var int
*/
protected $_parent;

protected function _construct()

$path = $this->getCurrentCategoryPath();
$parent = $path[count($path)-2];
if (!$parent)
$parent = Mage::app()->getStore()->getRootCategoryId();

$this->_parent = $parent;



/**
* render category html
*
* @param Mage_Catalog_Model_Category $category
* @param integer $level
* @param array $levelClass
* @return string
*/
public function drawOpenCategoryItem($category, $level = 0, array $levelClass = null)

$html = array();

if (!$category->getIsActive()) 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);
$levelClass = array_merge($levelClass, $combineClasses);
$levelClass[] = $this->_getClassNameFromCategoryName($category);

$html[1] = '<a href="' . $this->getCategoryUrl($category) . '">' . $this->escapeHtml($category->getName()) . '</a>' . "n";

if ( in_array($category->getId(), $this->getCurrentCategoryPath()) )
$children = $this->_getLeftCategoryCollection()
->addIdFilter($category->getChildren());

$hasChildren = $children && ($childrenCount = count($children));
if ($hasChildren)
$htmlChildren = '';

foreach ($children as $i => $child)

$class = array();
if ($childrenCount == 1)
$class[] = 'only';

else

if (!$i) $class[] = 'first';
if ($i == $childrenCount - 1) $class[] = 'last';

$htmlChildren .= $this->drawOpenCategoryItem($child, $level + 1, $class);


if (!empty($htmlChildren))
$levelClass[] = 'open';

$html[2] = '<ul>' . "n"
. $htmlChildren . "n"
. '</ul>';




$html[0] = sprintf('<li class="%s">', implode(" ", $levelClass)) . "n";
$html[3] = "n" . '</li>' . "n";

ksort($html);
return implode('', $html);


/**
* Convert the category name into a string that can be used as a css class
*
* @param Mage_Catalog_Model_Category $category
* @return string
*/
protected function _getClassNameFromCategoryName($category)

$name = $category->getName();
$name = preg_replace('/-2,/', '-', preg_replace('/[^a-z-]/', '-', strtolower($name)));
while ($name && $name0 == '-') $name = substr($name, 1);
while ($name && substr($name, -1) == '-') $name = substr($name, 0, -1);
return $name;


/**
* Check if the current category matches the passed in category
*
* @param Mage_Catalog_Model_Category $category
* @return bool
*/
protected function _isCurrentCategory($category)

return ($cat = $this->getCurrentCategory()) && $cat->getId() == $category->getId();


/**
* return top level category name
*
* @return string
*/
public function getBlockTitle()
if ( $this->_parent == Mage::app()->getStore()->getRootCategoryId() )
return '';
else
return Mage::getModel('catalog/category')->load($this->_parent)->getName();



/**
* Get sibling catagories
*
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
public function getLeftCategories()
$parent['include_in_menu'] == 0 )
return null;

if (!isset($this->_leftCategories))
$this->_leftCategories = $this->_getLeftCategoryCollection()
->addIdFilter($parent->getChildren());

return $this->_leftCategories;


/**
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection
*/
protected function _getLeftCategoryCollection()

$collection = Mage::getResourceModel('catalog/category_collection');
$collection->addAttributeToSelect('url_key')
->addAttributeToSelect('name')
->addAttributeToSelect('all_children')
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1)
->setOrder('position', 'ASC')
->joinUrlRewrite();
return $collection;


/**
* 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>';

$columnItemsNum = array();
if ($level == 0 && $activeChildrenCount)
$items_per_column = Mage::getStoreConfig('theme/navigation/column_items');
$columns = ceil($activeChildrenCount / $items_per_column);
$columnItemsNum = array_fill(0, $columns, $items_per_column);
$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) else
$isLast = ($j == $activeChildrenCount - 1);


$childHtml = $this->_renderCategoryMenuItemHtml(
$child,
($level + 1),
$isLast,
($j == 0),
false,
$outermostItemClass,
$childrenWrapClass,
$noEventAttributes
);
if ($level == 0)
$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($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 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 = '<option value="">' . $this->__('- Please select category -') . '</option>';
$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[] = '<option value="'.$this->getCategoryUrl($category).'" '.$active.'>' . str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;',$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;






If you can see anything which maybe causing this problem could you let me know please as i am lost with this problem.



Thank you







magento-1.9 category navigation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 14 '14 at 14:33







Adam Allen

















asked Oct 1 '14 at 14:53









Adam AllenAdam Allen

1,30062861




1,30062861





bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • inspect this subcategory, see if there is any supernumerary class added to the element.

    – Julien Lachal
    Oct 14 '14 at 12:02











  • The class change from inactive to active on the bottom category, same as when you are actually in the category

    – Adam Allen
    Oct 14 '14 at 12:19











  • Can you add either a image or add a url

    – Renon Stewart
    Oct 14 '14 at 14:00











  • @R.S what an screen shot of the problem? cant give out URL because the site isnt live yet and is password protected

    – Adam Allen
    Oct 14 '14 at 14:01












  • Probably the function _isCurrentCategory gets wrong category $cat = $this->getCurrentCategory(); from the registry? What does this code return?

    – Amasty
    Oct 14 '14 at 14:21

















  • inspect this subcategory, see if there is any supernumerary class added to the element.

    – Julien Lachal
    Oct 14 '14 at 12:02











  • The class change from inactive to active on the bottom category, same as when you are actually in the category

    – Adam Allen
    Oct 14 '14 at 12:19











  • Can you add either a image or add a url

    – Renon Stewart
    Oct 14 '14 at 14:00











  • @R.S what an screen shot of the problem? cant give out URL because the site isnt live yet and is password protected

    – Adam Allen
    Oct 14 '14 at 14:01












  • Probably the function _isCurrentCategory gets wrong category $cat = $this->getCurrentCategory(); from the registry? What does this code return?

    – Amasty
    Oct 14 '14 at 14:21
















inspect this subcategory, see if there is any supernumerary class added to the element.

– Julien Lachal
Oct 14 '14 at 12:02





inspect this subcategory, see if there is any supernumerary class added to the element.

– Julien Lachal
Oct 14 '14 at 12:02













The class change from inactive to active on the bottom category, same as when you are actually in the category

– Adam Allen
Oct 14 '14 at 12:19





The class change from inactive to active on the bottom category, same as when you are actually in the category

– Adam Allen
Oct 14 '14 at 12:19













Can you add either a image or add a url

– Renon Stewart
Oct 14 '14 at 14:00





Can you add either a image or add a url

– Renon Stewart
Oct 14 '14 at 14:00













@R.S what an screen shot of the problem? cant give out URL because the site isnt live yet and is password protected

– Adam Allen
Oct 14 '14 at 14:01






@R.S what an screen shot of the problem? cant give out URL because the site isnt live yet and is password protected

– Adam Allen
Oct 14 '14 at 14:01














Probably the function _isCurrentCategory gets wrong category $cat = $this->getCurrentCategory(); from the registry? What does this code return?

– Amasty
Oct 14 '14 at 14:21





Probably the function _isCurrentCategory gets wrong category $cat = $this->getCurrentCategory(); from the registry? What does this code return?

– Amasty
Oct 14 '14 at 14:21










2 Answers
2






active

oldest

votes


















0














This could be a CSS related issue, please try to find the exact CSS being used for that block and try to see if any Bold font design has been written over there!






share|improve this answer























  • There is CSS because we need it to bold when the user is in the category. The problem is the bottom category is set to active when you are not in it.

    – Adam Allen
    Oct 17 '14 at 10:32











  • The return in _isCurrentCategory($category), is it giving required output? place a log to check

    – Rahul Kumar Das
    Oct 17 '14 at 10:36











  • What do you mean is it giving required output? If you mean does it work as we want. Then yes, the parent category is bold when you are in it and so are the children categories. The problem is when you are in a parent category it is also setting the last child category to active as well even when you are not in it

    – Adam Allen
    Oct 17 '14 at 10:39











  • From frontend, could you check that which css property is making the bottom category BOLD?

    – Rahul Kumar Das
    Oct 17 '14 at 10:43











  • .col-left .block-left-nav li.active > a font-weight: bold;

    – Adam Allen
    Oct 17 '14 at 10:45


















0














Maybe you're just getting this active class through some JavaScript code on frontend? I would start from checking all JavaScript related to the menu.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f37696%2fbottom-category-on-left-navigation-is-always-open%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This could be a CSS related issue, please try to find the exact CSS being used for that block and try to see if any Bold font design has been written over there!






    share|improve this answer























    • There is CSS because we need it to bold when the user is in the category. The problem is the bottom category is set to active when you are not in it.

      – Adam Allen
      Oct 17 '14 at 10:32











    • The return in _isCurrentCategory($category), is it giving required output? place a log to check

      – Rahul Kumar Das
      Oct 17 '14 at 10:36











    • What do you mean is it giving required output? If you mean does it work as we want. Then yes, the parent category is bold when you are in it and so are the children categories. The problem is when you are in a parent category it is also setting the last child category to active as well even when you are not in it

      – Adam Allen
      Oct 17 '14 at 10:39











    • From frontend, could you check that which css property is making the bottom category BOLD?

      – Rahul Kumar Das
      Oct 17 '14 at 10:43











    • .col-left .block-left-nav li.active > a font-weight: bold;

      – Adam Allen
      Oct 17 '14 at 10:45















    0














    This could be a CSS related issue, please try to find the exact CSS being used for that block and try to see if any Bold font design has been written over there!






    share|improve this answer























    • There is CSS because we need it to bold when the user is in the category. The problem is the bottom category is set to active when you are not in it.

      – Adam Allen
      Oct 17 '14 at 10:32











    • The return in _isCurrentCategory($category), is it giving required output? place a log to check

      – Rahul Kumar Das
      Oct 17 '14 at 10:36











    • What do you mean is it giving required output? If you mean does it work as we want. Then yes, the parent category is bold when you are in it and so are the children categories. The problem is when you are in a parent category it is also setting the last child category to active as well even when you are not in it

      – Adam Allen
      Oct 17 '14 at 10:39











    • From frontend, could you check that which css property is making the bottom category BOLD?

      – Rahul Kumar Das
      Oct 17 '14 at 10:43











    • .col-left .block-left-nav li.active > a font-weight: bold;

      – Adam Allen
      Oct 17 '14 at 10:45













    0












    0








    0







    This could be a CSS related issue, please try to find the exact CSS being used for that block and try to see if any Bold font design has been written over there!






    share|improve this answer













    This could be a CSS related issue, please try to find the exact CSS being used for that block and try to see if any Bold font design has been written over there!







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 17 '14 at 9:42









    Rahul Kumar DasRahul Kumar Das

    1,6981119




    1,6981119












    • There is CSS because we need it to bold when the user is in the category. The problem is the bottom category is set to active when you are not in it.

      – Adam Allen
      Oct 17 '14 at 10:32











    • The return in _isCurrentCategory($category), is it giving required output? place a log to check

      – Rahul Kumar Das
      Oct 17 '14 at 10:36











    • What do you mean is it giving required output? If you mean does it work as we want. Then yes, the parent category is bold when you are in it and so are the children categories. The problem is when you are in a parent category it is also setting the last child category to active as well even when you are not in it

      – Adam Allen
      Oct 17 '14 at 10:39











    • From frontend, could you check that which css property is making the bottom category BOLD?

      – Rahul Kumar Das
      Oct 17 '14 at 10:43











    • .col-left .block-left-nav li.active > a font-weight: bold;

      – Adam Allen
      Oct 17 '14 at 10:45

















    • There is CSS because we need it to bold when the user is in the category. The problem is the bottom category is set to active when you are not in it.

      – Adam Allen
      Oct 17 '14 at 10:32











    • The return in _isCurrentCategory($category), is it giving required output? place a log to check

      – Rahul Kumar Das
      Oct 17 '14 at 10:36











    • What do you mean is it giving required output? If you mean does it work as we want. Then yes, the parent category is bold when you are in it and so are the children categories. The problem is when you are in a parent category it is also setting the last child category to active as well even when you are not in it

      – Adam Allen
      Oct 17 '14 at 10:39











    • From frontend, could you check that which css property is making the bottom category BOLD?

      – Rahul Kumar Das
      Oct 17 '14 at 10:43











    • .col-left .block-left-nav li.active > a font-weight: bold;

      – Adam Allen
      Oct 17 '14 at 10:45
















    There is CSS because we need it to bold when the user is in the category. The problem is the bottom category is set to active when you are not in it.

    – Adam Allen
    Oct 17 '14 at 10:32





    There is CSS because we need it to bold when the user is in the category. The problem is the bottom category is set to active when you are not in it.

    – Adam Allen
    Oct 17 '14 at 10:32













    The return in _isCurrentCategory($category), is it giving required output? place a log to check

    – Rahul Kumar Das
    Oct 17 '14 at 10:36





    The return in _isCurrentCategory($category), is it giving required output? place a log to check

    – Rahul Kumar Das
    Oct 17 '14 at 10:36













    What do you mean is it giving required output? If you mean does it work as we want. Then yes, the parent category is bold when you are in it and so are the children categories. The problem is when you are in a parent category it is also setting the last child category to active as well even when you are not in it

    – Adam Allen
    Oct 17 '14 at 10:39





    What do you mean is it giving required output? If you mean does it work as we want. Then yes, the parent category is bold when you are in it and so are the children categories. The problem is when you are in a parent category it is also setting the last child category to active as well even when you are not in it

    – Adam Allen
    Oct 17 '14 at 10:39













    From frontend, could you check that which css property is making the bottom category BOLD?

    – Rahul Kumar Das
    Oct 17 '14 at 10:43





    From frontend, could you check that which css property is making the bottom category BOLD?

    – Rahul Kumar Das
    Oct 17 '14 at 10:43













    .col-left .block-left-nav li.active > a font-weight: bold;

    – Adam Allen
    Oct 17 '14 at 10:45





    .col-left .block-left-nav li.active > a font-weight: bold;

    – Adam Allen
    Oct 17 '14 at 10:45













    0














    Maybe you're just getting this active class through some JavaScript code on frontend? I would start from checking all JavaScript related to the menu.






    share|improve this answer



























      0














      Maybe you're just getting this active class through some JavaScript code on frontend? I would start from checking all JavaScript related to the menu.






      share|improve this answer

























        0












        0








        0







        Maybe you're just getting this active class through some JavaScript code on frontend? I would start from checking all JavaScript related to the menu.






        share|improve this answer













        Maybe you're just getting this active class through some JavaScript code on frontend? I would start from checking all JavaScript related to the menu.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 19 '14 at 21:59









        zitixzitix

        1,09772141




        1,09772141



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f37696%2fbottom-category-on-left-navigation-is-always-open%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

            Magento 2 disable Secret Key on URL's from terminal The Next CEO of Stack OverflowMagento 2 Shortcut/GUI tool to perform commandline tasks for windowsIn menu add configuration linkMagento oAuth : Generating access token and access secretMagento 2 security key issue in Third-Party API redirect URIPublic actions in admin controllersHow to Disable Cache in Custom WidgetURL Key not changing in Magento 2Product URL Key gets deleted when importing custom options - Magento 2Problem with reindex terminalMagento 2 - bin/magento Commands not working in Cpanel Terminal

            Aasi (pallopeli) Navigointivalikko