0

I am using Magento 1.9.2.4

I have created 3 root categories with multiple sub categories in each root category.

Category image

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

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;

Settings under Catalog->Search engine optimization settings

5
  • try Re-indexing May 30, 2016 at 6:43
  • Tried that also, no luck.
    – danish
    May 30, 2016 at 7:25
  • Do you have multi store/website for which you have created other root categories. Whats the setting you have under Catalog|Search Engine Optimization
    – Bharath
    May 30, 2016 at 7:34
  • If its not multi store why do you want to create multiple root categories. A root category is parent of all sub categories for a specific store.Every root category will be specific to one store.
    – Bharath
    May 30, 2016 at 7:45
  • Well does that mean it should get the name of the sub category but not the url?
    – danish
    May 30, 2016 at 9:22

1 Answer 1

0

In order to get the URLs you mention, they must be under "Category" category root.

Category (root store category) - Portable power - Test - Professional - Heavy Use

You can't achieve what you are looking for with your current categories structure without heavily modifying/overwriting Magento core files (not advised at all).

You can try...

Category (as root store category) - Portable power - Test - Life Style - Professional - Solar Need - Heavy Use

This will give you by default URLs such as:

  • Portable power - domain-name/portable-power.html
  • Test - domainname/test.html
  • Professional - domain-name/life-style/professional.html
  • Heavy Use - domain-name/solar-need/heavy-use.html

Hope it helps.

2
  • Then why does magento has option to add more than 1 root category?
    – danish
    Jun 4, 2016 at 4:34
  • According to Magento documentation: Because the root category is the highest level of the catalog, your store can have only one root category active at a time. You can, however, create additional root categories for alternate catalog structures, different stores, and views. [...]The root category is not visible to customers in the store, and does not have a URL key. More info: docs.magento.com/m2/ce/user_guide/catalog/category-root.html Jun 5, 2016 at 16:44

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .