Call-back icon  Sales: Call 877.832.5289 (N America)|310.295.4144 (International)

Magento

eCommerce Software for Online Growth

Magento Forum

   
Page 1 of 2
Controlling sort order for categories in layered navigation
 
Ian M
Jr. Member
 
Total Posts:  12
Joined:  2008-01-16
 

Is there a way to control the sort order of CATEGORIES displayed in the layered navigation?

For example, I have a category called “Fruit” and within that I have sub categories called Apples, Bananas and Oranges. I can control the display sort order for the sub categories by dragging the sub categories around in the “category admin panel” to display correctly i.e.

Fruit
---- Apples
---- Bananas
---- Oranges

However, when displaying the sub-categories in the “SHOP BY” category layered navigation, I don’t seem to be able to control the sort order.

Please see attached picture as an example.

Thanks,

Ian

Image Attachments
sort order issue.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
witt
Jr. Member
 
Total Posts:  3
Joined:  2008-03-31
 

Hi Ian,

I could not find any option to make the categories appear in the order you defined them. But you can modify /app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php.

Just add addAttributeToSort(’position’, ‘asc’) sorting criteria to the function that loads the child categories collection that will be used in the Shopping Filter block.

protected function _initItems()
{
$categoty = $this->getCategory();
$collection = Mage::getResourceModel(’catalog/category_collection’)
->addAttributeToSelect(’name’)
->addAttributeToSelect(’all_children’)
->addAttributeToSelect(’is_anchor’)
->addAttributeToFilter(’is_active’, 1)
->addAttributeToSort(’position’, ‘asc’)
->joinUrlRewrite()
->addIdFilter($categoty->getChildren())
->load();

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ian M
Jr. Member
 
Total Posts:  12
Joined:  2008-01-16
 

Hi witt,

That’s great - thanks very much for your quick reply.

Regards,

Ian

 
Magento Community Magento Community
Magento Community
Magento Community
 
TechBundle
Member
 
Avatar
Total Posts:  51
Joined:  2008-03-26
 

I did this and my layered navigation is still not sorting how I want it to. Anyone have any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
PC Games Plus
Member
 
Avatar
Total Posts:  56
Joined:  2008-01-04
Sacramento, CA
 

The solution to your problem is in the product attributes. Open an attribute and look for the box that refers to the display order and adjust according to your tastes

 
Magento Community Magento Community
Magento Community
Magento Community
 
TechBundle
Member
 
Avatar
Total Posts:  51
Joined:  2008-03-26
 

Unless I am completely misunderstanding what you are telling me, all that does is change the sort order of the attributes of a product, not the sort order of categories in layered navigation.

 
Magento Community Magento Community
Magento Community
Magento Community
 
PC Games Plus
Member
 
Avatar
Total Posts:  56
Joined:  2008-01-04
Sacramento, CA
 

What you are referring to is the way they are displayed in the product info entry page. I am talking about the way categories in the layered navigation are being shown. I think that is what you are talking about. It took me awhile to find it too. It is listed in the particular attribute under “Frontend Properties” listed as “position” the lower the number the higher up it shows.

 
Magento Community Magento Community
Magento Community
Magento Community
 
TechBundle
Member
 
Avatar
Total Posts:  51
Joined:  2008-03-26
 

Under which product attribute? How can changing a product’s attribute change the sort order of a category in layered navigation? Products and categories are separate entities.

 
Magento Community Magento Community
Magento Community
Magento Community
 
TechBundle
Member
 
Avatar
Total Posts:  51
Joined:  2008-03-26
 

Is there confusion about the term “layered navigation”?

If you look at the image attached to the first post in the thread, I have exactly the same issue.

I can drag sub-categories around in “Category Management” and it will change the display order of the sub-categories in the frontend top menu bar. However, it does not change the display order of those same categories in the “Shop By Category” box on the left side of the page when viewing the parent category.

 
Magento Community Magento Community
Magento Community
Magento Community
 
PC Games Plus
Member
 
Avatar
Total Posts:  56
Joined:  2008-01-04
Sacramento, CA
 

I’m sorry… too tired i guess. The thing that you are asking about can’t be fixed in the manner I described.

 
Magento Community Magento Community
Magento Community
Magento Community
 
joolsr
Sr. Member
 
Total Posts:  90
Joined:  2008-01-16
 

just thinking. On the first line of the code,is says $catetogy . Is this correct or a bug?

This is true of the main current Magento code too

 
Magento Community Magento Community
Magento Community
Magento Community
 
warren
Member
 
Total Posts:  54
Joined:  2007-12-18
 

Guys can anyone point me in the right direction to get Layered Navigation to order correctly?

Cheers

Warren

 
Magento Community Magento Community
Magento Community
Magento Community
 
joolsr
Sr. Member
 
Total Posts:  90
Joined:  2008-01-16
 

In terms of specifics. I ended up having to delete and recreate my category, but it all worked quite easily. Then the navigation was fine.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Enthusiast
 
Avatar
Total Posts:  872
Joined:  2007-12-14
Illinois, USA
 

1. Open your attribute.
2. On the properties tab that it opens to, look for “Position” under Frontend Properties.

That # effects what order the layered navigation is in.

Edit: But upon reading again, you were talking about the categories - if you sort the order they’re in for the main navigation, will that do what you want it to?

 Signature 

Creativity is falling in love with the world. – Dewitt Jones
Current Projects: Aqua Gear Direct & IHSA State Finals • Currently Running: PHP 5.2.5/MySQL 5.0.45/Magento 1.1.8 on HostGator

 
Magento Community Magento Community
Magento Community
Magento Community
 
joolsr
Sr. Member
 
Total Posts:  90
Joined:  2008-01-16
 

yes its the categories that dont work as you would like. Even if you re-order in the backend by the nice drag and drop feature, its doesnt re-order accordingly for the layered nav for the categories. As I said, the only way I could fix it was to delete the problematic category and recreate it. Then it worked fine.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Simon King
Member
 
Avatar
Total Posts:  45
Joined:  2008-01-10
 

Adding the code witt suggested to app/code/core/Mage/Catalog/Block/Navigation.php (line 77) solved the order problem for me.

 Signature 

-----------------
Organic Internet & Mobile
Mobile & Web Application Design & Development
Yorkshire, UK

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2
 
Sales: Call 877.832.5289 (North America) 310.295.4144 (International)
© Copyright 2008 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
53190 users|769 users currently online|107216 forum posts