hurraken Posted May 4, 2010 Share Posted May 4, 2010 Bonjour à tous,J'ai tenté de tripatouiller le fichier link.php pour obtenir l'id de category dans l'url de mes fiches produits mais sans succès.Je souhaiterais obtenir une url du type http://xxx/product.php?id_product=1&id_category=4'>http://xxx/product.php?id_product=1&id_category=4 au lieu de http://xxx/product.php?id_product=1Le but est d'avoir les boutons de catégories de mon menu en current lorsque le visiteur est sur un produit.Je vous remercie d'avance de votre aide.Cordialement. Link to comment Share on other sites More sharing options...
BVince Posted May 4, 2010 Share Posted May 4, 2010 Hi,pour récupérer l'id catégorie d'un produit, je fais comme ça : $product = new Product(intval($_GET['id_product'])); if (isset($product) AND Validate::isLoadedObject($product)) $ActiveCategory = intval($product->id_category_default); et voilà.... Link to comment Share on other sites More sharing options...
hurraken Posted May 4, 2010 Author Share Posted May 4, 2010 Bonjour Vince,Merci pour ta réponse.Mais où dois-je intégrer ce morceau de code pour que l'url contiennent l'id de la catégorie ? Link to comment Share on other sites More sharing options...
BVince Posted May 4, 2010 Share Posted May 4, 2010 Non, l'url ne contiendra jamais l'id de la catégorie, mais si tu regardes le code, l'id du produit te permet de récupérer l'id catégorie par défaut de ce produit sans que cela soit passé en url. Link to comment Share on other sites More sharing options...
hurraken Posted May 4, 2010 Author Share Posted May 4, 2010 J'imagine que je dois triturer le code sur product.php au niveau de : $product = new Product(intval($_GET['id_product']), true, intval($cookie->id_lang)); if (!Validate::isLoadedObject($product) OR !$product->active) $errors[] = Tools::displayError('product is no longer available'); elseif (!$product->checkAccess(intval($cookie->id_customer))) $errors[] = Tools::displayError('you do not have access to this product'); else { Je vais tester.Merci encore BVince Link to comment Share on other sites More sharing options...
hurraken Posted May 4, 2010 Author Share Posted May 4, 2010 Erf, ça ne marche pas.Merci tout de même Link to comment Share on other sites More sharing options...
BVince Posted May 4, 2010 Share Posted May 4, 2010 La portion de code que je t'ai fourni te permet d'obtenir dans $ActiveCategory la catégorie du produit en cours, donc c'est ton module menu que tu dois modifier pour affecter la classe current selon ton besoin à l'aide de la variable $ActiveCategory. Et ne baisse pas les bras en 3 secondes et demi en mettant "ça marche pas", "Si vous donnez un poisson à un pauvre, il mangera un jour; mais si vous lui apprenez à pêcher, il mangera tous les jours" Link to comment Share on other sites More sharing options...
hurraken Posted May 4, 2010 Author Share Posted May 4, 2010 Re BVince,Ton proverbe est bien approprié mais je dois fournir ce menu rapidement à un client qui croit que je suis un cador en prestashop, or ce n'est pas le cas. Celà dit, je trouve Prestashop vraiment super.Le menu que j'utilise est le module categoriesbar. il y a un fichier tpl et un php. Le fichier php semblent envoyer les variables dans le tpl et là, je ne comprend rien.Ton code doit certainement s'insérer à cet endroit (.tpl) //construct categories $depth = 0; $rootCateg = Category::getRootCategory()->recurseLiteCategTree($depth); if (isset($_GET['id_category'])) $ActiveCategory = intval($product->id_category_default); $smarty->assign('currentCategoryId', intval($_GET['id_category'])); $smarty->assign('bar_tpl_path', _PS_MODULE_DIR_.'categoriesbar/category-bar-level.tpl'); $smarty->assign('categoriesLevel', $rootCateg); return $this->display(__FILE__, 'categoriesbar.tpl'); et pour envoyer ses variables ici (.php) : {foreach from=$categoriesLevel.children item=child name=categoriesLevel} {if $smarty.foreach.categoriesLevel.last} {include file=$bar_tpl_path node=$child last='true'} {else} {include file=$bar_tpl_path node=$child} {/if} {/foreach} Je ne pige absolument pas la logique !!Si tu pouvais au moins me mettre sur la piste...Merci encore pour tout ce que tu faisEDIT : le premier bloc de code est erroné, il comporte le tien : $depth = 0; $rootCateg = Category::getRootCategory()->recurseLiteCategTree($depth); if (isset($_GET['id_category'])) $smarty->assign('currentCategoryId', intval($_GET['id_category'])); $smarty->assign('bar_tpl_path', _PS_MODULE_DIR_.'categoriesbar/category-bar-level.tpl'); $smarty->assign('categoriesLevel', $rootCateg); return $this->display(__FILE__, 'categoriesbar.tpl'); } Link to comment Share on other sites More sharing options...
BVince Posted May 4, 2010 Share Posted May 4, 2010 Je ferais comme ça : $depth = 0; $rootCateg = Category::getRootCategory()->recurseLiteCategTree($depth); $ActiveCategory = ""; if (isset($_GET['id_category'])) $ActiveCategory = intval($_GET['id_category']); if (isset($_GET['id_product'])) { $product = new Product(intval($_GET['id_product'])); if (isset($product) AND Validate::isLoadedObject($product)) $ActiveCategory = intval($product->id_category_default); } $smarty->assign('currentCategoryId', $ActiveCategory); $smarty->assign('bar_tpl_path', _PS_MODULE_DIR_.'categoriesbar/category-bar-level.tpl'); $smarty->assign('categoriesLevel', $rootCateg); return $this->display(__FILE__, 'categoriesbar.tpl'); Link to comment Share on other sites More sharing options...
hurraken Posted May 4, 2010 Author Share Posted May 4, 2010 Ca me retourne une page blanche mais c'est de ma faute, je n'ai pas communiqué la fin du code et du coup il y a deux return.La fin du code du .php : /** * Returns module content for header * * @param array $params Parameters * @return string Content */ function hookTop($params) { global $smarty; //construct categories $depth = 0; $rootCateg = Category::getRootCategory()->recurseLiteCategTree($depth); if (isset($_GET['id_category'])) $smarty->assign('currentCategoryId', intval($_GET['id_category'])); $smarty->assign('bar_tpl_path', _PS_MODULE_DIR_.'categoriesbar/category-bar-level.tpl'); $smarty->assign('categoriesLevel', $rootCateg); return $this->display(__FILE__, 'categoriesbar.tpl'); } function hookNavbar($params) { return $this->hookTop($params); } } ?> EDIT : que ton nom soit loué à travers les âges BVince !Ca marche !!!Mille mercis pour ton aide !! Link to comment Share on other sites More sharing options...
BVince Posted May 4, 2010 Share Posted May 4, 2010 Tu as essayé les modifications de code que je t'ai donné plus haut ? Link to comment Share on other sites More sharing options...
BVince Posted May 4, 2010 Share Posted May 4, 2010 /** * Returns module content for header * * @param array $params Parameters * @return string Content */ function hookTop($params) { global $smarty; //construct categories $depth = 0; $rootCateg = Category::getRootCategory()->recurseLiteCategTree($depth); $ActiveCategory = ""; if (isset($_GET['id_category'])) $ActiveCategory = intval($_GET['id_category']); if (isset($_GET['id_product'])) { $product = new Product(intval($_GET['id_product'])); if (isset($product) AND Validate::isLoadedObject($product)) $ActiveCategory = intval($product->id_category_default); } if($ActiveCategory!="") $smarty->assign('currentCategoryId', $ActiveCategory); $smarty->assign('bar_tpl_path', _PS_MODULE_DIR_.'categoriesbar/category-bar-level.tpl'); $smarty->assign('categoriesLevel', $rootCateg); return $this->display(__FILE__, 'categoriesbar.tpl'); } function hookNavbar($params) { return $this->hookTop($params); } } ?> Link to comment Share on other sites More sharing options...
hurraken Posted May 4, 2010 Author Share Posted May 4, 2010 Oui camarade, je l'avais insérer comme un manche (voir mes remerciements plus haut) Link to comment Share on other sites More sharing options...
BVince Posted May 4, 2010 Share Posted May 4, 2010 Impeccable, je pense que le code au dessus ressemble plus à ce que tu as fait.....et ça marche !!!!Bye. 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