Ozgur34 Posted July 24, 2013 Share Posted July 24, 2013 PrestaShop 1.5.4.1 Block top menu Categories / sub categories Hi My question is: How can I order sub category item names on the menu's sub level as ascending (order by name ascending) At the moment as PrestaShop default as order by position. Which file and which lines to edit? Would anyone help me out on this please? Thnx. Link to comment Share on other sites More sharing options...
vekia Posted July 26, 2013 Share Posted July 26, 2013 in this case is necessary to change top horizontal menu function related to the subcategories. In fact, this is a getChildren function located in the classes/category.php file: public static function getChildren($id_parent, $id_lang, $active = true, $id_shop = false) { if (!Validate::isBool($active)) die(Tools::displayError()); $query = 'SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, category_shop.`id_shop` FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').') '.Shop::addSqlAssociation('category', 'c').' WHERE `id_lang` = '.(int)$id_lang.' AND c.`id_parent` = '.(int)$id_parent.' '.($active ? 'AND `active` = 1' : '').' GROUP BY c.`id_category` ORDER BY category_shop.`position` ASC'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); } what to do? i think that the best duplcate this function in the category.php class file, modify the WHERE clause in the query to the database, then change name of the function to something different for example: public static function getChildrenToMenu($id_parent, $id_lang, $active = true, $id_shop = false) { if (!Validate::isBool($active)) die(Tools::displayError()); $query = 'SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, category_shop.`id_shop` FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').') '.Shop::addSqlAssociation('category', 'c').' WHERE `id_lang` = '.(int)$id_lang.' AND c.`id_parent` = '.(int)$id_parent.' '.($active ? 'AND `active` = 1' : '').' GROUP BY c.`id_category` ORDER BY cl.`name` ASC return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); } then in the module file (blocktopmenu.php) use this new function instead old one. instead $children = Category::getChildren((int)$id_category, (int)$id_lang, true, (int)$id_shop); use this: $children = Category::getChildrenToMenu((int)$id_category, (int)$id_lang, true, (int)$id_shop); 1 Link to comment Share on other sites More sharing options...
femo Posted November 28, 2013 Share Posted November 28, 2013 Do I have to do something else? I think I've done everything as you said but it doesn't do anything... (PS 1.5.6.0) Link to comment Share on other sites More sharing options...
vekia Posted November 28, 2013 Share Posted November 28, 2013 after change you have to regenerate menu, just open menu configuration page and hit save button module tpl file will be regenerated then Link to comment Share on other sites More sharing options...
jdgojariya Posted September 18, 2014 Share Posted September 18, 2014 after change you have to regenerate menu, just open menu configuration page and hit save button module tpl file will be regenerated then I Do all the changes. But not working. Link to comment Share on other sites More sharing options...
vekia Posted September 18, 2014 Share Posted September 18, 2014 what menu you use? default block top menu ? Link to comment Share on other sites More sharing options...
jdgojariya Posted September 19, 2014 Share Posted September 19, 2014 what menu you use? default block top menu ? Yes I got solution 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' : '').' Link to comment Share on other sites More sharing options...
vekia Posted September 19, 2014 Share Posted September 19, 2014 thanks for sharing code snippet i marked topic title as solved and your answer as a solution 1 Link to comment Share on other sites More sharing options...
jdgojariya Posted September 20, 2014 Share Posted September 20, 2014 thanks for sharing code snippet i marked topic title as solved and your answer as a solution Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now