This is how i solved a huge issue

General ShopSite user discussion

This is how i solved a huge issue

Postby RedSyntax » Thu Feb 05, 2009 9:58 am

I used a JavaScript to achieve the goal of restricting shipping options to a zip code range, ie shoppers in Alaska and Hawaii can't use the standard shipping options and passed to the check it function.
Last edited by RedSyntax on Fri Feb 06, 2009 10:05 am, edited 1 time in total.
RedSyntax
 
Posts: 51
Joined: Mon Nov 17, 2008 7:29 am

Postby MichelleC » Thu Feb 05, 2009 12:35 pm

Yes- i would definitely like to know how to do this: "How can i put an onclick function on a button in a tag??"

anyone know? thanks!
MichelleC
 
Posts: 28
Joined: Wed Jan 21, 2009 9:08 am

Postby MichelleC » Fri Feb 06, 2009 11:54 am

cool! can you post/share the javascript?
MichelleC
 
Posts: 28
Joined: Wed Jan 21, 2009 9:08 am

The javascript

Postby RedSyntax » Thu Feb 12, 2009 8:47 am

var zip_range = "^(967)([0-9]{2})|^(968)([0-9]{2})|^(995)([0-9]{2})|^(996)([0-9]{2})|^(997)([0-9]{2})|^(998)([0-9]{2})|^(996)([0-9]{2})|^(999)([0-9]{2})"
var re = new RegExp(zip_range);
if (document.order.shipping[0].type == "radio") {
for (var i=0; i < document.order.shipping.length; i++)
{
if (document.order.shipping[i].checked)
{
var rad_val = document.order.shipping[i].value;
}
}
}
else {
var rad_val = document.order.shipping.value;
}

if (button == "8" && document.order.zip_code.value.match(re) && (rad_val == "m3" || rad_val == "m3")) {
alert(" If you are located within Alaska or Hawaii please SELECT the Alaska & Hawaii shipping option");
return(false);
}
RedSyntax
 
Posts: 51
Joined: Mon Nov 17, 2008 7:29 am

Postby MichelleC » Thu Feb 12, 2009 9:31 am

Ah! THANKS so much for sharing!
MichelleC
 
Posts: 28
Joined: Wed Jan 21, 2009 9:08 am

Other possible uses for this type of code.

Postby VinceS » Fri Feb 27, 2009 6:44 am

Very nice.
I'm going to try to modify this code to force the customer who is shipping within my home state to select the State Tax drop down in the cart. That will save some calls and some awkward conversations. I'm tired of getting beat for Sales Tax.
VinceS
 
Posts: 134
Joined: Fri Apr 06, 2007 1:26 pm

The javascript

Postby RedSyntax » Fri Feb 27, 2009 7:50 am

Ya, It shouldn't be hard to implement, you just need to write the regexp(I recommend an online regexp checker/assembler) that matches the zip code ranges of your choice.

And also remember it has to go into. The "JavaScript added at start of built-in CheckIt function:" Box found at:
Commerce Setup-->Customize Ordering System-->Shopping Cart Screen
RedSyntax
 
Posts: 51
Joined: Mon Nov 17, 2008 7:29 am


Return to User Forum

Who is online

Users browsing this forum: No registered users and 130 guests