Jump to content

How can I order sub category item names on the menu's sub level as ascending?


Ozgur34

Recommended Posts

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

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);

  • Like 1
Link to comment
Share on other sites

  • 4 months later...
  • 9 months later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...