patouki 0 Posted March 2, 2012 Bonjour, voici mon site Je voudrais afficher 3 produits au hasard par catégorie. Est-ce possible ? Pourrais-je avoir des pistes ? Merci. Share this post Link to post Share on other sites
benoit@ignis.fr 0 Posted March 2, 2012 peut-etre une idée ... ? prendre tout les produits d'une catégorie, et arriver a les ordonner alléatoirement (voir si y'a pas un order by =rand quelque par a mettre)... puis prendre les 3 premiers de la liste seulement. Share this post Link to post Share on other sites
patouki 0 Posted March 2, 2012 je peux récupérer directement de la base de donnée et écrire en PHP ou dois-je passer par Smarty ? ( que je ne gère as bien ) Share this post Link to post Share on other sites
ericdel 11 Posted March 5, 2012 Effectivement, j'ai fait comme Benoit dit : récupérer tous les produits, appliquer un shuffle($products) et prendre les 3 premiers Share this post Link to post Share on other sites
luci1 9 Posted March 6, 2012 Bonjour, Voilà ce que j'ai pour la version 1.4.6.2 : Dans le controller "controllers/CategoryController.php" on remarque que par défaut, les produit sont chargés dans la fonction productListAssign, plus particulièrement à la ligne suivante (167 chez moi ): $this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay); Et si on regarde en détail ce que fait cette fonction : /** * Return current category products * * @param integer $id_lang Language ID * @param integer $p Page number * @param integer $n Number of products per page * @param boolean $getTotal return the number of results instead of the results themself * @param boolean $active return only active products * @param boolean $random active a random filter for returned products * @param int $randomNumberProducts number of products to return if random is activated * @param boolean $checkAccess set to false to return all products (even if customer hasn't access) * @return mixed Products or number of products */ public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $checkAccess = true) { ... le code de la fonction } ON remarque donc qu'il y a deux paramètres qui nous intéressent plus particulièrement , les paramètres : * @param boolean $random active a random filter for returned products * @param int $randomNumberProducts number of products to return if random is activated en les utilisant correctement, on obtiens ce que tu souhaites avoir : $this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay, false, true, true, 3); Share this post Link to post Share on other sites