1

Iam developing a shoping cart site. I want to change the price of the product if the country changes.The prices of the the products shoul be all over the project Whenever country changes according to the currency. For this iam trying to set a session variable in jquery and with this i want to retreive the data.But Iam unable to get it.

if suppose iam selecting the USD in index page its working fine.And if iam redirecting to another page.its not working.

Every indidual pages its working fine.which means for every page iam changes the country then the price of the product changing. For this i want to pass the session variable. But Iam unable to set the session variable in Jquery.Can Anty one help me to solve this issue. Here iam Inserting the Jquery code

Currency.format = 'money_with_currency_format';
var shopCurrency = 'INR';

//Sometimes merchants change their shop currency, let's tell our JavaScript file
Currency.money_with_currency_format[shopCurrency] = "${{amount}} INR";
Currency.money_format[shopCurrency] = "${{amount}} INR";

//Default currency
var defaultCurrency = 'INR' || shopCurrency;

//Cookie currency
var cookieCurrency = Currency.cookie.read();

//Fix for customer account pages
jQuery('span.money span.money').each(function () {
    jQuery(this).parents('span.money').removeClass('money');
});

//Saving the current price
jQuery('span.money').each(function () {
    jQuery(this).attr('data-currency-INR', jQuery(this).html());
});

//If there's no cookie.
if (cookieCurrency == null)
{
    if (shopCurrency !== defaultCurrency)
    {
        Currency.convertAll(shopCurrency, defaultCurrency);
    }
    else
    {
        Currency.currentCurrency = defaultCurrency;
    }
}
//If the cookie value does not correspond to any value in the currency dropdown.
elseif(jQuery('[name=currencies]').size() && jQuery('[name=currencies] option[value=' + cookieCurrency + ']').size() === 0)
{
    Currency.currentCurrency = shopCurrency;
    Currency.cookie.write(shopCurrency);
}
elseif(cookieCurrency === shopCurrency)
{
Currency.currentCurrency = shopCurrency;
}
else
{
    Currency.convertAll(shopCurrency, cookieCurrency);
}

//Currency value changes
jQuery('[name=currencies]').val(Currency.currentCurrency).change(function () {
    var newCurrency = jQuery(this).val();
    Currency.convertAll(Currency.currentCurrency, newCurrency);
    jQuery('.selected-currency').text(Currency.currentCurrency);
});

var original_selectCallback = window.selectCallback;
var selectCallback = function (variant, selector)
{
    original_selectCallback(variant, selector);
    Currency.convertAll(shopCurrency, jQuery('[name=currencies]').val());
    jQuery('.selected-currency').text(Currency.currentCurrency);
};

jQuery('.selected-currency').text(Currency.currentCurrency);
<?php
//PHP Session Created
$_SESSION['newCurrency'] = $_POST['currencies'];
?>

//Currencies Html Code
    < select id = "currencies" name = "currencies" >
                < option value = "INR" selected = "selected" > INR < /option> / / default
                < option value = "USD" > USD < /option>
                < option value = "CAD" > CAD < /option>
                < option value = "GBP" > GBP < /option>
                < option value = "EUR" > EUR < /option>
                < /select>
                //Display's generated session
<?php
echo $_SESSION['newCurrency'];
?>
4
  • jQuery don't have access to server side of your site, that's why session variable is cannot be set without request to backend scripts Commented Jul 31, 2015 at 6:05
  • So what i can do?to retrive the session variable?can you help me please. Commented Jul 31, 2015 at 6:12
  • You cant set and get session variables using ajax stackoverflow.com/questions/26343370/… Commented Jul 31, 2015 at 7:04
  • so how can i pass the session variable. Commented Jul 31, 2015 at 9:34

2 Answers 2

1

Use local Storage to store that session variable.

var sessionvalue = localStorage['sessionvalue'];
    if (!sessionvalue ) {
           //Do your stuff
    }

You can get more info here

Sign up to request clarification or add additional context in comments.

1 Comment

What you tried ? can you set up a fiddle ? so i can view it and help you if possible
0

you can simply get a value of any php variable in javascript var. like

<script>
    var sess = "<?php echo $_SESSION['Key']; ?>";
    ........
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.