Preserve language while browsing products

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
otsakir
Forum Members
Forum Members
Posts: 17
Joined: Wed Mar 07, 2012 4:26 pm

Preserve language while browsing products

Post by otsakir »

Hi,

I am using the Products module in a multilingual e-shop like site. I 've also enabled pretty urls. Each page exists in all languages and the active language is determined from the first component of the url. If for instance it starts with 'en', the english language is used. I am using {$cgsimple->get_root_alias()} for that. So far so good.

Unfortunately, when I try to navigate from a product summary page to a product detail page the detail view is rendered using the default language of the site. Note that the rest of the page is rendered correctly using the right language and not the default. Looks like I can't pass the language info to the Products module.

By the way, the url that displays the detail looks like:

Code: Select all

http://mydomain/Products/2/26/6
2 - is the product id
26 - is the page id
6 - ???

The are two workarounds that come to my mind but none seems appropriate. The first would be to pass the language information in the GET request. For instance, append something like "&XXXlang=en". This can't be used since i am using pretty urls. At least not without messing with the Products source code. The second would be to use a POST instead of a GET and put an additional lang parameter in the post but obviously that doesn't seem right.

Any ideas?
Peciura

Re: Preserve language while browsing products

Post by Peciura »

You can append any url with language parameter

Code: Select all

...?lang={$lang}
Also it is easily to save language parameter to $_SESSION['lang'] or $_COOKIE['lang'] whenever url param "lang" is set.
It is easy to get language value

Code: Select all

{assign var='lang' value=$smarty.session.lang}
otsakir
Forum Members
Forum Members
Posts: 17
Joined: Wed Mar 07, 2012 4:26 pm

Re: Preserve language while browsing products

Post by otsakir »

I appended the following

Code: Select all

?cntnt01lang=en_US
and it worked. I had to add the 'cntnt01' first.

The only problem is that it makes 'pretty' urls kind of 'uglier'. I hope it has no effect on SEO and site crawling.

About the second solution, even if the language is saved in the session, how is it applied to the Products detail view later on? I tried to update it in both the detail template of the products and the global page template with

Code: Select all

{assign var="lang" value=....}
but it didn't have any effect. At least not in the string literals that are taken from the module's language files. I think that somehow it has to be passed as a module parameter.
Peciura

Re: Preserve language while browsing products

Post by Peciura »

There were 2 option on using/passing values, not 2 solutions.
...I think that somehow it has to be passed as a module parameter.
If you create page that displays Products detail template depending on url you can use saved language

Code: Select all

{Products action='details' productid=$productid_from_url lang=$smarty.session.lang}
Similar function with url

Code: Select all

{Products action='details' productid=$productid_from_url lang=$smarty.get.lang}
$productid_from_url can be url param or value extracted with regexp or mod_rewrite on htaccess. It is just another variable like language

'cntn01' is default action id. It means Products module is displayed on whole content block. If you have uncommon layout it will not work the way you expect.

As for SEO, Google will understand any link you throw to it. If there are more than one valid link to the same page it will chose the shortest one. Further more it might index your summary pages only providing they contain 99% of all useful info. But that is another story.
otsakir
Forum Members
Forum Members
Posts: 17
Joined: Wed Mar 07, 2012 4:26 pm

Re: Preserve language while browsing products

Post by otsakir »

:o

That explains a lot, in particular using $smarty.get variable. So, one can easily pass normal parameters to the url and access them through $smarty.get."paramname" in the page templates.

You've been most helpful. Thanks.
Post Reply

Return to “Modules/Add-Ons”