Jump to content

[Solved]How to get a cookie value in a javascript file with Prestashop?


Recommended Posts

Hi,

 

I have created a javascript function called formatCurrency2 which is pretty similar to formatCurrency (both located in themes/prestashop/js/tools.js).

To use this new function I need to know the value of a cookie called 'currency2'.

 

In a php file on Prestashop I simply do $currency2 = $cookie->currency2; and it works perfectly.

However I have no idea how to do that in a javascript file.

I need to read this cookie from this javascript file otherwise the data won't be updated with ajax.

 

Any help would be really appreciated :)

 

Thank you !

Edited by cactusman2 (see edit history)
Link to comment
Share on other sites

Hi,

 

Thank you for your answer and sorry for the late reply.

That actually what I did finally ! As I couldn't find out how to do the way I wanted I tried an other way.

Set the variable on the php files then using them in the new javascript function.

Link to comment
Share on other sites

  • 1 year later...

Hi,

 

Thank you for your answer and sorry for the late reply.

That actually what I did finally ! As I couldn't find out how to do the way I wanted I tried an other way.

Set the variable on the php files then using them in the new javascript function.

 

Hi cactusman.....

i'm also interested in your solution....why not sharing?

 

Tkx

Ariom

Link to comment
Share on other sites

Hi,

 

I will try to explain as good as I can.

You will have first to set the variable in the php file.

In my case I wanted to use the 'currency2' cookie to the cart page so I set up a new php variable from the cookie 'currency2' in classes/Cart.php

$other_currency = $cookie->currency2;
$currency2 = new Currency($other_currency);

Then in the corresponding js file you can use those variable.

 

Note that it's not something easy to do.

Also you might have to modify other files and create new function depending of what you want to obtain.

In my case I need the cookie 'currency2' to calculates all prices with a different currency so more modification were involved + the addition of a new function.

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