Okay, new to PHP. Have used a few other programming languages in the past, usually basic type languages. So far, PHP is similar enough that I can get along with what I need to do. Anyway, ...
I've been racking

my brain the last few days. I am trying to figure out how to set up shipping fees for our online store. I don't want to use a 3rd-party software (free or otherwise). I want to use the Post Office (USPS) since they have free boxes, their fees are usually cheaper (and, we're not shipping anything hazardous). And, I've gotten set up with Paypal. Everything is working so far ... except Paypal can only seperate shipping fees based upon State. That won't work for us because we live in Texas, so shipping to El Paso versus Houston versus Dallas would require different shipping costs, different increments. In fact, shipping to El Paso costs about the same as shipping to Kansas City, but I can't seperate cities like El Paso from Paypal's setup.
That's the background. I've found sort of a solution, but I just realised a few minutes ago how large this is going to make my program ... and very probably ... SLOW.

Paypal offers a couple of variables that I thought I could use. I've tested a simple version of the system, and it works. You see (for those who aren't familiar with it), the post office has seperated the country into 8 zones, and the zone boundaries are based upon where you are shipping from. Zone 1 is your local area. Zone 2 is a little farther away. With each zone, the distance is greater. Thus, the shipping costs go up accordingly. Finally, zone 8 (for us anyway) is like shipping to the tip of Maine. Anyway, to find out what zone (and thus, what shipping rate to charge), I need to know the customer's shipping zip code ... then, cross reference it with a list I printed from the USPS website.
Here's is a simple script that does that:
Code: Select all
<?php
$handling_cart_value = "4.00";
/*User typed in zipcode from previous page
I just need the first 3 digits of the zip code.*/
$zipcode = substr($_POST["zipcode"],0,3);
switch ($zipcode) {
case 750:
case 751:
$zone=1;
break;
case 734:
case 735:
$zone=2;
break;
case 706:
$zone=3;
break;
default:
$zone=8;
break;
endswitch;
}
switch ($zone) {
case 1:
$shipping_value = "1.00";
$shipping2_value = "0.25";
break;
case 2:
$shipping_value = "1.25";
$shipping2_value = "0.25";
break;
case 3:
$shipping_value = "1.25";
$shipping2_value = "0.50";
break;
default:
$shipping_value = "2";
$shipping2_value = "0.75";
break;
endswitch;
}
?>
This is a very simple example. Doesn't include all the zones and definitely doesn't include all the 3-digit zip codes, either. Our local zone includes nine 3-digit zipcode regions. That's not bad. But, zone 3 has 54 3-digit zipcode regions. Plus, zones 4-6 have more than 3. That is a lot of switch case statements. I fear that it will bog down my website. A few seconds is okay. But, what type of slow down are we talking about for a server to go through a couple hundred (maybe even like 500) switch case statements? Is there a better way without getting into a full blown shopping cart? I've heard of using an array. Would it be faster in this case? Would it be easy to edit? (For example, if USPS decides to re-zone ... ugh!)
Any ideas would be helpful.
Mark
P.S. - The reason I don't want to go with a full blown shopping cart is I want a system that I can get my brain around. I've looked at shopping carts and they have too much. I would rather build it myself from the ground up. That way, I understand what's going on.