Fablux Posted November 21, 2013 Share Posted November 21, 2013 Hi, excuse me for my bad english. I have a problem with the module topmenu. The root category link on topmenu go to my index page. I must go in category root when i click on category! This is my site http://www.eltmegastore.com the root category is PRODOTTI. Can you help me? Thank's! Link to comment Share on other sites More sharing options...
vekia Posted November 21, 2013 Share Posted November 21, 2013 you mean that you want to open root category page? where the subcategories will be listed? Link to comment Share on other sites More sharing options...
Fablux Posted November 21, 2013 Author Share Posted November 21, 2013 you mean that you want to open root category page? where the subcategories will be listed? Yes! This is the root category link http://www.eltmegastore.com/2-prodotti Link to comment Share on other sites More sharing options...
vekia Posted November 21, 2013 Share Posted November 21, 2013 in this case it will be necessary to modify the block top menu php file (blocktopmenu.php) there is a switch code which generates links in top menu, Link to comment Share on other sites More sharing options...
Fablux Posted November 21, 2013 Author Share Posted November 21, 2013 in this case it will be necessary to modify the block top menu php file (blocktopmenu.php) there is a switch code which generates links in top menu, private function makeMenuOption() { $menu_item = $this->getMenuItems(); $id_lang = (int)$this->context->language->id; $id_shop = (int)Shop::getContextShopID(); foreach ($menu_item as $item) { if (!$item) continue; preg_match($this->pattern, $item, $values); $id = (int)substr($item, strlen($values[1]), strlen($item)); switch (substr($item, 0, strlen($values[1]))) { case 'CAT': $category = new Category((int)$id, (int)$id_lang); if (Validate::isLoadedObject($category)) $this->_html .= '<option value="CAT'.$id.'">'.$category->name.'</option>'.PHP_EOL; break; case 'PRD': $product = new Product((int)$id, true, (int)$id_lang); if (Validate::isLoadedObject($product)) $this->_html .= '<option value="PRD'.$id.'">'.$product->name.'</option>'.PHP_EOL; break; case 'CMS': $cms = new CMS((int)$id, (int)$id_lang); if (Validate::isLoadedObject($cms)) $this->_html .= '<option value="CMS'.$id.'">'.$cms->meta_title.'</option>'.PHP_EOL; break; case 'CMS_CAT': $category = new CMSCategory((int)$id, (int)$id_lang); if (Validate::isLoadedObject($category)) $this->_html .= '<option value="CMS_CAT'.$id.'">'.$category->name.'</option>'.PHP_EOL; break; case 'MAN': $manufacturer = new Manufacturer((int)$id, (int)$id_lang); if (Validate::isLoadedObject($manufacturer)) $this->_html .= '<option value="MAN'.$id.'">'.$manufacturer->name.'</option>'.PHP_EOL; break; case 'SUP': $supplier = new Supplier((int)$id, (int)$id_lang); if (Validate::isLoadedObject($supplier)) $this->_html .= '<option value="SUP'.$id.'">'.$supplier->name.'</option>'.PHP_EOL; break; case 'LNK': $link = MenuTopLinks::get((int)$id, (int)$id_lang, (int)$id_shop); if (count($link)) { if (!isset($link[0]['label']) || ($link[0]['label'] == '')) { $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks::get($link[0]['id_linksmenutop'], (int)$default_language, (int)Shop::getContextShopID()); } $this->_html .= '<option value="LNK'.$link[0]['id_linksmenutop'].'">'.$link[0]['label'].'</option>'; } break; case 'SHOP': $shop = new Shop((int)$id); if (Validate::isLoadedObject($shop)) $this->_html .= '<option value="SHOP'.(int)$id.'">'.$shop->name.'</option>'.PHP_EOL; break; } } } private function makeMenu() { $menu_items = $this->getMenuItems(); $id_lang = (int)$this->context->language->id; $id_shop = (int)Shop::getContextShopID(); foreach ($menu_items as $item) { if (!$item) continue; preg_match($this->pattern, $item, $value); $id = (int)substr($item, strlen($value[1]), strlen($item)); switch (substr($item, 0, strlen($value[1]))) { case 'CAT': $this->getCategory((int)$id); break; case 'PRD': $selected = ($this->page_name == 'product' && (Tools::getValue('id_product') == $id)) ? ' class="sfHover"' : ''; $product = new Product((int)$id, true, (int)$id_lang); if (!is_null($product->id)) $this->_menu .= '<li'.$selected.'><a href="'.$product->getLink().'">'.$product->name.'</a></li>'.PHP_EOL; break; case 'CMS': $selected = ($this->page_name == 'cms' && (Tools::getValue('id_cms') == $id)) ? ' class="sfHover"' : ''; $cms = CMS::getLinks((int)$id_lang, array($id)); if (count($cms)) $this->_menu .= '<li'.$selected.'><a href="'.$cms[0]['link'].'">'.$cms[0]['meta_title'].'</a></li>'.PHP_EOL; break; case 'CMS_CAT': $category = new CMSCategory((int)$id, (int)$id_lang); if (count($category)) { $this->_menu .= '<li><a href="'.$category->getLink().'">'.$category->name.'</a>'; $this->getCMSMenuItems($category->id); $this->_menu .= '</li>'.PHP_EOL; } break; case 'MAN': $selected = ($this->page_name == 'manufacturer' && (Tools::getValue('id_manufacturer') == $id)) ? ' class="sfHover"' : ''; $manufacturer = new Manufacturer((int)$id, (int)$id_lang); if (!is_null($manufacturer->id)) { if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) $manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name, false); else $manufacturer->link_rewrite = 0; $link = new Link; $this->_menu .= '<li'.$selected.'><a href="'.$link->getManufacturerLink((int)$id, $manufacturer->link_rewrite).'">'.$manufacturer->name.'</a></li>'.PHP_EOL; } break; case 'SUP': $selected = ($this->page_name == 'supplier' && (Tools::getValue('id_supplier') == $id)) ? ' class="sfHover"' : ''; $supplier = new Supplier((int)$id, (int)$id_lang); if (!is_null($supplier->id)) { $link = new Link; $this->_menu .= '<li'.$selected.'><a href="'.$link->getSupplierLink((int)$id, $supplier->link_rewrite).'">'.$supplier->name.'</a></li>'.PHP_EOL; } break; case 'SHOP': $selected = ($this->page_name == 'index' && ($this->context->shop->id == $id)) ? ' class="sfHover"' : ''; $shop = new Shop((int)$id); if (Validate::isLoadedObject($shop)) { $link = new Link; $this->_menu .= '<li'.$selected.'><a href="'.$shop->getBaseURL().'">'.$shop->name.'</a></li>'.PHP_EOL; } break; case 'LNK': $link = MenuTopLinks::get((int)$id, (int)$id_lang, (int)$id_shop); if (count($link)) { if (!isset($link[0]['label']) || ($link[0]['label'] == '')) { $default_language = Configuration::get('PS_LANG_DEFAULT'); $link = MenuTopLinks::get($link[0]['id_linksmenutop'], $default_language, (int)Shop::getContextShopID()); } $this->_menu .= '<li><a href="'.$link[0]['link'].'"'.(($link[0]['new_window']) ? ' target="_blank"': '').'>'.$link[0]['label'].'</a></li>'.PHP_EOL; } break; } } } There are two switch; makeMenuOption( ) and makeMenu( ) What is my switch? Thank's for support! Link to comment Share on other sites More sharing options...
vekia Posted November 21, 2013 Share Posted November 21, 2013 one simple change: private function getCategory($id_category, $id_lang = false, $id_shop = false) { $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id; $category = new Category((int)$id_category, (int)$id_lang); if ($category->level_depth > 1) change if ($category->level_depth > 1) to if ($category->level_depth > 0) Link to comment Share on other sites More sharing options...
Fablux Posted November 22, 2013 Author Share Posted November 22, 2013 one simple change: change if ($category->level_depth > 1) to if ($category->level_depth > 0) with this change, nothing happens. Link to comment Share on other sites More sharing options...
vekia Posted November 22, 2013 Share Posted November 22, 2013 after that you have to recompile module, just hit "save" button on module configuration page after that this method will work Link to comment Share on other sites More sharing options...
Fablux Posted November 22, 2013 Author Share Posted November 22, 2013 Does not work, faulting module. Link to comment Share on other sites More sharing options...
vekia Posted November 24, 2013 Share Posted November 24, 2013 what you see after clicking on "save" ? turn on error reporting, you will see what's goin on there (what and where causing problem) Link to comment Share on other sites More sharing options...
Fablux Posted November 25, 2013 Author Share Posted November 25, 2013 After chlicking on save it's regular, when i save it's total white in FO and error in BO. Before, when i modify ($category->level_depth > 0) the module topmenu it's vanish from the module list in BO! Link to comment Share on other sites More sharing options...
vekia Posted November 25, 2013 Share Posted November 25, 2013 turn on error reporting will see what's goin on there. it's almost impossible that change from 1 to 0 causing this - or it is, but probably because of there is not enough memory to regenerate menu Link to comment Share on other sites More sharing options...
imachine Posted December 24, 2016 Share Posted December 24, 2016 I confirm this works, also in 1.7 - the file to edit is ps_mainmenu.php in ps_mainmenu inside modules/ Same line to be modified, result as expected. 1 Link to comment Share on other sites More sharing options...
U1yss Posted October 28, 2021 Share Posted October 28, 2021 works on 1.7.7.1 thanks! 1 Link to comment Share on other sites More sharing options...
SANDU Posted November 2, 2021 Share Posted November 2, 2021 hi guys, this solution worked for me for a while, however, probably after an update of prestashop, it went back to earlier method. do I need to avoid any updates in the future? or maybe I have to edit the .tpl file as well in order to get this working forever? 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