Jump to content

Top Horizontal Menu - sort submenu content


Recommended Posts

Hi

 

Is there an easy way to sort the dropdown list alphabetically for a menu item on the top horizontal menu?

This is for categories not manufacturers, which can already show in alphabetical order.

 

Thanks

Mark

Link to comment
Share on other sites

Which ones are you willing to sort alphabetically, exactly? First or second level subcategories?

It would imply modifying Category::getNestedCategories I believe, it seems quite complicated so no, not an easy way

Link to comment
Share on other sites

It was the first level of subcategories I wanted to sort.

The second level I have suppressed with a css tag just to  make it look tidier.

I did check out the getNestedCategoies function and because of the way the data is stored and the recursion used, it would be a rewrite. Maybe I'm not that keen at the moment to do that.

 

Regards

Mark

Link to comment
Share on other sites

function mentioned by nemo has got param: $sql_sort 

ORDER BY cl.`name` DESC

so in module php file you can try something like

$this->_menu .= $this->generateCategoriesMenu(Category::getNestedCategories($id, $id_lang, true, $this->user_groups,true,null,'order by cl.`name` DESC'));
Link to comment
Share on other sites

Hi

 

I tried the above change to sort order ... the array ends up empty after the sql call (see attached before and after echo data) whereas data is in the $categories array before the change.

I'll try and decipher the full sql statement to see if any obvious issue.

 

Cheers

Mark

 

post-151466-0-72322600-1400673289_thumb.pngpost-151466-0-68008600-1400673312_thumb.png

Link to comment
Share on other sites

Still same result .. nothing in the array when I add the above.

Will check out more tomorrow and run the sql statement against the database from a separate php file.

Many thanks for your input

Regards

Mark

Link to comment
Share on other sites

Hi Vekia

 

I checked the code after the sql statement has executed and dumped the array, and the data is moved to the array indexed by the current root category for the menu. All the other categories are then children of this category stored by their category_id. So even if the sql sorted by name they would be scambled when stored in this array.

I think the solution is to write a separate function based on the existing one and only call this from blocktopmenu.php, but store the child categories differently ie. in the order I want based on name not category_id (or sort the children based on name).

I may not get to this today but will let you know how I go.

 

Regards

Mark

Link to comment
Share on other sites

Hi Vekia

 

I ended up changing blocktopmenu.php which worked out to be minimal changes.

Commented out line 344 and added the following lines (attached).

This works fine, but its only for first sublevel which is what I wanted as i don't display further sublevels.

 

Regards

Mark

 

post-151466-0-25836800-1400751029_thumb.png

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

classes/category.php file

 

In getNestedCategories function arount 478 line in  PS 1.6

 

Find 

 

'.($sql_sort == '' && $use_shop_restriction ? ', category_shop.`position` ASC' : '').'

 

and replace with

 

'.($sql_sort == '' && $use_shop_restriction ? ', cl.`name` ASC' : '').'

  • Like 3
Link to comment
Share on other sites

×
×
  • Create New...