Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Zone Shipping by State, Ver. 1.0


Skittles

Recommended Posts

Within a few minutes of this post, I will be uploading the contribution "Zone Shipping by State, Ver. 1.0".

 

I am starting this thread first so I can include the URL of this topic with the contribution description. Once the file is posted, I'll come back and include a link to the contribution.

 

This contribution is specifically for shipping within the United States and the only language file included is for English. (Sorry, I'm not bi-lingual...)

 

However, it should be relatively easy to modify for use in other countries.

 

This contribution can be used alone, or with the standard zones.php included with osCommerce, with a simple one line modification to zones.php.

 

When used together, only one or the other will display, based on the country of the shipping address.

 

This contribution is working on a site that is days away from going live, at which time I'll post the URL.

 

-Skittles

 

The contribution is here: http://www.oscommerce.com/community/contributions,4703

Edited by Skittles
Link to comment
Share on other sites

  • Replies 112
  • Created
  • Last Reply

Top Posters In This Topic

Anita, this is a wonderful module. I can already see needing it for future projects!!

 

Thanks a lot, fabulous read me file also. WTG!

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

Anita, this is a wonderful module. I can already see needing it for future projects!!

 

Thanks a lot, fabulous read me file also. WTG!

Thanks Monika.

 

When my client asked me for the ability this module provides, I went looking through the contributions and the forums for answers. All I found were other osCommerce shopkeepers looking for a similar solution. So while I created this module for my client, I knew it would also meet the needs of the community at large.

 

Most of the credit goes to the programmers that created the original zones.php, and osCommerce as a whole. I wouldn't have had a clue what to do if it weren't for their efforts and good documentation. :)

 

-Skittles

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

 

I'm going to use this module for my clients site. I just need some clarification.

The way I read the text file instructions is as follows, so correct me if I'm wrong here please!

 

This can be used along with the default zones.php file by adding the following modification:

On or around line 118, replace:

$dest_country = $order->delivery['country']['iso_code_2'];

with:

// for use with interstate shipping module.

if (($dest_country = $order->delivery['country']['iso_code_2']) == 'US') return;

 

This will cause the module to exit immediately if the delivery destination country IS the US.

 

Ok, so the interstate.php in our case will be used for shipping within the US, and then the zones.php can be used for all other countries?

 

Robert

Link to comment
Share on other sites

Hello,

 

I'm going to use this module for my clients site. I just need some clarification.

The way I read the text file instructions is as follows, so correct me if I'm wrong here please!

 

This can be used along with the default zones.php file by adding the following modification:

On or around line 118, replace:
$dest_country = $order->delivery['country']['iso_code_2'];
with:
// for use with interstate shipping module.
if (($dest_country = $order->delivery['country']['iso_code_2']) == 'US') return;

This will cause the module to exit immediately if the delivery destination country IS the US.

Ok, so the interstate.php in our case will be used for shipping within the US, and then the zones.php can be used for all other countries?

 

Robert

Merry Christmas, Robert.

 

Yes, that is exactly right.

 

If the delivery address is in the US, interstate.php will handle the shipping. If the delivery address is NOT in the US, zones.php will handle the shipping.

 

The customer will only see shipping charges from one or the other, never both.

 

This doesn't affect other shipping modules, so you can still use other modules to give the customer the option to upgrade to a more expensive, faster delivery service.

 

-Skittles

 

P.S. And a Happy Chanukah... :D

Link to comment
Share on other sites

Hey Skittles,

 

Thank you for your quick response! ;)

 

I seem to be having trouble with this module. After installing it in admin, and testing a purchase,

I get a "Invalid Zone" message in the shipping account area.

 

I've thoroughly read your instructions. Actually, all the the changes listed seem to be already done

in your files I downloaded except for this line - (adds 'z.zone_code' to $shipping_address_query in function cart().) (I'm no coder but that just looks like a note and not a command) in the order.php file, but I went ahead and followed the instructions for each line in each file.

 

When having that line in there I received a syntax error! So I removed it

 

 

Ok, So I tryed just ftping the originals I got in your download to see if they would work "as is" and I still

get the same message "Invalid Zone" I've tried uninstalling the default zone, and no luck.

 

I installed a couple other modules like the flat rate, and that showed up ok in my test account shipping choice.

 

Any suggestions?

 

Still getting the Invalid Zone message...

 

Robert

Edited by inetmarketing
Link to comment
Share on other sites

Hey Skittles,

 

Thank you for your quick response! ;)

 

I seem to be having trouble with this module. After installing it in admin, and testing a purchase,

I get a "Invalid Zone" message in the shipping account area.

 

I've thoroughly read your instructions. Actually, all the the changes listed seem to be already done

in your files I downloaded except for this line - (adds 'z.zone_code' to $shipping_address_query in function cart().) (I'm no coder but that just looks like a note and not a command) in the order.php file, but I went ahead and followed the instructions for each line in each file.

 

When having that line in there I received a syntax error! So I removed it

Ok, So I tryed just ftping the originals I got in your download to see if they would work "as is" and I still

get the same message "Invalid Zone" I've tried uninstalling the default zone, and no luck.

 

I installed a couple other modules like the flat rate, and that showed up ok in my test account shipping choice.

 

Any suggestions?

 

Still getting the Invalid Zone message...

 

Robert

Hey Robert.

 

First, you're right about the comment. It was never intended to be written to order.php.

 

Second, The error message only displays when the "State" (interstate.php) or the "Country" (zones.php) isn't included in any zone.

 

Quick question. Assuming you installed both interstate.php and the modified zones.php, did you then edit "Zone Rates Within USA" from the Admin and set "Offer USA specific zone rates by state?" to True. I believe it is False by default.

 

I will be online for the next several hours. We will figure it out!

 

-Anita

Link to comment
Share on other sites

Hey Anita,

 

I'm in NY (eastern time) so it was getting late last night, but maybe we can get this figured out later this evening

seeing as it morning now and a new day. :D Not sure about the time differential with Oregon.

 

Q: Was I correct in saying that the files already have the changes completed in your files I downloaded?

and should work "as is"?

 

When I installed the files in (Admin), they were already set to true by default.

 

Q: what is the sort order setting for?

Thats always set at "0" by default. I assumed that was the order they would appear in the account area.

 

I didn't EDIT any of the pre-defined settings in ADMIN. (weights or prices) I left them as is. I did originally change the handling value

which was set to 5.00, but I tried using the files without any changes made manually also.

 

I will take another look at the files this evening, and try adding them again.

 

Thanks,

 

Robert

Edited by inetmarketing
Link to comment
Share on other sites

Hey Anita,

 

I'm in NY (eastern time) so it was getting late last night, but maybe we can get this figured out later this evening

seeing as it morning now and a new day. :D Not sure about the time differential with Oregon.

 

Q: Was I correct in saying that the files already have the changes completed in your files I downloaded?

and should work "as is"?

 

When I installed the files in (Admin), they were already set to true by default.

 

Q: what is the sort order setting for?

Thats always set at "0" by default. I assumed that was the order they would appear in the account area.

 

I didn't EDIT any of the pre-defined settings in ADMIN. (weights or prices) I left them as is. I did originally change the handling value

which was set to 5.00, but I tried using the files without any changes made manually also.

 

I will take another look at the files this evening, and try adding them again.

 

Thanks,

 

Robert

Robert,

 

There's a three hour difference. And though I work out of my home, I work mostly "swing shift" as that's when my husband is at work.

 

The sort order is the order in which the "option" is displayed during checkout. If you use more than one shipping module, you should set the sort order. In the admin, modules are listed alphabetically by the module's filename (i.e. interstate.php, zones.php)

 

Because I developed this module for a client's site, and installed it along with numerous other changes, I tested this on my development site before releasing the contribution. I used the same files you have, followed the directions in the readme file, and made no changes to either interstate.php file. It worked "right out of the box". However, my development site (on my computer, using XAMPP) is not heavily modified, so any incompatibilities with other contributions/modifications wouldn't be apparent.

 

While you control the actual error message in the language file (interstate.php), the message "Invalid Zone" occurs when the module compares the state of the delivery address with the states listed for each zone and doesn't find a match.

 

Here' the code:

	  $dest_state = $order->delivery['state']; 
  $dest_zone = 0;
  $error = false;

  for ($i=1; $i<=$this->num_zones; $i++) {
	$state_table = constant('INTERSTATE_STATES_' . $i);
	$state_zones = split("[,]", $state_table);
	if (in_array($dest_state, $state_zones)) {
	  $dest_zone = $i;
	  break;
	}
  }
  if ($dest_zone == 0) {
	$error = true;
  } else {
...

First, it sets the variables

Second, it loops through each zone's list of states looking for a match.

If a match is found, the zone variable is set to the number of the zone and the loop is stopped

If no match is found, the loop continues.

Third, after exiting the loop, the variable $dest_zone is tested for a valid zone. If the value wasn't modified in the loop, it will be 0, and $error will be set to true.

 

Later in the code, the error message is returned, instead of the shipping info, when $error is set to true.

 

This tells me that one way or another $dest_state is not being passed the information necessary to match with any of the two character state abbreviations used in the zone definitions.

 

I didn't include military APO/FPO or territories in the defaults, so using any of these would cause an error. However, I suspect you used a New York address while testing the module, which shouldn't produce the error.

 

There are two modifications to order.php.

The first is to an sql query to include the zone_code from the zones table. zone_code contains the abbreviations for the states.

The second changes the results stored in the array to use zone_code instead of zone_name.

If the second mod wasn't done, there would not be any error messages (instead of the loaded page) to alert you. However, $dest_state would actually have the full name of the state (New York) instead of the abbreviation (NY).

 

Try this. In the shipping module interstate.php, find the following code, around line 93:

	  if ($error == true) $this->quotes['error'] = INTERSTATE_INVALID_ZONE;

Replace it with this:

//	  if ($error == true) $this->quotes['error'] = INTERSTATE_INVALID_ZONE;
  if ($error == true) $this->quotes['error'] = $dest_state;

From the Admin, you will need to "remove" the module, then re-install it for the change to take effect.

 

Then when you test it, instead of seeing "Invalid Zone", you will see the actual value that is being passed to the module.

 

Once we know what is being passed, we'll go from there.

 

I'll be keeping a close eye on this forum for the next eight to twelve hours. Hang in there. We'll find it and we'll fix it!

 

-Skittles

Link to comment
Share on other sites

Hey Anita,

 

Ok, Its really great to see active community members, developers, etc.

 

and your assistance is greatly appreciated!

 

You were correct that the shipping address I used was NY. I will add the changes, and put back some clean files

as I cannot remember exactly which was my last try last night.

 

I'll let you know in a bit what the out come is...

 

Robert

Link to comment
Share on other sites

Ok Anita,

 

The Result:

Shipping Method

Please select the preferred shipping method to use on this order. Please Select

 

 

Economy Shipping, Best Way

NY

 

 

Zone Rates

No shipping available to the selected country

 

No check box!

 

I noticed in the zones.php

this is there:

 

$default_countries = '';

if ($i == 1) {

$default_countries = 'US,CA';

 

I took out the "US" inside the ADMIN. Can this be a problem?

 

Robert

Link to comment
Share on other sites

Ok Anita,

 

The Result:

No check box!

 

I noticed in the zones.php

this is there:

I took out the "US" inside the ADMIN. Can this be a problem?

 

Robert

Robert,

 

No, having US included in the Zones module shouldn't prevent Interstate from working. If the bit of code that causes zones.php to exit without running were removed, both "options" would appear in the checkout.

 

I'll get back to you in a "few" minutes.

 

In the meantime, what other contributions/modules are installed?

 

-Anita

Link to comment
Share on other sites

Anita,

 

Yours is the only contribution I've installed in the cart.

Thanks for checking Robert.

 

I've found the bug in my code. I'm now trying to find an elegant solution.

 

The easy way out is to remove all the spaces following the commas in the zones definitions.

 

i.e. change "OR, WA, CA, NV" to OR,WA,CA,NV".

 

I'm trying to avoid that for two reasons. One, it is so easy to add the space automatically, causing a difficult to find bug (not unlike this one.) Two, I don't like what the long lines do to the display in the Admin.

 

I'll post the elegant solution here as soon as I figure it out. And I'll upload the changes to the contribution page.

 

Sorry for the frustration. :blush:

-Anita

Link to comment
Share on other sites

Thanks for checking Robert.

 

I've found the bug in my code. I'm now trying to find an elegant solution.

 

The easy way out is to remove all the spaces following the commas in the zones definitions.

 

i.e. change "OR, WA, CA, NV" to OR,WA,CA,NV".

 

I'm trying to avoid that for two reasons. One, it is so easy to add the space automatically, causing a difficult to find bug (not unlike this one.) Two, I don't like what the long lines do to the display in the Admin.

 

I'll post the elegant solution here as soon as I figure it out. And I'll upload the changes to the contribution page.

 

Sorry for the frustration. :blush:

-Anita

 

Anita,

 

Well, I can only begin to understand the FUN behind php coding. I can read some of it, but design and graphics are my forte. I hate it when I leave a semi-colon out of my css or misspell a word.

 

I started taking a php course (basics), but it just added to the learning curve. One thing I've learned is

you can never stop learning! :'(

 

I can't wait to see what you come up with.

 

Robert

Link to comment
Share on other sites

Anita,

 

Well, I can only begin to understand the FUN behind php coding. I can read some of it, but design and graphics are my forte. I hate it when I leave a semi-colon out of my css or misspell a word.

 

I started taking a php course (basics), but it just added to the learning curve. One thing I've learned is

you can never stop learning! :'(

 

I can't wait to see what you come up with.

 

Robert

"Dammit, Jim, I'm a doctor, not a PHP programmer!"

 

Ok, I'm paraphrasing. (Hope I didn't offend any trekkies...)

 

But truth be told, I'm a photographer, not a programmer.

 

So here's the solution. In the the module file interstate.php find this, (should be line 48):

		$state_zones = split("[,]", $state_table);

Change it to:

		$state_zones = split("[ ,]", $state_table);

 

Now it will split on either the comma or the space. (Probably creates blank elements in the array, but doesn't break anything.)

 

I'll upload the updated contrib later tonight.

 

Thanks for your help, Robert. I'd have had to deal with this snafu sooner or later. Sooner is better, I think.

 

Merry Christmas.

-Anita (aka Skittles)

Link to comment
Share on other sites

Hey Anita,

 

It worked.

 

Not sure whay the cart is saying 6 pounds for an item that has the setting 2.00 though.

 

Its charging me $23 for shipping.

 

Maybe the admin settings need to be adjusted huh?

 

Robert

 

Thanks for all your help! ;)

Link to comment
Share on other sites

Hey Anita,

 

It worked.

 

Not sure whay the cart is saying 6 pounds for an item that has the setting 2.00 though.

 

Its charging me $23 for shipping.

 

Maybe the admin settings need to be adjusted huh?

 

Robert

 

Thanks for all your help! ;)

Robert,

 

In the Admin, under Configuration (left menu), go to Shipping/Packaging.

 

There you will find "Package Tare Weight". If you don't want to add extra weight to cover the box and packing material, make this value 0.

 

Also, the module as is has defaults for shipping from the West Coast. Your client needs to create their own shipping table, and determine which states belong in which zones. The rates they charge will be based on many factors, including who their shipper is and what it cost them to ship the items.

 

This module makes it possible, but in terms of weight and dollar amounts, it is only starting point.

 

Have fun!

 

-Anita

Link to comment
Share on other sites

Robert,

 

In the Admin, under Configuration (left menu), go to Shipping/Packaging.

 

There you will find "Package Tare Weight". If you don't want to add extra weight to cover the box and packing material, make this value 0.

 

Also, the module as is has defaults for shipping from the West Coast. Your client needs to create their own shipping table, and determine which states belong in which zones. The rates they charge will be based on many factors, including who their shipper is and what it cost them to ship the items.

 

This module makes it possible, but in terms of weight and dollar amounts, it is only starting point.

 

Have fun!

 

-Anita

 

Hey,

 

Yeah, I believe she did add for packaging, etc..

 

Yeah, she knows more about the tables. I know she said she wanted to go with 8 zones, which means

I have to change the file again. Yes, I know... Un-install it first! :P

 

Thanks again.

 

Have a safe and happy holiday!

 

Robert

Link to comment
Share on other sites

Hey Anita,

 

Not sure what happened, but the "Zone shipping by state" won't install.

 

It was fine the other night.

 

I had gotten an email from my client saying she went in Admin and changed the states, weights, prices within

the 5 zones, and clicked UPDATE, and everything was gone. It wouldn't Install again either.

 

I went in and tried to Install it, and when the page refreshes the Install button is still there.

 

I asked if she changed anything else and she that was it.

 

------------------------

I tryed uploading all the files again, and still no dice.

 

Any idea what could've happened?

 

Robert

Link to comment
Share on other sites

Hey Anita,

 

Not sure what happened, but the "Zone shipping by state" won't install.

 

It was fine the other night.

 

I had gotten an email from my client saying she went in Admin and changed the states, weights, prices within

the 5 zones, and clicked UPDATE, and everything was gone. It wouldn't Install again either.

 

I went in and tried to Install it, and when the page refreshes the Install button is still there.

 

I asked if she changed anything else and she that was it.

 

------------------------

I tryed uploading all the files again, and still no dice.

 

Any idea what could've happened?

 

Robert

For the folks following this thread, I contacted Robert by PM and we resolved this problem.

 

For whatever reason, when he removed the module, the entries were not removed from the configuration table. With all the install/uninstall that was done while finding the extra space issue, there were literally hundreds of entries in the table.

 

We removed all the entries for "interstate", then he installed the module again. It appears to be working correctly. He removed, then reinstalled the module. This time, there weren't any duplicate entries.

 

It isn't clear why his instance of the database wasn't deleting the rows of data when the module was uninstalled. It may or may not be relevant that his copy of osCommerce was installed using Fantastico.

 

Cheers,

-Skittles

Link to comment
Share on other sites

Hi all.

 

I promised to provide a link to the site I created this contribution for, once it went live. Well, it's live! :D

 

I still have a number of details to work on, but the site is completely functional. To see this module in action, you will need to register and go through the initial motions of ordering, at least through the shipping page. Currently, only US addresses are accepted as this merchant doesn't ship out of the country.

 

This is a live site! Any orders made will be processed! DO NOT COMPLETE THE ORDER, unless you actually want the product!

OK. Here's the link to Futon Man. B)

 

(By the way, I did NOT create the design, I only implemented it. The site was designed by Stephen Chovanec of Arlington VA, whose day job is as a Senior Designer for PBS Interactive!)

 

Merry Christmas, Happy Chanukah, and Happy [enter your favorite winter holiday here]!

-Skittles

 

P.S. ...And A Prosperous Happy New Year! :thumbsup:

Link to comment
Share on other sites

  • 3 weeks later...

Hi All,

 

I just downloaded and installed this according to the instructions (I believe, some of the instructions are ambigous to me).

like

When you enter these state lists, enter them into the Zone X States fields, where

"X" is the number of the zone. Zone Codes are part of the Zones table, and must be

listed exactly as they are listed in the table. USA destinations use two characters,

all upper case. See the Zones table for other countries. The codes should be

separated by commas. Do not use any other punctuation. For example:

1: OR, WA, CA, NV

2: AZ, CO, ID, MT, NM, UT, WY

3: AL, AR, IA, IL, KS, LA, MN, MO, MS, NE, ND, OK, SD, TN, TX, WI

4: CT, DC, DE, FL, GA, IN, KY, MA, MD, ME, MI, NH, NJ, NY, OH, PA, RI, SC, VA,

VT, WV

5: AK, HI

 

I tried to set this up with only 2 zones

 

	 for ($i = 1; $i <= $this->num_zones; $i++) {
	$default_states = '';
	$default_rates = '';
	if ($i == 1) {
	  $default_states = 'AL, AS, AZ, AR, CA, CO, CT, DE, FM, FL, GA, ID, IL, IN, IA, KS, KY, LA, ME, MH, MD, MA, MI, MB, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA, WV, WI, WY';
	  $default_rates = '100:11.00, 200:12.00, 300:13.00, 400:14.00';
	}
	if ($i == 2) {
	  $default_states = 'AK, HI';
	  $default_rates = '100:26.00, 200:27.00, 300:28.00, 400:129.00';
	}

 

and when I enter in a new address for either Alaska or Hawaii, it still gives me the continental US pricing.

 

Where am I going south here, pun intended.

 

Thanks in advance,

 

Don

 

EDIT: I just turned of the Table Rates and only have "Zone Rates Within USA" on and when I try to checkout it does not list ANY shipping method and of course, gives me an error if I try to continue.

Edited by Dmacman
Link to comment
Share on other sites

Hi, I've read the entire topic and I was wondering how to chose the shipping method to use? I've looked at the USPS and UPS contrib then I came across yours. We have accounts for UPS and USPS but how does Zones work?

 

I'm new to this and our store is not yet online but maybe you could help me select the best method. We will be selling car parts mostly in the U.S.

 

Any thoughts would be helpfull.

 

Felipe de la Rosa

Yahoo! IM: fdelarosa59

Felipe de la Rosa

*Please feel free to IM me via YIM or AIM.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...