wojodesign / simplecart-js

A simple javascript shopping cart that easily integrates with your current website.
simplecartjs.org
1.79k stars 492 forks source link

location based shipping #183

Open ALaf opened 12 years ago

ALaf commented 12 years ago

there is a thread already and i commented there too (https://github.com/wojodesign/simplecart-js/issues/133) but i would like to bring this up so perhaps someone knows how to do it notices.

i just want 2 options, domestic and international. has anyone managed to do this, and if then, how do i go about it? thanks in advance!

brettwejrowski commented 12 years ago

It's pretty easy if you are using jQuery; just have a custom shipping function that gets the value of a select to determine the price. Something like:


simpleCart.shipping = function(){
  if( $("#shippingSelect").val() == "domestic" ){
    // domestic rate
    return 40;
  } else {
    // international rate 
    return 50;
  }
};
ALaf commented 12 years ago

thanks so much! i am not familiar with jQuery and Javascript in general, so i'll have to educate myself a bit to wrap my head around that on how to apply the code. but i get the idea, i think. if i cannot figure out i'll come back and ask again. thanks again!

ALaf commented 12 years ago

ok, i tried to teach myself but finally gave up. if i want to apply the above code to 2 radio buttons with domestic shipping of 4.00 and international shipping of 5.50, how should i configure the html code? if anyone can help me out, i'd be grateful. thanks!

Teilzeitautist commented 11 years ago

Hi, I tried this method with SimpleCart 2.2.2 and it works fine for me. However the visible shipping value gets only updated when I refresh the page or add or remove an item.

Therefore I would like to have a page refresh upon changing the option value. I tried in various ways to add a "simpleCart.update" function to the code above, but I am afraid I am not too good at javascript to accomplish it.

Maybe someone could help me? Thanks a lot in advance, Thomas

Here is my code:

<select id="shippingSelect">
<option value="de">Deutschland</option>
<option value="at">Österreich</option>
<option value="eu">EU</option>
<option value="ch">Schweiz</option>
<option value="welt">Weltweit</option>
</select>

<script type="text/javascript">
simpleCart.shipping = function(){
  if( $("#shippingSelect").val() == "de" ){return 9;}
  if( $("#shippingSelect").val() == "at" ){return 29;}
  if( $("#shippingSelect").val() == "eu" ){return 49;}
  if( $("#shippingSelect").val() == "ch" ){return 69;}
  if( $("#shippingSelect").val() == "welt" ){return 89;}
  $("#shippingSelect").val().change(function(){simpleCart.update}); // This is my part which doesn't do anything yet
};  
</script>
Teilzeitautist commented 11 years ago

I moved the second function outside of my first function and managed to sucessfully reload the entire page on changing my options. But that is of course far away from perfect, so I still need to know how to add the "simpleCart.update" function to my code:

Anyway, here is my latest try:

<script type="text/javascript">
    simpleCart.shipping = function(){
  if( $("#shippingSelect").val() == "de" ){return 29;}
  if( $("#shippingSelect").val() == "at" ){return 49;}
  if( $("#shippingSelect").val() == "eu" ){return 99;}
  if( $("#shippingSelect").val() == "ch" ){return 149;}
  if( $("#shippingSelect").val() == "welt" ){return 249;}
};
$("#shippingSelect").change(function(){window.location.reload();});  
</script>
Teilzeitautist commented 11 years ago

Got it...

To whom it may concern:

<select id="shippingSelect" onchange="simpleCart.update();">
    <option value="de">Deutschland – Versandpauschale: 29 € &nbsp;</option>
    <option value="at">Österreich – Versandpauschale: 49 € &nbsp;</option>
    <option value="eu">EU – Versandpauschale: 99 € &nbsp;</option>
    <option value="ch">Schweiz – Versandpauschale: 149 € &nbsp;</option>
    <option value="welt">Weltweit – Versandpauschale: 249 € &nbsp;</option>
</select>

<script type="text/javascript">
simpleCart.shipping = function(){
  if( $("#shippingSelect").val() == "de" ){return 29;}
  if( $("#shippingSelect").val() == "at" ){return 49;}
  if( $("#shippingSelect").val() == "eu" ){return 99;}
  if( $("#shippingSelect").val() == "ch" ){return 149;}
  if( $("#shippingSelect").val() == "welt" ){return 249;}
};
</script> 
R0o commented 11 years ago

Hi, I found this script that automatically calculates the location of the person viewing the page, and what I like to do is pass some variables to set different shipping by giving us country code ex: EN, DE, IT ... I've seen a page where someone has used it to change the shipping but does not use SimpleCart, so if anyone knew how to make a function to set the shipping in some countries would greatly appreciate it.

Well, this is the script:

‪‪

and this is the link to the page where he explains the use function to change the shipping charge, by the end of the page:

http://codecanyon.net/item/plumshop-a-jquery-shopping-cart/discussion/427746?page=5

Thanks in advance and sorry for my English.