I am using Magento 1.9.2.4
I have created 3 root categories with multiple sub categories in each root category.
First root category (Category) works fine, but their is some issue with sub-categories of other 2 root categories. For those sub-categories it gets some weird url.
1) Category - Root category
- Portable power - http://domain-name/portable-power.html
- Test - http://domainname/test.html
2) Lifestyle - Root category
3) Solar Need - Root category
And if I try http://domain-name/professional.html or http://domain-name/heavy-use.html URL's for professional and heavy use sub-categories, it shows 404 error.
I cleared the cache, tried re-indexing, ran compilation, disabled compilation, but nothing seems to work.
Below is the code I am using to get the root categories and sub categories.
$html = '';
$children = $menuTree->getChildren();
$parentLevel = $menuTree->getLevel();
$childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;
$counter = 1;
$childrenCount = $children->count();
$parentPositionClass = $menuTree->getPositionClass();
$itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';
$baseUrl = Mage::getBaseUrl();
$html .= '<li class="new-menu level0 nav-1 first last parent"><a href="'.$baseUrl.'products">Shop Solar</a>';
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')//or you can just add some attributes
->addAttributeToFilter('level', 1)//2 is actually the first level
->addAttributeToFilter('is_active', 1)//if you want only active categories
;
if ($categories) {
$html .= '<div class="menu-arrow"></div><ul>';
foreach ($categories as $category) {
$html .= '<li>';
$html .= '<p class="menu-heading">By '.$category->getName().'</p>';
$html .= '<ul class="child">';
//$children = Mage::getModel('catalog/category')->getCategories($category->getID());
$children = Mage::getModel( 'catalog/category' )->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('parent_id',array('eq' => $category->getID()))
->addFieldToFilter('is_active', array('eq' => '1'));
if ($children) {
foreach ($children as $child) {
if ($child->getCustomIconAttribute()) {
$iconUrl = Mage::getBaseUrl('media').'catalog/category/'.$child->getCustomIconAttribute();
}
else
{
$iconUrl = '';
}
$html .= '<li>';
$html .= '<div class="menu-icon"><img src="'.$iconUrl.'" /></div>';
$html .= '<div class="cat-wrap"><a href="'.$child->getUrl().'">'.$child->getName().'</a>';
$html .= '<p class="cat-desc">'.$child->getDescription().'</p></div>';
$html .= '</li>';
}
}
$html .= '</ul>';
$html .= '</li>';
}
$html .= '<p class="all-prod"><a href="'.$baseUrl.'products">View All Products</a></p></ul>';
}
$html .= '</li>';
return $html;