Jump to content

Top Horizontal Menù Links In Sifferent Languages


silvioscavone

Recommended Posts

Hello, I mofified blocktopmenu-php in order to have some external links.

 

Now I want a different link depending on the language selected by the user. I'm trying the following code, but it doesn't works, any help?

 protected function getCMSMenuItems($parent, $depth = 1, $id_lang = false)
    {
        $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id;
 
        if ($depth > 3) {
            return;
        }
 
        $categories = $this->getCMSCategories(false, (int)$parent, (int)$id_lang);
        $pages = $this->getCMSPages((int)$parent);
 
        if (count($categories) || count($pages)) {
            $this->_menu .= '<ul>';
 
            foreach ($categories as $category) {
                $cat = new CMSCategory((int)$category['id_cms_category'], (int)$id_lang);
 
                $this->_menu .= '<li>';
                $this->_menu .= '<a href="'.Tools::HtmlEntitiesUTF8($cat->getLink()).'">'.$category['name'].'</a>';
                $this->getCMSMenuItems($category['id_cms_category'], (int)$depth + 1);
                $this->_menu .= '</li>';
            }
if (Context::getContext()->customer->isLogged())
 
{
foreach ($pages as $page)
{
$cms = new CMS($page['id_cms'], (int)$id_lang);
$links = $cms->getLinks((int)$id_lang, array((int)$cms->id));
 
$selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
 
 
if ($cms->id==13){
$this->_menu .= '<li '.$selected.'>';
$this->_menu .= '<a href="http://newsite.rimaoil.it/listini/listino_raccordi_tubo_flessibile.pdf" target="_blank">'.$cms->meta_title.'</a>';
$this->_menu .= '</li>';
                }
else if ($cms->id==14){
$this->_menu .= '<li '.$selected.'>';
$this->_menu .= '<a href="http://newsite.rimaoil.it/listini/listino_tubi_flessibili.pdf" target="_blank">'.$cms->meta_title.'</a>';
$this->_menu .= '</li>';
                }
else if ($cms->id==19){
$this->_menu .= '<li '.$selected.'>';
$this->_menu .= '<a href="http://newsite.rimaoil.it/listini/listino_raccordi_parker.pdf" target="_blank">'.$cms->meta_title.'</a>';
$this->_menu .= '</li>';
                }
else if ($cms->id==20){
$this->_menu .= '<li '.$selected.'>';
$this->_menu .= '<a href="http://newsite.rimaoil.it/listini/listino_flange_raccordi_pompe.pdf" target="_blank">'.$cms->meta_title.'</a>';
$this->_menu .= '</li>';
                }
else if ($cms->id==21){
$this->_menu .= '<li '.$selected.'>';
$this->_menu .= '<a href="http://newsite.rimaoil.it/listini/listino_raccordi_tubo_rigido.pdf" target="_blank">'.$cms->meta_title.'</a>';
$this->_menu .= '</li>';
                }
else if ($cms->id==24){
$this->_menu .= '<li '.$selected.'>';
$this->_menu .= '<a href="http://www.rimaoil.it/prodottinew.php" target="_blank">'.$cms->meta_title.'</a>';
$this->_menu .= '</li>';
                }
else if ($cms->id==23){
 
if ($id_lang == 'it') {
$this->_menu .= '<li '.$selected.'>';
$this->_menu .= '<a href="http://newsite.rimaoil.it/tabelle/ita.txt" target="_blank">'.$cms->meta_title.'</a>';
$this->_menu .= '</li>';
}
else if ($id_lang =='en'){
$this->_menu .= '<li '.$selected.'>';
$this->_menu .= '<a href="http://newsite.rimaoil.it/tabelle/eng.txt" target="_blank">'.$cms->meta_title.'</a>';
$this->_menu .= '</li>';
}
                }
else {
                $this->_menu .= '<li '.$selected.'>';
$this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
$this->_menu .= '</li>';    
                }
 
}
}
else {
            foreach ($pages as $page) {
                $cms = new CMS($page['id_cms'], (int)$id_lang);
                $links = $cms->getLinks((int)$id_lang, array((int)$cms->id));
 
                $selected = ($this->page_name == 'cms' && ((int)Tools::getValue('id_cms') == $page['id_cms'])) ? ' class="sfHoverForce"' : '';
                $this->_menu .= '<li '.$selected.'>';
                $this->_menu .= '<a href="'.$links[0]['link'].'">'.$cms->meta_title.'</a>';
                $this->_menu .= '</li>';
            }
}
 
            $this->_menu .= '</ul>';
        }
    }
Edited by silvioscavone (see edit history)
Link to comment
Share on other sites

1. first of all, not sure why you need to handle the language by yourself, it should be handled by PrestaShop core already for the LINK.

 

2. you using the $id_lang in wrong way.

some time you use it as int (the ID of the language such as 1 ,2 ), but some time you use it as iso coe like "en", "it"

Link to comment
Share on other sites

Cause prestashop already do it for CMS page, I need to handle language for a different link respect to selected language, accordignly to modify to blocktopmenu.php

 

shokinro: probably you answered the question, the lang id is a number not iso code, the condition was wrong.

 

Thanks

Edited by silvioscavone (see edit history)
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...