markb13 Posted May 21, 2014 Share Posted May 21, 2014 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 More sharing options...
NemoPS Posted May 21, 2014 Share Posted May 21, 2014 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 More sharing options...
markb13 Posted May 21, 2014 Author Share Posted May 21, 2014 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 More sharing options...
vekia Posted May 21, 2014 Share Posted May 21, 2014 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 More sharing options...
vekia Posted May 21, 2014 Share Posted May 21, 2014 i can't test it at the moment 1 Link to comment Share on other sites More sharing options...
markb13 Posted May 21, 2014 Author Share Posted May 21, 2014 I'll give it a shot Thanks for that Mark Link to comment Share on other sites More sharing options...
markb13 Posted May 21, 2014 Author Share Posted May 21, 2014 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 Link to comment Share on other sites More sharing options...
vekia Posted May 21, 2014 Share Posted May 21, 2014 in file: classes/Category.php change '.($sql_sort != '' ? $sql_sort : ' ORDER BY c.`level_depth`).' to: '.($sql_sort != '' ? $sql_sort : ' ORDER BY c.`level_depth` ASC, cl.`name` ASC').' 1 Link to comment Share on other sites More sharing options...
markb13 Posted May 21, 2014 Author Share Posted May 21, 2014 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 More sharing options...
markb13 Posted May 21, 2014 Author Share Posted May 21, 2014 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 More sharing options...
markb13 Posted May 22, 2014 Author Share Posted May 22, 2014 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 1 Link to comment Share on other sites More sharing options...
jdgojariya Posted September 18, 2014 Share Posted September 18, 2014 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' : '').' 3 Link to comment Share on other sites More sharing options...
Recommended Posts