nicola10 Posted July 19, 2012 Share Posted July 19, 2012 Ciao a tutti sto usando la versione 1.4.8.2 di prestashop ed ho installato il modulo menu dhtml by tom06 per la visualizzazione del menu In questo modulo non è prevista la funzione per la riscrittura degli url Qualcuno potrebbe aiutarmi? E' un vecchio modulo e nonostante ciò non sono riuscito a trovare alcuna informazione Il seguente codice è del file blockcategoriesmdi.php <?php // remerciements (me contacter si je vous ai oublié ) // // Merci à "regreg", "Henri TORRES" // class BlockCategoriesMDI extends Module { public function __construct() { $this->name = 'blockcategoriesmdi'; $this->tab = 'Blocks'; $this->version = 1.1; parent::__construct(); $this->page = basename(__file__,'.php'); $this->displayName = $this->l('Menu DHTML by Tom06'); $this->description = $this->l('Add a dhtml menu in your site'); } function install() { if (parent::install() == false OR $this->registerHook('leftColumn') == false OR Configuration::updateValue('BLOCK_CATEGMDI_MAX_DEPTH', 4) == false) return false; return true; } public function getContent() { $output = '<h2>'.$this->displayName.'</h2>'; if (Tools::isSubmit('submitBlockCategories')) { $maxDepth = intval(Tools::getValue('maxDepth')); if ($maxDepth <= 0) { $output .= '<div class="alert error">'.$this->l('Maximum depth: Invalid number.').'</div>'; } else { Configuration::updateValue('BLOCK_CATEGMDI_MAX_DEPTH', intval($maxDepth)); $output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>'; } } return $output.$this->displayForm(); } public function displayForm() { return ' <form action="'.$_SERVER['REQUEST_URI'].'" method="post"> <fieldset> <legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend> <label>'.$this->l('Maximum depth').'</label> <div class="margin-form"> <input type="text" name="maxDepth" value="'.Configuration::get('BLOCK_CATEGMDI_MAX_DEPTH').'" /> <p class="clear">'.$this->l('Set the maximum depth of sublevels displayed in this block').'</p> </div> <center><input type="submit" name="submitBlockCategories" value="'.$this->l('Save').'" class="button" /></center> </fieldset> </form>'; } public function hookLeftColumn($params) { // Numéro d'identification des sous menu // $ID_ddsubmenuside = 0; /////////////////////////////////////////// global $smarty; /* ONLY FOR THEME OLDER THAN v1.0 */ global $link; $smarty->assign(array( 'categories' => Category::getHomeCategories(intval($params['cookie']->id_lang), true), 'link' => $link )); /* ELSE */ function NbSousCategories ($id_parent){ global $Depth_max; $sql = 'SELECT count(*) as Nombre FROM '._DB_PREFIX_.'category c WHERE c.active = 1 AND c.id_parent = '.$id_parent.' AND c.level_depth <= '.Configuration::get('BLOCK_CATEGMDI_MAX_DEPTH'); $resultat = Db::getInstance()->Execute($sql); $r = mysql_fetch_assoc($resultat); return $r['Nombre']; } function recupSousCategories ($id_parent,$mode,$id_sub,$idlang) { // $mode=1 si c'est le 1er niveau de sous catégorie, sinon $mode=2 // requête à executer $sql = 'SELECT c.id_category, cl.name FROM '._DB_PREFIX_.'category c LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (c.id_category = cl.id_category AND id_lang = '.$idlang.') WHERE c.active = 1 AND c.id_parent = '.$id_parent.' AND level_depth <= '.Configuration::get('BLOCK_CATEGMDI_MAX_DEPTH').' ORDER BY level_depth, cl.name ASC'; // Exécution de la requête $resultat = Db::getInstance()->Execute($sql); // Si la requête est vide on renvoit vide if (mysql_num_rows($resultat)==0){ return ''; } // Préparation du texte if($mode=='1'){ $LignesSousCat = $LignesSousCat.'<ul id="ddsubmenuside'.$id_sub.'" class="ddsubmenustyle blackwhite">'; } else { $LignesSousCat = $LignesSousCat.'<ul>'; } // Sinon lecture des sous catégories et mise en place while($res = mysql_fetch_assoc($resultat)){ // Lecture du nombre de sous catégories $NbSousCat = NbSousCategories($res['id_category']); $chaine = '<li><a href="category.php?id_category=%d">%s</a>'; $LignesSousCat = $LignesSousCat.sprintf($chaine,$res['id_category'],Category::HideCategoryPosition($res['name'])); // Si il y a encore un niveau inférieur dans le menu if( $NbSousCat>0 ){ $LignesSousCat = $LignesSousCat.recupSousCategories($res['id_category'],'2','',$idlang); } // On ferme la ligne $LignesSousCat = $LignesSousCat.'</li>'; } $LignesSousCat = $LignesSousCat.'</ul>'; return $LignesSousCat; } $req_cat = ' SELECT * FROM '._DB_PREFIX_.'category c LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (c.id_category = cl.id_category AND id_lang = '.intval($params['cookie']->id_lang).') WHERE c.active = 1 AND c.level_depth=2 AND c.id_parent = 1 ORDER BY level_depth, c.id_category ASC'; // CONDIZIONE ORIGINALE RIGA 131 WHERE c.active = 1 AND c.level_depth=1 // LECTURE DES CATEGORIES $result = Db::getInstance()->Execute($req_cat); // Si aucune catégorie de trouvé if(mysql_num_rows($result)==0){ $smarty->assign('lignes_menu_parent','<li>*** VIDE ***</li>'); $smarty->assign('lignes_sous_categories',''); return $this->display(__FILE__, $this->name.'.tpl'); } // Sinon on lit les catégories, sous-catégories, etc ... while ($categorie_parent = mysql_fetch_assoc($result)){ $NbSousCat = NbSousCategories($categorie_parent['id_category']); // Ajout de la catégorie $lignes_menu_parent = $lignes_menu_parent.'<li><a href="'.link::getCategoryLink($categorie_parent['id_category']).'"'; // Si il y a des sous catégories, on attribue un code de liaison if( $NbSousCat>'0' ){ $ID_ddsubmenuside = ($ID_ddsubmenuside+1); $lignes_menu_parent = $lignes_menu_parent.' rel="ddsubmenuside'.$ID_ddsubmenuside.'"'; } // On termine la ligne en cours $lignes_menu_parent = $lignes_menu_parent.'>'.Category::HideCategoryPosition($categorie_parent['name']).'</a></li>'; // Si il y a des sous catégories, on lit la suite if( $NbSousCat>'0' ){ $SousCategories = $SousCategories.recupSousCategories($categorie_parent['id_category'],'1',$ID_ddsubmenuside,intval($params['cookie']->id_lang)); } } // On copie les lignes dans le template $smarty->assign('lignes_menu_parent',$lignes_menu_parent); $smarty->assign('lignes_sous_categories',$SousCategories); return $this->display(__FILE__, $this->name.'.tpl'); } public function hookRightColumn($params) { return $this->hookLeftColumn($params); } } ?> E questo è il file blockcategoriesmdi.tpl <!-- Block categories module --> <script type="text/javascript" src="{$base_dir}modules/blockcategoriesmdi/ddlevelsmenu.js"></script> <link rel="stylesheet" type="text/css" href="{$base_dir}modules/blockcategoriesmdi/ddlevelsmenu-sidebar.css" /> <link rel="stylesheet" type="text/css" href="{$base_dir}modules/blockcategoriesmdi/ddlevelsmenu-topbar.css" /> <link rel="stylesheet" type="text/css" href="{$base_dir}modules/blockcategoriesmdi/ddlevelsmenu-base.css" /> <div id="categories_block_left" class="block"> <h4>{l s='CATALOGO' mod='blockcategories'}</h4> <div class="block_content"> <div id="ddsidemenubar" class="markermenu"> <ul> <li class="primo"></li> {$lignes_menu_parent} <li class="primo"></li> </ul> </div> </div> </div> <script type="text/javascript"> ddlevelsmenu.setup("ddsidemenubar", "sidebar") </script> <div> {$lignes_sous_categories} </div> <!-- /Block categories module --> Link to comment Share on other sites More sharing options...
nicola10 Posted July 19, 2012 Author Share Posted July 19, 2012 (edited) Cercando nel forum ho letto che in casi del genere oltre ad avere una buona base di PHP (che non ho) e una buona conoscenza di Prestashop (idem come per PHP) Nel file /classes/Link.php alla riga 131 c'è la funzione getCategoryLink public function getCategoryLink($id_category, $alias = NULL, $id_lang = NULL) { if (is_object($id_category)) return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).(int)($id_category->id).'-'.$id_category->link_rewrite) : (_PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category->id)); if ($alias) return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).(int)($id_category).'-'.$alias) : (_PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category)); return _PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category); } Nel file blockcategoriesmdi.php ci sono queste 2 funzioni NbSousCategories function NbSousCategories ($id_parent){ global $Depth_max; $sql = 'SELECT count(*) as Nombre FROM '._DB_PREFIX_.'category c WHERE c.active = 1 AND c.id_parent = '.$id_parent.' AND c.level_depth <= '.Configuration::get('BLOCK_CATEGMDI_MAX_DEPTH'); $resultat = Db::getInstance()->Execute($sql); $r = mysql_fetch_assoc($resultat); return $r['Nombre']; } recupSousCategories function recupSousCategories ($id_parent,$mode,$id_sub,$idlang) { // $mode=1 si c'est le 1er niveau de sous catégorie, sinon $mode=2 // requête à executer $sql = 'SELECT c.id_category, cl.name FROM '._DB_PREFIX_.'category c LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (c.id_category = cl.id_category AND id_lang = '.$idlang.') WHERE c.active = 1 AND c.id_parent = '.$id_parent.' AND level_depth <= '.Configuration::get('BLOCK_CATEGMDI_MAX_DEPTH').' ORDER BY level_depth, cl.name ASC'; // Exécution de la requête $resultat = Db::getInstance()->Execute($sql); // Si la requête est vide on renvoit vide if (mysql_num_rows($resultat)==0){ return ''; } // Préparation du texte if($mode=='1'){ $LignesSousCat = $LignesSousCat.'<ul id="ddsubmenuside'.$id_sub.'" class="ddsubmenustyle blackwhite">'; } else { $LignesSousCat = $LignesSousCat.'<ul>'; } // Sinon lecture des sous catégories et mise en place while($res = mysql_fetch_assoc($resultat)){ // Lecture du nombre de sous catégories $NbSousCat = NbSousCategories($res['id_category']); $chaine = '<li><a href="category.php?id_category=%d">%s</a>'; $LignesSousCat = $LignesSousCat.sprintf($chaine,$res['id_category'],Category::HideCategoryPosition($res['name'])); // Si il y a encore un niveau inférieur dans le menu if( $NbSousCat>0 ){ $LignesSousCat = $LignesSousCat.recupSousCategories($res['id_category'],'2','',$idlang); } // On ferme la ligne $LignesSousCat = $LignesSousCat.'</li>'; } $LignesSousCat = $LignesSousCat.'</ul>'; return $LignesSousCat; } Quindi da quanto ho capito dovrei aggiungere le 2 funzioni del modulo in Link.php ed aggiungere il parametro link_rewrite nelle 2 funzioni scritte nel file blockcategoriesmdi.php Nel modulo blockcategories presente nella distribuzione normale di Prestashop $link viene costruito così: public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0) { global $link; $children = array(); if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth)) foreach ($resultParents[$id_category] as $subcat) $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1); if (!isset($resultIds[$id_category])) return false; return array('id' => $id_category, 'link' => $link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'], 'children' => $children); } Mentre in blockcategoriesmdi.php $link viene costruito così: global $link; $smarty->assign(array( 'categories' => Category::getHomeCategories(intval($params['cookie']->id_lang), true), 'link' => $link )); $chaine = '<li><a href="category.php?id_category=%d">%s</a>'; Edited July 19, 2012 by nicola10 (see edit history) 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