[FIX] website: set correct value in frontend_lang cookie

Before this commit, the `url_code` field value was stored in the cookie instead
of the `code` field.
This was making the language selector in the frontend to not change the lang
correctly when trying to access the website default lang, ONLY for the lang
having an `url_code` different than its `code` value (typically the case for
principal languages).

Step to reproduce:
  - Add `fi_FI` as main lang on website
  - Visit frontend and change lang to `Suomi`, it won't change

This behavior was only related to the language switcher. It did not affect
dispatching (if correct lang in url) and nearest lang finder.

Fixes #41522

closes odoo/odoo#41728

X-original-commit: b62b2828552abb38c8adc74c69cb427c3fd98605
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
Romain Derie
2019-12-11 13:33:22 +00:00
parent 0f2a500f0e
commit e788c040f6
+3 -1
View File
@@ -113,11 +113,13 @@ class Website(Home):
@http.route('/website/lang/<lang>', type='http', auth="public", website=True, multilang=False)
def change_lang(self, lang, r='/', **kwargs):
""" :param lang: supposed to be value of `url_code` field """
if lang == 'default':
lang = request.website.default_lang_id.url_code
r = '/%s%s' % (lang, r or '/')
redirect = werkzeug.utils.redirect(r or ('/%s' % lang), 303)
redirect.set_cookie('frontend_lang', lang)
lang_code = request.env['res.lang']._lang_get_code(lang)
redirect.set_cookie('frontend_lang', lang_code)
return redirect
@http.route(['/website/country_infos/<model("res.country"):country>'], type='json', auth="public", methods=['POST'], website=True)