Jump to content

[Résolu] Ranger blocktopmenu par ordre alphabétique


Recommended Posts

Bonjour tout le monde.

 

J'utilise Prestashop 1.6 et le le module "Menu Horizontal Haut" sur mon site et je souhaiterai ranger les sous-menus (catégories CMS) par ordre alphabétique. J'ai vu ça et là une méthode proposant de supprimer les catégories puis de les réécrire dans l'ordre alphabétique... Je ne suis pas du tout d'accord avec cette méthode, imaginant qu'il existe un moyen plus propre en modifiant un "Order by" dans le code soit du module, soit des classes. Le problème c'est que je ne trouve pas où il faut que je fasse mes modifications.

 

Merci d'avance pour votre aide :)

Edited by Neith17 (see edit history)
Link to comment
Share on other sites

salut,

dans blocktopmenu.php

protected function getCMSPages($id_cms_category, $id_shop = false, $id_lang = false)
    {
        $id_shop = ($id_shop !== false) ? (int)$id_shop : (int)Context::getContext()->shop->id;
        $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id;

        $where_shop = '';
        if (Tools::version_compare(_PS_VERSION_, '1.6.0.12', '>=') == true) {
            $where_shop = ' AND cl.`id_shop` = '.(int)$id_shop;
        }

        $sql = 'SELECT c.`id_cms`, cl.`meta_title`, cl.`link_rewrite`
			FROM `'._DB_PREFIX_.'cms` c
			INNER JOIN `'._DB_PREFIX_.'cms_shop` cs
			ON (c.`id_cms` = cs.`id_cms`)
			INNER JOIN `'._DB_PREFIX_.'cms_lang` cl
			ON (c.`id_cms` = cl.`id_cms`)
			WHERE c.`id_cms_category` = '.(int)$id_cms_category.'
			AND cs.`id_shop` = '.(int)$id_shop.'
			AND cl.`id_lang` = '.(int)$id_lang.
            $where_shop.'
			AND c.`active` = 1
			ORDER BY `position`';

        return Db::getInstance()->executeS($sql);
    }

Un petit ORDER BY cl.`meta_title` devrait faire l'affaire...

 

cdt

Edited by Alexandre Carette (see edit history)
Link to comment
Share on other sites

Merci pour ton aide, j'ai déjà fait la modification que tu viens de me conseiller et ça ne fonctionne pas, ah moins que je l'écrive mal : 

protected function getCMSPages($id_cms_category, $id_shop = false, $id_lang = false)
    {
        $id_shop = ($id_shop !== false) ? (int)$id_shop : (int)Context::getContext()->shop->id;
        $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id;

        $where_shop = '';
        if (Tools::version_compare(_PS_VERSION_, '1.6.0.12', '>=') == true) {
            $where_shop = ' AND cl.`id_shop` = '.(int)$id_shop;
        }

        $sql = 'SELECT c.`id_cms`, cl.`meta_title`, cl.`link_rewrite`
			FROM `'._DB_PREFIX_.'cms` c
			INNER JOIN `'._DB_PREFIX_.'cms_shop` cs
			ON (c.`id_cms` = cs.`id_cms`)
			INNER JOIN `'._DB_PREFIX_.'cms_lang` cl
			ON (c.`id_cms` = cl.`id_cms`)
			WHERE c.`id_cms_category` = '.(int)$id_cms_category.'
			AND cs.`id_shop` = '.(int)$id_shop.'
			AND cl.`id_lang` = '.(int)$id_lang.
            $where_shop.'
			AND c.`active` = 1
			ORDER BY cl.`meta_title`';

        return Db::getInstance()->executeS($sql);
    }

J'ai aussi chercher dans la page Category.php en me basant sur le fait qu'il pouvait y avoir un héritage mais là non plus rien y fait :/

Link to comment
Share on other sites


protected function getCMSCategories($recursive = false, $parent = 1, $id_lang = false, $id_shop = false)

{

$id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id;

$id_shop = ($id_shop !== false) ? $id_shop : Context::getContext()->shop->id;

$join_shop = '';

$where_shop = '';

 

if (Tools::version_compare(_PS_VERSION_, '1.6.0.12', '>=') == true) {

$join_shop = ' INNER JOIN `'._DB_PREFIX_.'cms_category_shop` cs

ON (bcp.`id_cms_category` = cs.`id_cms_category`)';

$where_shop = ' AND cs.`id_shop` = '.(int)$id_shop.' AND cl.`id_shop` = '.(int)$id_shop;

}

 

if ($recursive === false) {

$sql = 'SELECT bcp.`id_cms_category`, bcp.`id_parent`, bcp.`level_depth`, bcp.`active`, bcp.`position`, cl.`name`, cl.`link_rewrite`

FROM `'._DB_PREFIX_.'cms_category` bcp'.

$join_shop.'

INNER JOIN `'._DB_PREFIX_.'cms_category_lang` cl

ON (bcp.`id_cms_category` = cl.`id_cms_category`)

WHERE cl.`id_lang` = '.(int)$id_lang.'

AND bcp.`id_parent` = '.(int)$parent.

$where_shop;

 

return Db::getInstance()->executeS($sql);

} else {

$sql = 'SELECT bcp.`id_cms_category`, bcp.`id_parent`, bcp.`level_depth`, bcp.`active`, bcp.`position`, cl.`name`, cl.`link_rewrite`

FROM `'._DB_PREFIX_.'cms_category` bcp'.

$join_shop.'

INNER JOIN `'._DB_PREFIX_.'cms_category_lang` cl

ON (bcp.`id_cms_category` = cl.`id_cms_category`)

WHERE cl.`id_lang` = '.(int)$id_lang.'

AND bcp.`id_parent` = '.(int)$parent.

$where_shop;

 

$results = Db::getInstance()->executeS($sql);

foreach ($results as $result) {

$sub_categories = $this->getCMSCategories(true, $result['id_cms_category'], (int)$id_lang);

if ($sub_categories && count($sub_categories) > 0) {

$result['sub_categories'] = $sub_categories;

}

$categories[] = $result;

}

 

return isset($categories) ? $categories : false;

}

}

Link to comment
Share on other sites

Merci pour ton aide et désolé pour le temps de réponse, j'ai essayé et ça ne fonctionne toujours pas... Il est aussi possible que je n'ai pas placé le "Order by" au bon endroit :

if ($recursive === false) {
            $sql = 'SELECT bcp.`id_cms_category`, bcp.`id_parent`, bcp.`level_depth`, bcp.`active`, bcp.`position`, cl.`name`, cl.`link_rewrite`
				FROM `'._DB_PREFIX_.'cms_category` bcp'.
                $join_shop.'
				INNER JOIN `'._DB_PREFIX_.'cms_category_lang` cl
				ON (bcp.`id_cms_category` = cl.`id_cms_category`)
				WHERE cl.`id_lang` = '.(int)$id_lang.'
				AND bcp.`id_parent` = '.(int)$parent.
                $where_shop.'
                ORDER BY cl.`meta_title`';

            return Db::getInstance()->executeS($sql);
        } else {
            $sql = 'SELECT bcp.`id_cms_category`, bcp.`id_parent`, bcp.`level_depth`, bcp.`active`, bcp.`position`, cl.`name`, cl.`link_rewrite`
				FROM `'._DB_PREFIX_.'cms_category` bcp'.
                $join_shop.'
				INNER JOIN `'._DB_PREFIX_.'cms_category_lang` cl
				ON (bcp.`id_cms_category` = cl.`id_cms_category`)
				WHERE cl.`id_lang` = '.(int)$id_lang.'
				AND bcp.`id_parent` = '.(int)$parent.
                $where_shop.'
                ORDER BY cl.`meta_title`';

            $results = Db::getInstance()->executeS($sql);
            foreach ($results as $result) {
                $sub_categories = $this->getCMSCategories(true, $result['id_cms_category'], (int)$id_lang);
                if ($sub_categories && count($sub_categories) > 0) {
                    $result['sub_categories'] = $sub_categories;
                }
                $categories[] = $result;
            }

            return isset($categories) ? $categories : false;
        }
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...