cactusman2 Posted May 4, 2012 Share Posted May 4, 2012 (edited) 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 May 8, 2012 by cactusman2 (see edit history) Link to comment Share on other sites More sharing options...
CartExpert.net Posted May 7, 2012 Share Posted May 7, 2012 Hi, if you are using ajax then set the variable, pass it over to javascript and process it. Link to comment Share on other sites More sharing options...
cactusman2 Posted May 8, 2012 Author Share Posted May 8, 2012 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 More sharing options...
websku Posted June 19, 2013 Share Posted June 19, 2013 Hello, I'm facing similar issue to read the cookie from the .js file. Can you post a sample code how you managed to read the cookie from the javascript file? Link to comment Share on other sites More sharing options...
ariom Posted June 26, 2013 Share Posted June 26, 2013 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 More sharing options...
cactusman2 Posted June 27, 2013 Author Share Posted June 27, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now