Jump to content

[Résolu] Affichage des Fabricants dans un ordre alphabétique


Recommended Posts

voila :

static public function getManufacturers($getNbProducts = false, $id_lang = 0, $active = false, $p = false, $n = false)
   {
       if (!$id_lang)
           $id_lang = Configuration::get('PS_LANG_DEFAULT');
       $sql = 'SELECT m.*, ml.`description`';
       if ($getNbProducts) $sql.= ' , COUNT(p.`id_product`) as nb_products';
       $sql.= ' FROM `'._DB_PREFIX_.'manufacturer` as m
       LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.intval($id_lang).')';
       if ($getNbProducts)
           $sql.= ' LEFT JOIN `'._DB_PREFIX_.'product` as p ON (p.`id_manufacturer` = m.`id_manufacturer`)
           '.($active ? 'WHERE p.`active` = 1' : '').'
           GROUP BY m.`id_manufacturer`';
       $sql.= ' ORDER BY m.`name` ASC'.($p ? ' LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n) : '');
       $manufacturers = Db::getInstance()->ExecuteS($sql);
       if ($manufacturers === false)
           return false;

       for ($i = 0; $i < sizeof($manufacturers); $i++)
           if (intval(Configuration::get('PS_REWRITING_SETTINGS')))
               $manufacturers[$i]['link_rewrite'] = Tools::link_rewrite($manufacturers[$i]['name'], false);
           else
               $manufacturers[$i]['link_rewrite'] = 0;
       return $manufacturers;
   }

   static public function getManufacturersWithoutAddress()
   {
       $sql = 'SELECT m.* FROM `'._DB_PREFIX_.'manufacturer` m
               LEFT JOIN `'._DB_PREFIX_.'address` a ON (a.`id_manufacturer` = m.`id_manufacturer` AND a.`deleted` = 0)
               WHERE a.`id_manufacturer` IS NULL';
       return Db::getInstance()->ExecuteS($sql);
   }



et ca :

static public function getManufacturers($getNbProducts = false, $id_lang = 0, $active = false, $p = false, $n = false)
   {
       if (!$id_lang)
           $id_lang = Configuration::get('PS_LANG_DEFAULT');
       $sql = 'SELECT m.*, ml.`description`';
       if ($getNbProducts) $sql.= ' , COUNT(p.`id_product`) as nb_products';
       $sql.= ' FROM `'._DB_PREFIX_.'manufacturer` as m
       LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.intval($id_lang).')';
       if ($getNbProducts)
           $sql.= ' LEFT JOIN `'._DB_PREFIX_.'product` as p ON (p.`id_manufacturer` = m.`id_manufacturer`)
           '.($active ? 'WHERE p.`active` = 1' : '').'
           GROUP BY m.`id_manufacturer`';
       $sql.= ' ORDER BY m.`name` ASC'.($p ? ' LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n) : '');
       $manufacturers = Db::getInstance()->ExecuteS($sql);
       if ($manufacturers === false)
           return false;

       for ($i = 0; $i < sizeof($manufacturers); $i++)
           if (intval(Configuration::get('PS_REWRITING_SETTINGS')))
               $manufacturers[$i]['link_rewrite'] = Tools::link_rewrite($manufacturers[$i]['name'], false);
           else
               $manufacturers[$i]['link_rewrite'] = 0;
       return $manufacturers;
   }

   static public function getManufacturersWithoutAddress()
   {
       $sql = 'SELECT m.* FROM `'._DB_PREFIX_.'manufacturer` m
               LEFT JOIN `'._DB_PREFIX_.'address` a ON (a.`id_manufacturer` = m.`id_manufacturer` AND a.`deleted` = 0)
               WHERE a.`id_manufacturer` IS NULL';
       return Db::getInstance()->ExecuteS($sql);
   }


Merci de ton aide

Link to comment
Share on other sites


       $sql.= ' ORDER BY m.`name` ASC'.($p ? ' LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n) : '');




Pourtant ça semble bien trié par ordre alphabétique sur le nom du fabricant.

Mais pourquoi tu as collé deux fois le même code ?
Link to comment
Share on other sites

Pourrais-tu insérer :

echo $sql;

Avant la ligne :

$manufacturers = Db::getInstance()->ExecuteS($sql);

Ensuite recharge la page d'accueil de ta boutique.

Ensuite montre nous la requete ecrite tout en haut de la page d'accueil

Link to comment
Share on other sites

la fonction elle été en 2 fois, alors je l'ai mis en 2 fois ...
mais c est peut etre avec des conditions differente ...

ou sinon je viens de faire ce que tu m'as dis Mambe, et voila ce que ca donne :

SELECT m.*, ml.`description` FROM `ps_manufacturer` as m LEFT JOIN `ps_manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = 2) ORDER BY m.`name` ASC

Link to comment
Share on other sites

Etrange, la requete renvoi bien la liste des fournisseur triée par le nom du fournisseur. (ORDER BY m.`name`)

N-y-a-t-il pas un ou plusieurs espaces devant certains nom de fournisseurs?

Sinon, je ne vois pas trop la

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...