Jump to content

[SOLVED] Hreflang category links return parent categories untranslated


Recommended Posts

Hey there:

I'm using a multilanguage installation of Prestashop 1.6, and while trying (using various sources) to set up hreflang tags for the different versions of the shop, I'm running into some trouble.

I'm using friendly URLs; While I can get my hreflang and canonical up and running for both index (obviously) and product pages using getPageLink and getProductLink, my categories are all messed up.

Canonical shows up OK, but somehow, getCategoryLink will ONLY translate the category name, and not parent categories, so my links are looking like this.

shop.my/original_parent_cat_name/original_subparent_cat_name/translated_subcategory/

or, in an actual example:

<link rel="alternate" hreflang="en" href="https://---/en/productos-led/lamparas-dicroicas/dichroic-accessories/">
<link rel="alternate" hreflang="pt" href="https://---/pt/productos-led/lamparas-dicroicas/acessorios-dicroicos/">
<link rel="alternate" hreflang="es" href="https://---/es/productos-led/lamparas-dicroicas/accesorios-dicroicas/">

 

But, it should look something like this:

<link rel="alternate" hreflang="en" href="https://---/en/led-products/dichroic-lamps/dichroic-accessories/">
<link rel="alternate" hreflang="pt" href="https://---/pt/produtos-led/lampadas-dicroicas/acessorios-dicroicos/">
<link rel="alternate" hreflang="es" href="https://---/es/productos-led/lamparas-dicroicas/accesorios-dicroicas/">

 My header.tpl file:

{if $languages|@count > 1}{foreach $languages as $lang}
<link rel="alternate" hreflang="{$lang.iso_code}" href="{$link->getCategoryLink($smarty.get.id_category, null, $lang.id_lang,null,null )}" />
{/foreach}

 

Can you guys give me a hint as to where I should start looking?   I'm using Ha99ys' CleanURLs override for Link Class (attached) and I'm (pretty much... quite... almost) sure that's the issue, specifically _getParentsCategories function, since it doesn't quite like the idea of the external lang_id source variable in the template.  So I guess the answer is hacking into the override.

 

 

 

 

Link.php

Edited by Luis C
Solved (see edit history)
Link to comment
Share on other sites

Well... as I suspected, it WAS Clearn URLs override the reason of the "malfunction". I know it's not the best practice, but I simply modified _getParentsCategories function with a second parameter,  and reflected the same change where getCategoryLink calls the former.

getParentsCategories

	public function _getParentsCategories($id_current = NULL, $id_lang)
{
		if (!$id_lang)
			$id_lang = Context::getContext()->language->id;
.....

getCategoryLink

			$subCategories = $this->_getParentsCategories1($category->id, $id_lang);

 everything seems OK now.

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...