Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Free Shipping Within US/Charge for international

Free Shipping Within US/Charge for international

Views: 6,653

Results 21 to 40 of 59
27 Feb 2013, 2:40 AM
#21
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Free Shipping Within US/Charge for international

Thank you for all the help. I may just try the scenario that you had in the other thread and use the code "21". it would work for everything except HI, AK, and the territories.

27 Feb 2013, 4:04 AM
#22
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free Shipping Within US/Charge for international

You could also add Hawaii and Alaska if needed to your Zone Definition and add the Territories if you want them in there ...

27 Feb 2013, 10:43 PM
#23
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

I had a thought....but first let me say I have no idea about any of this "coding" stuff....beyond doing basic HTML from about 8 yrs ago.

On ebay when an item is listed you can list weights/shipping details for U.S. shipments and then list it separately for foreign shipments.

I got to thinking....it seems like it would be fairly easy to add a second box for shipping weight for international....so you'd have the original shipping weight box for U.S. weight and a 2nd box for international weight. I'm assuming each would have it's own "variable", and then in the shipping module the U.S rates would use the variable/weight that was entered for U.S., and the international rates would use the variable/weight entered for international.

Possible?

28 Feb 2013, 12:04 AM
#24
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free Shipping Within US/Charge for international

Adding an extra weight box is easy ... doing something with it is much more complicated ...

More or less you are totally rewriting how the shipping is managed at this time ...

4 Mar 2013, 6:08 PM
#25
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

So does anyone have any ideas about a "3rd party" addon (even if it costs money) that will do this? In searching the forums this seems like a pretty common issue.....so much so, that it seems someone would of found a "fix" for this.

Offering free shipping in your own country but charging for international shipping is not that uncommon.

4 Mar 2013, 6:46 PM
#26
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free Shipping Within US/Charge for international

If you just want Free Shipping on ALL Products for the US and regular charges for anywhere not in the US ...

you could created 2 Zone Definitions, one for the US and one for the Rest of the World ...

Now add the Zone Definition for the Rest of the World to USPS and install the Free Shipping Options and add the Zone Definition for the US to that and configure it to Total >= 0.00 ...

Now the US gets Free Shipping on ALL Orders and the Rest of the World gets regular USPS shipping ...

4 Mar 2013, 8:33 PM
#27
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

As I mentioned earlier in the thread, the problem is that I only ship first class items for free. There is just no fair and equitable way to ship priority items for free.

I have items that run from 1 oz. (in the envelope/package) to 9 and 10#'s.

4 Mar 2013, 8:39 PM
#28
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free Shipping Within US/Charge for international

Are you saying Free Shipping for Products that weight 1oz to 9 - 10 lbs in the same instance as saying you only ship the Free Shipping by First Class, as this does not make any sense as there is not First Class over 13 oz ... or are you saying something else ... :blink:

Perhaps you could type really really slowly for us so we grasp what you are saying as you kinda lost me here ... :lookaroun

4 Mar 2013, 8:55 PM
#29
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

Sorry to be confusing. I didn't realize that it was. I realize anything over 13 oz. is NOT first class.

Anyhow I have individual items that weigh anywhere from 1 oz., up to 9 or 10 pounds.

For any customer from the United States, the following apply.

I offer FREE SHIPPING on any individual item (plus packaging, envelope, label, etc.) that weighs 13 Oz. or less that can be mailed as a first class item.

Any item (plus packaging, envelope/box, label, etc.) that I have that weighs more than 13 oz., has to ship as priority mail and I charge the appropriate rate to the customer.

As an example, I sell Iphone cases. One Iphone case in an envelope weighs 3 oz., so I ship it for free. If a customer buys 6 IPhone cases they get free shipping since free shipping is offered on each one of the 6 items they bought. The total weight is going to be over 13 oz., so I will ship the package as priority mail. All the customer cares about is the fact they bought 6 items that offered free shipping, so they get free shipping.

Another example. If a customer buys one IPhone case, and another product that weighs 2#, they will be charged for the cost of a 2# package. In that package I'll include the IPhone case. The package will now weight 2# and 3 Oz., so I'll pay priority shipping for a 3# package, although the customer only paid for the shipping on a 2# package.

None of the above applies to international customers. They pay shipping for every item based on the weight of the item, and whatever service they choose.

As mentioned earlier, I only use USPS.

4 Mar 2013, 9:33 PM
#30
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

Actually the fact that an item would ship for first class shouldn't be the determining factor in how this is figured. The "trigger" should be if an item is marked as "free (U.S.) shipping". This way if there were ever an item that weighed more than 13 oz. and someone wanted to run it as a promotion and offer "Free Shipping" then they could just by marking it "Free Shipping"....irregardless of the weight of the item.

A couple more examples.....

A customer from the United States buys the following...
3 items that are marked as "free U.S. shipping". Each item weighs 6 Oz. each.
3 items that are NOT marked as free shipping. Each item weighs 1#
Since the 3 items that are 6 Oz. each, are all marked as "free U.S. Shipping" then the weight is ignored for those 3 items, and the shipping module figures the weight as 3#'s (3 items that each weigh 1# each), and charges the customer for a 3# Pkg. I package everything up, and the package weighs 4#, 2 oz. I pay for a 5# priority package, and mail it off.

A customer from Brazil makes the same identical purchase. Since none of the items are offered as free shipping to Brazil the module figures the total weight as 4#, 2 Oz. (3 x 1#, and 3 x 6 oz.). He chooses the way he wants to ship it at the price that the module figures for 4#, 2 oz., and I ship the package with the total postage cost being paid by the customer.

5 Mar 2013, 2:55 AM
#31
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free Shipping Within US/Charge for international

Do you currently use the Always Free Shipping on ANY of your products?

If not, did you look at post #5 and how to make a Zone for the US and use the Always Free Shipping so that ONLY those in your defined Zone for the US would get Free Shipping on those items and everyone else would be charged the weight on the Product? :lookaroun

5 Mar 2013, 9:00 AM
#32
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

Ajeh:

Do you currently use the Always Free Shipping on ANY of your products?

If not, did you look at post #5 and how to make a Zone for the US and use the Always Free Shipping so that ONLY those in your defined Zone for the US would get Free Shipping on those items and everyone else would be charged the weight on the Product? :lookaroun
In regards to the first question...I am just now setting this up, so I am just experimenting and trying to find the solution I need before I start entering all of my products.

In regards to the second question....that is EXACTLY what I want to do. If you see my post #8 in this thread I asked about doing that. All I originally asked for in this thread was what would be the zone "number" I needed to use that represented all 50 states, and the territories......but somehow that was never answered and the thread took an entirely different direction.

5 Mar 2013, 1:44 PM
#33
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free Shipping Within US/Charge for international

When you build the Zone Definition you will see in the URL if you click on it a number zID=1 ... if you do not see that in the URL, click on the blue arrow on the right side of the definition and you should see it ...

The reason 21 was suggested is because in the FAQs on Zone Definitions there are examples on how to build Zones and the US 48 plus DC happened to use 21 ...

If you want the 50 States, you could use the US 48 plus DC and add Alaska and Hawaii ...

If you want ALL of the US including the 50 States, DC and ALL US Territories, then you can create a Zone Definition by adding in the DETAILS:
Country: United States
Zone: All Zones

without having to add the individual States, DC and Territories ...

Afraid we got off on a tangent as you then said you only wanted First Class for your Free Shipping and what the solution in #5 explains is how to make Free Shipping on Products for US only (based on your Zone Definition defailts) and not for anyone else on Products and the Rest of the World gets charged the Product Weight ...

Mixed Carts for the US with both Free Shipping and non-Free Shipping Products would give the Shipping Methods for the weight of the non-Free Shipping Products with the Free Shipping Products having the Product weight excluded ...

7 Mar 2013, 12:36 AM
#34
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

Linda, I've made all the changes as described in the other thread. I think I'm closer (with your help), but still not quite there. I notice the other thread is almost two years old, so I'm wondering if that might have anything to do with it, since the USPS shipping mod that I edited is a different mod than what was being used back then?

The shipping mod's that I have enabled is the USPS mod and the freeshipper mod. All others are set to false. Right now I have nothing listed for tare weights until I get the main shipping figured out.

Here is what is happening.....

1 item is in the cart which is marked as "always free shipping" and has a weight of .125 entered.
The Shipping estimator shows the following
-- With a U.S. shipping address it shows "Free Shipping 0.00". GOOD
-- With a Canadian address it shows the correct shipping rates for Canada. GOOD
-- When I add 20 of the "always free shipping" items to the cart it still shows "Free Shipping 0.00" for the U.S. GOOD
-- And for shipping to Canada it shows the the correct shipping rates for Canada. GOOD

The ONLY question I would have on the above is this....When someone chooses a free item and it only shows "Free Shipping 0.00". Is it possible to show that along with options such as priority and express in case they want to upgrade to either of those? If not I'm entirely happy with what it is doing now.

NOW, here is the problem I am having.

1 item is in the cart which DOES NOT offer free shipping. There is a weight of 1# entered for this item.
The shipping estimator shows the following
-- With a U.S. shipping address it shows no shipping options or costs at all. WRONG
-- With a Canadian address it shows the correct shipping rates for Canada. GOOD

SECOND EXAMPLE
2 items in the cart. 1 of the items is a free shipping item with a weight of .125, and the other is an item that DOES NOT offer free shipping. This item has a weight of 1#.
The shipping estimator shows the following
-- With a U.S. shipping address it shows no shipping options or costs at all. It does show 2 items and 1#, but no price. WRONG
-- With a Canadian address it shows, 2 items and 1.13#, and the correct shipping rates for Canada. . GOOD

7 Mar 2013, 12:53 AM
#35
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free Shipping Within US/Charge for international

Can you post a copy of your file:
/includes/modules/shipping/usps.php

"from the server", that you are currently using?

Do you have an URL to the Product that is:

1 item is in the cart which DOES NOT offer free shipping.  There is a weight of 1# entered for this item.
The shipping estimator shows the following
-- With a U.S. shipping address it shows no shipping options or costs at all.  WRONG
-- With a Canadian address it shows the correct shipping rates for Canada.  GOOD

that we could perhaps peek at and see this issue? :lookaroun

As to showing USPS and Free Shipping at the same time for the US on the Products marked as ALWAYS FREE SHIPPING ...

If you were able to have Free Shipping on Products marked as ALWAYS FREE SHIPPING for the US and show regular USPS shipping prices that they can "upgrade" to, then would you want all of the USPS shipping methods to show or just some of them?

7 Mar 2013, 1:26 AM
#36
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

Here is the file you asked for. I have to post in 3 posts. 1 of 3

<?php /** * USPS Module for Zen Cart v1.3.x - v1.6 * RateV3 Updates to: January 27, 2013 Version G for CURL * * @package shippingMethod * @copyright Copyright 2003-2013 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: usps.php 18348G 2013-01-27 01:27:00Z ajeh $ */ // bof: functions contributed by Marco B //Quote sorting functions if (!function_exists('usps_sort_Alphanumeric')) { function usps_sort_Alphanumeric ($a, $b) { return strcmp($a['title'],$b['title']); } } if (!function_exists('usps_sort_Price')) { function usps_sort_Price ($a, $b) { $c=(float)$a['cost']; $d=(float)$b['cost']; if ($c==$d) return 0; return ($c>$d?1:-1); } } // eof: functions contributed by Marco B /** * USPS Shipping Module class * */ class usps extends base { /** * Declare shipping module alias code * * @var string */ var $code; /** * Shipping module display name * * @var string */ var $title; /** * Shipping module display description * * @var string */ var $description; /** * Shipping module icon filename/path * * @var string */ var $icon; /** * Shipping module status * * @var boolean */ var $enabled; /** * Shipping module list of supported countries (unique to USPS/UPS) * * @var array */ var $countries; /** * Constructor * * @return usps */ // use USPS translations for US shops var $usps_countries; function usps() { global $order, $db, $template, $current_page_base; $this->code = 'usps'; $this->title = MODULE_SHIPPING_USPS_TEXT_TITLE; if (MODULE_SHIPPING_USPS_STATUS == 'True' && MODULE_SHIPPING_USPS_DEBUG_MODE != 'Off' && IS_ADMIN_FLAG) { $this->title .= '<span class="alert"> (Debug is ON: ' . MODULE_SHIPPING_USPS_DEBUG_MODE . ')</span>'; } if (MODULE_SHIPPING_USPS_STATUS == 'True' && MODULE_SHIPPING_USPS_SERVER != 'production' && IS_ADMIN_FLAG) { $this->title .= '<span class="alert"> (USPS Server set to: ' . MODULE_SHIPPING_USPS_SERVER . ')</span>'; } $this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER; $this->icon = $template->get_template_dir('shipping_usps.gif', DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . 'shipping_usps.gif'; $this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS; $this->tax_basis = MODULE_SHIPPING_USPS_TAX_BASIS; // disable only when entire cart is free shipping // if (true || zen_get_shipping_enabled($this->code)) { $this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false); // } if ($this->enabled) { // check if all keys are in configuration table and correct version $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_VERSION'"); $check_version = $check_query->fields['configuration_value']; if (IS_ADMIN_FLAG) { $chk_sql = $db->Execute("select * from " . TABLE_CONFIGURATION . " where configuration_key like 'MODULE\_SHIPPING\_USPS\_%' "); $chk_keys = $this->keys(); if (($check_version != '2013-01-27') || (sizeof($chk_keys) != $chk_sql->RecordCount())) { $this->title = $this->title . '<span class="alert">' . ' - Missing Keys you should reinstall!' . '</span>'; } } } global $db, $order, $cart; $valid_zone_id = 4; $check_flag = false; $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $valid_zone_id . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); while (!$check->EOF) { if ($check->fields['zone_id'] < 1) { $check_flag = true; break; } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) { $check_flag = true; break; } $check->MoveNext(); } if ($check_flag == true) { $this->enabled = false; } else { $this->enabled = true; } // echo 'USPS shipping class delivery: ' . 'checkflag: ' . $check_flag . '<br> shipping: ' . $order->delivery['country']['id'] . ' state: ' . $order->delivery['state'] . ' zone: ' . $order->delivery['zone']['id']; if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) { $check_flag = false; $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_USPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); while (!$check->EOF) { if ($check->fields['zone_id'] < 1) { $check_flag = true; break; } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) { $check_flag = true; break; } $check->MoveNext(); } if ($check_flag == false) { $this->enabled = false; } } // update and new shipping names 01-27-2013 $this->types = array( 'EXPRESS' => 'Express Mail', // ID="0" 'FIRST CLASS' => 'First-Class Mail', // ID="1" 'PRIORITY' => 'Priority Mail', // ID="2" 'PARCEL' => 'Standard Post', // ID="3" changed from Parcel Post 01-27-2013 'MEDIA' => 'Media Mail', // ID="4" 'LIBRARY' => 'Library' // ID="5" ); // update and add new shipping names 01-02-2011 // 4 6 7 12 1 10 [17] 2 11 9 16 [24] [25] 8 [22] [23] [18] [20] 14 15 13 // update and new shipping names 01-22-2012 // 4 6 7 12 1 [26] 10 17 2 11 9 16 24 25 8 22 23 18 20 [19] [15] 14 13 // update and new shipping names 01-27-2013 // 4 6 7 12 1 26 10 17 [27] 2 11 9 16 24 25 8 22 23 18 20 19 [15] 14 13 $this->intl_types = array( 'Global Express' => 'Global Express Guaranteed (GXG)**', // ID="4" 'Global Express Non-Doc Rect' => 'Global Express Guaranteed Non-Document Rectangular', // ID="6" 'Global Express Non-Doc Non-Rect' => 'Global Express Guaranteed Non-Document Non-Rectangular', // ID="7" 'USPS GXG Envelopes' => 'USPS GXG Envelopes**', // ID="12" 'Express Mail Int' => 'Express Mail International', // ID="1" 'Express Mail Int Flat Rate Box' => 'Express Mail International Flat Rate Boxes', // ID="26" 'Express Mail Int Flat Rate Env' => 'Express Mail International Flat Rate Envelope', // ID="10" 'Express Mail Int Legal' => 'Express Mail International Legal Flat Rate Envelope', // ID="17" 'Express Mail Int Padded Flat Rate Env' => 'Express Mail International Padded Flat Rate Envelope', // ID="27" 'Priority Mail International' => 'Priority Mail International', // ID="2" 'Priority Mail Int Flat Rate Lrg Box' => 'Priority Mail International Large Flat Rate Box', // ID="11" 'Priority Mail Int Flat Rate Med Box' => 'Priority Mail International Medium Flat Rate Box', // ID="9" 'Priority Mail Int Flat Rate Small Box' => 'Priority Mail International Small Flat Rate Box**', // ID="16" 'Priority Mail Int DVD' => 'Priority Mail International DVD Flat Rate Box**', // ID="24" 'Priority Mail Int Lrg Video' => 'Priority Mail International Large Video Flat Rate Box**', // ID="25" 'Priority Mail Int Flat Rate Env' => 'Priority Mail International Flat Rate Envelope**', // ID="8" 'Priority Mail Int Legal Flat Rate Env' => 'Priority Mail International Legal Flat Rate Envelope**', // ID="22" 'Priority Mail Int Padded Flat Rate Env' => 'Priority Mail International Padded Flat Rate Envelope**', // ID="23" 'Priority Mail Int Gift Card Flat Rate Env' => 'Priority Mail International Gift Card Flat Rate Envelope**', // ID=18 'Priority Mail Int Small Flat Rate Env' => 'Priority Mail International Small Flat Rate Envelope**', // ID="20" 'Priority Mail Int Window Flat Rate Env' => 'Priority Mail International Window Flat Rate Envelope**', // ID=19 'First Class Mail Int Package' => 'First-Class Package International Service**', // ID="15" Changed Mail International Parcel to Package International Service 'First Class Mail Int Lrg Env' => 'First-Class Mail International Large Envelope**', // ID="14" 'First Class Mail Int Letter' => 'First-Class Mail International Letter**' // ID="13" ); $this->countries = $this->country_list(); // use USPS translations for US shops $this->usps_countries = $this->usps_translation(); } /** * Get quote from shipping provider's API: * * @param string $method * @return array of quotation results */ function quote($method = '') { // BOF: UPS USPS global $order, $shipping_weight, $shipping_num_boxes, $transittime; if ( zen_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) { $this->_setService($method); } // usps doesnt accept zero weight send 1 ounce (0.0625) minimum $usps_shipping_weight = ($shipping_weight <= 0.0 ? 0.0625 : $shipping_weight); $shipping_pounds = floor ($usps_shipping_weight); $shipping_ounces = (16 * ($usps_shipping_weight - floor($usps_shipping_weight))); // usps currently cannot handle more than 5 digits on international // change to 2 if International rates fail based on Tare Settings $shipping_ounces = zen_round($shipping_ounces, MODULE_SHIPPING_USPS_DECIMALS); // weight must be less than 35lbs and greater than 6 ounces or it is not machinable switch(true) { case ($shipping_pounds == 0 and $shipping_ounces < 6): // override admin choice too light $is_machinable = 'False'; break; case ($usps_shipping_weight > 35): // override admin choice too heavy $is_machinable = 'False'; break; default: // admin choice on what to use $is_machinable = MODULE_SHIPPING_USPS_MACHINABLE; } $this->_setMachinable($is_machinable); $this->_setContainer('None'); $this->_setSize('REGULAR'); $this->_setFirstClassType('FLAT'); $this->_setWeight($shipping_pounds, $shipping_ounces); $uspsQuote = $this->_getQuote(); if (is_array($uspsQuote)) { if (isset($uspsQuote['error'])) { $this->quotes = array('module' => $this->title, 'error' => $uspsQuote['error']); } else { // BOF: UPS USPS if (in_array('Display weight', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) { switch (SHIPPING_BOX_WEIGHT_DISPLAY) { case (0): $show_box_weight = ''; break; case (1): $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')'; break; case (2): $show_box_weight = ' (' . number_format($usps_shipping_weight * $shipping_num_boxes,2) . TEXT_SHIPPING_WEIGHT . ')'; break; default: $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($usps_shipping_weight,2) . TEXT_SHIPPING_WEIGHT . ')'; break; } } // EOF: UPS USPS // BOF: UPS USPS $this->quotes = array('id' => $this->code, 'module' => $this->title . $show_box_weight); // EOF: UPS USPS // set handling fee if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US')) { // national $usps_handling_fee = MODULE_SHIPPING_USPS_HANDLING; } else { // international $usps_handling_fee = MODULE_SHIPPING_USPS_HANDLING_INT; } $methods = array(); $size = sizeof($uspsQuote); for ($i=0; $i<$size; $i++) { list($type, $cost) = each($uspsQuote[$i]); // BOF: UPS USPS $title = ((isset($this->types[$type])) ? $this->types[$type] : $type); if(in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) $title .= $transittime[$type]; // strip the ** from the titles $title = str_replace('**', '', $title); $cost = preg_replace('/[^0-9.]/', '', $cost); // add $this->usps_countries to title to test actual country $methods[] = array('id' => $type, 'title' => $title, 'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? $usps_handling_fee * $shipping_num_boxes : $usps_handling_fee) ); // bof: sort by contributed by Marco B // Sort the options if (MODULE_SHIPPING_USPS_QUOTE_SORT != 'Unsorted') { usort($methods,'usps_sort_'.MODULE_SHIPPING_USPS_QUOTE_SORT); } // eof: sort by contributed by Marco B } $this->quotes['methods'] = $methods; if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } } } elseif ($uspsQuote == -1) { $this->quotes = array('module' => $this->title, 'error' => MODULE_SHIPPING_USPS_TEXT_SERVER_ERROR . (MODULE_SHIPPING_USPS_SERVER=='test' ? MODULE_SHIPPING_USPS_TEXT_TEST_MODE_NOTICE : '')); } else { $this->quotes = array('module' => $this->title, 'error' => MODULE_SHIPPING_USPS_TEXT_ERROR . (MODULE_SHIPPING_USPS_SERVER=='test' ? MODULE_SHIPPING_USPS_TEXT_TEST_MODE_NOTICE : '')); } if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title); return $this->quotes; } /** * check status of module * * @return boolean */ function check() { global $db; if (!isset($this->_check)) { $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'"); $this->_check = $check_query->RecordCount(); } return $this->_check; } /** * Install this module * */ function install() { global $db; $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('USPS Version Date', 'MODULE_SHIPPING_USPS_VERSION', '2013-01-27', 'You have installed:', '6', '0', 'zen_cfg_select_option(array(\'2013-01-27\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable USPS Shipping', 'MODULE_SHIPPING_USPS_STATUS', 'True', 'Do you want to offer USPS shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS Web Tools User ID', 'MODULE_SHIPPING_USPS_USERID', 'NONE', 'Enter the USPS USERID assigned to you for Rate Quotes/ShippingAPI.', '6', '0', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Which server to use', 'MODULE_SHIPPING_USPS_SERVER', 'production', 'An account at USPS is needed to use the Production server', '6', '0', 'zen_cfg_select_option(array(\'test\', \'production\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('All Packages are Machinable', 'MODULE_SHIPPING_USPS_MACHINABLE', 'False', 'Are all products shipped machinable based on C700 Package Services 2.0 Nonmachinable PARCEL POST USPS Rules and Regulations?<br /><br /><strong>Note: Nonmachinable packages will usually result in a higher Parcel Post Rate Charge.<br /><br />Packages 35lbs or more, or less than 6 ounces (.375), will be overridden and set to False</strong>', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee - US', 'MODULE_SHIPPING_USPS_HANDLING', '0', 'National Handling fee for this shipping method.', '6', '0', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee - International', 'MODULE_SHIPPING_USPS_HANDLING_INT', '0', 'International Handling fee for this shipping method.', '6', '0', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Handling Per Order or Per Box', 'MODULE_SHIPPING_USPS_HANDLING_METHOD', 'Box', 'Do you want to charge Handling Fee Per Order or Per Box?', '6', '0', 'zen_cfg_select_option(array(\'Order\', \'Box\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Quote Sort Order', 'MODULE_SHIPPING_USPS_QUOTE_SORT', 'Unsorted', 'Sorts the returned quotes using the service name Alphanumerically or by Price. Unsorted will give the order provided by USPS.', '6', '0', 'zen_cfg_select_option(array(\'Unsorted\',\'Alphanumeric\', \'Price\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Decimal Settings', 'MODULE_SHIPPING_USPS_DECIMALS', '3', 'Decimal Setting can be 1, 2 or 3. Sometimes International requires 2 decimals, based on Tare Rates or Product weights. Do you want to use 1, 2 or 3 decimals?', '6', '0', 'zen_cfg_select_option(array(\'1\', \'2\', \'3\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_USPS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_USPS_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_USPS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_USPS_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
7 Mar 2013, 1:28 AM
#37
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

File - 2 of 3

// National
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Domestic Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES', 'EXPRESS, PRIORITY, FIRST CLASS, PARCEL, MEDIA, LIBRARY', 'Select the domestic services to be offered:', '6', '14', 'zen_cfg_select_multioption(array('EXPRESS', 'PRIORITY', 'FIRST CLASS', 'PARCEL', 'MEDIA', 'LIBRARY'), ', now())");

// International
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('International Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES_INTL',
'Global Express, Global Express Non-Doc Rect, Global Express Non-Doc Non-Rect, USPS GXG Envelopes, Express Mail Int, Express Mail Int Flat Rate Box, Express Mail Int Flat Rate Env, Express Mail Int Legal, Express Mail Int Padded Flat Rate Env, Priority Mail International, Priority Mail Int Flat Rate Env, Priority Mail Int Flat Rate Small Box, Priority Mail Int Flat Rate Med Box, Priority Mail Int Flat Rate Lrg Box, Priority Mail Int DVD, Priority Mail Int Lrg Video, Priority Mail Int Legal Flat Rate Env, Priority Mail Int Padded Flat Rate Env, Priority Mail Int Gift Card Flat Rate Env, Priority Mail Int Small Flat Rate Env, Priority Mail Int Window Flat Rate Env, First Class Mail Int Lrg Env, First Class Mail Int Package, First Class Mail Int Letter',
'Select the international services to be offered:', '6', '15', 'zen_cfg_select_multioption(
array('Global Express', 'Global Express Non-Doc Rect', 'Global Express Non-Doc Non-Rect', 'USPS GXG Envelopes', 'Express Mail Int', 'Express Mail Int Flat Rate Box', 'Express Mail Int Flat Rate Env', 'Express Mail Int Legal', 'Express Mail Int Padded Flat Rate Env', 'Priority Mail International', 'Priority Mail Int Flat Rate Env', 'Priority Mail Int Flat Rate Small Box', 'Priority Mail Int Flat Rate Med Box', 'Priority Mail Int Flat Rate Lrg Box', 'Priority Mail Int DVD', 'Priority Mail Int Lrg Video', 'Priority Mail Int Legal Flat Rate Env', 'Priority Mail Int Padded Flat Rate Env', 'Priority Mail Int Gift Card Flat Rate Env', 'Priority Mail Int Small Flat Rate Env', 'Priority Mail Int Window Flat Rate Env', 'First Class Mail Int Lrg Env', 'First Class Mail Int Package', 'First Class Mail Int Letter'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('USPS Options', 'MODULE_SHIPPING_USPS_OPTIONS', 'Display weight, Display transit time', 'Select from the following the USPS options.', '6', '16', 'zen_cfg_select_multioption(array('Display weight', 'Display transit time'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Debug Mode', 'MODULE_SHIPPING_USPS_DEBUG_MODE', 'Off', 'Would you like to enable debug mode? A complete detailed log of USPS quote results may be emailed to the store owner, Log results or displayed to Screen.', '6', '0', 'zen_cfg_select_option(array('Off', 'Email', 'Logs', 'Screen'), ', now())");
}
/**

  • Remove this module

/
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key like 'MODULE_SHIPPING_USPS_%' ");
}
/
*

  • Build array of keys used for installing/managing this module
  • @return array
    /
    function keys() {
    $keys_list = array('MODULE_SHIPPING_USPS_VERSION', 'MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_SERVER', 'MODULE_SHIPPING_USPS_QUOTE_SORT', 'MODULE_SHIPPING_USPS_HANDLING', 'MODULE_SHIPPING_USPS_HANDLING_INT', 'MODULE_SHIPPING_USPS_HANDLING_METHOD', 'MODULE_SHIPPING_USPS_DECIMALS', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_TAX_BASIS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_MACHINABLE', 'MODULE_SHIPPING_USPS_OPTIONS', 'MODULE_SHIPPING_USPS_TYPES', 'MODULE_SHIPPING_USPS_TYPES_INTL');
    $keys_list[] = 'MODULE_SHIPPING_USPS_DEBUG_MODE';
    return $keys_list;
    }
    /
    *
  • Set USPS service mode
  • @param string $service
    /
    function _setService($service) {
    $this->service = $service;
    }
    /
    *
  • Set USPS weight for quotation collection
  • @param integer $pounds
  • @param integer $ounces
    /
    function _setWeight($pounds, $ounces=0) {
    $this->pounds = $pounds;
    $this->ounces = $ounces;
    }
    /
    *
  • Set USPS container type
  • @param string $container
    */
    function _setContainer($container) {
    $this->container = $container;
    }

/**

  • Set USPS Firs Class type
  • @param string $fctype
    */
    function _setFirstClassType($fctype) {
    $this->fctype = $fctype;
    }

/**

  • Set USPS package size
  • @param integer $size
    /
    function _setSize($size) {
    $this->size = $size;
    }
    /
    *
  • Set USPS machinable flag
  • @param boolean $machinable
    /
    function _setMachinable($machinable) {
    $this->machinable = $machinable;
    }
    /
    *
  • Get actual quote from USPS
  • @return array of results or boolean false if no results
    */
    function getQuote() {
    global $order, $transittime;
    if ((int)SHIPPING_ORIGIN_ZIP == 0) {
    // no quotes obtained no 5 digit zip code origin set
    return array('module' => $this->title,
    'error' => MODULE_SHIPPING_USPS_TEXT_ERROR . (MODULE_SHIPPING_USPS_SERVER=='test' ? MODULE_SHIPPING_USPS_TEXT_TEST_MODE_NOTICE : ''));
    }
    if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs') {
    $usps_instance_id = date('mdYGis');
    $usps_dir_logs = (defined('DIR_FS_LOGS') ? DIR_FS_LOGS : DIR_FS_SQL_CACHE);
    $logfilename = $usps_dir_logs . '/SHIP_usps_Debug
    ' . $usps_instance_id . '' . str_replace(' ', '', $order->delivery['country']['iso_code_2']) . '' . str_replace(' ', '', $order->delivery['postcode']) . '.log';
    }
// BOF: UPS USPS
if(in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) $transit = TRUE;
// EOF: UPS USPS

// translate for US Territories
// if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US')) {
$request = '<RateV3Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">';
$services_count = 0;

  if (isset($this->service)) {
    $this->types = array($this->service => $this->types[$this->service]);
  }

  $dest_zip = str_replace(' ', '', $order->delivery['postcode']);

// translate for US Territories
if ($order->delivery['country']['iso_code_2'] == 'US' || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US')) $dest_zip = substr($dest_zip, 0, 5);

  reset($this->types);
  // BOF: UPS USPS
  $allowed_types = explode(", ", MODULE_SHIPPING_USPS_TYPES);
  while (list($key, $value) = each($this->types)) {
    // BOF: UPS USPS
    if ( !in_array($key, $allowed_types) ) continue;
      //For Options list, go to page 6 of document: <http://www.usps.com/webtools/_pdf/Rate-Calculators-v1-2.pdf>
      //FIRST CLASS MAIL OPTIONS
      if ($key == 'FIRST CLASS') {
        $this->FirstClassMailType = '<FirstClassMailType>LETTER</FirstClassMailType>';
      } else {
        $this->FirstClassMailType = '';
      }
      //PRIORITY MAIL OPTIONS
      if ($key == 'PRIORITY'){
        $this->container = ''; // Blank, Flate Rate Envelope, or Flat Rate Box // Sm Flat Rate Box, Md Flat Rate Box and Lg Flat Rate Box

      }
      //EXPRESS MAIL OPTIONS
      if ($key == 'EXPRESS'){
        $this->container = '';  // Blank, or Flate Rate Envelope
      }
      //PARCEL POST OPTIONS
      if ($key == 'PARCEL'){
        $this->container = 'Regular';
        $this->machinable = 'true';
      }
      //MEDIA MAIL OPTIONS
      //LIBRARY MAIL OPTIONS
    $request .= '<Package ID="' . $services_count . '">' .
    '<Service>' . $key . '</Service>' .
    '<FirstClassMailType>' . $this->fctype . '</FirstClassMailType>' .
    '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' .
    '<ZipDestination>' . $dest_zip . '</ZipDestination>' .
    '<Pounds>' . $this->pounds . '</Pounds>' .
    '<Ounces>' . $this->ounces . '</Ounces>' .
    '<Container>' . $this->container . '</Container>' .
    '<Size>' . $this->size . '</Size>' .
    '<Machinable>' . $this->machinable . '</Machinable>' .
    '</Package>';
    // BOF: UPS USPS
    if($transit){
      $transitreq  = 'USERID="' . MODULE_SHIPPING_USPS_USERID . '">' .
      '<OriginZip>' . STORE_ORIGIN_ZIP . '</OriginZip>' .
      '<DestinationZip>' . $dest_zip . '</DestinationZip>';

      switch ($key) {
        case 'EXPRESS':  $transreq[$key] = 'API=ExpressMail&XML=' .
        urlencode( '<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>');
        break;
        case 'PRIORITY': $transreq[$key] = 'API=PriorityMail&XML=' .
        urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>');
        break;
        case 'PARCEL':   $transreq[$key] = 'API=StandardB&XML=' .
        urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>');
        break;
        default:         $transreq[$key] = '';
        break;
      }
    }
    // EOF: UPS USPS
    $services_count++;
  }
  $request .= '</RateV3Request>';

  $request = 'API=RateV3&XML=' . urlencode($request);
} else {
  // IntlRateRequest
  $request  = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '">' .
  '<Package ID="0">' .
  '<Pounds>' . $this->pounds . '</Pounds>' .
  '<Ounces>' . $this->ounces . '</Ounces>' .
  '<MailType>Package</MailType>' .
  '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' .
  '</Package>' .
  '</IntlRateRequest>';

  $request = 'API=IntlRate&XML=' . urlencode($request);
}

switch (MODULE_SHIPPING_USPS_SERVER) {
  case 'production':

// 01-02-2011
// 01-22-2012
$usps_server = 'http://production.shippingapis.com';
$api_dll = 'shippingapi.dll';
break;
case 'test':
default:
// 01-02-2011
// $usps_server = 'testing.shippingapis.com';
// $api_dll = 'ShippingAPI.dll';
// 01-22-2012
// $api_dll = 'stg-production.shippingapis.com';
// 01-27-2013
$usps_server = 'http://stg-production.shippingapis.com';
$api_dll = 'ShippingApi.dll';
break;
}

$body = '';

// BOF CURL
// Send quote request via CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $usps_server . '/' . $api_dll);
curl_setopt($ch, CURLOPT_REFERER, ($request_type == 'SSL' ? HTTPS_SERVER . DIR_WS_HTTPS_CATALOG : HTTP_SERVER . DIR_WS_CATALOG ));
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT, 'Zen Cart');
if (CURL_PROXY_REQUIRED == 'True') {
$this->proxy_tunnel_flag = (defined('CURL_PROXY_TUNNEL_FLAG') && strtoupper(CURL_PROXY_TUNNEL_FLAG) == 'FALSE') ? false : true;
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, $this->proxy_tunnel_flag);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY, CURL_PROXY_SERVER_DETAILS);
}

// submit request
$body = curl_exec($ch);

$this->commError = curl_error($ch);
$this->commErrNo = curl_errno($ch);
$this->commInfo = @curl_getinfo($ch);

// additional requests
// translate for US Territories
//      if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) {
if ($transit && is_array($transreq) && ( ($order->delivery['country']['id'] == STORE_COUNTRY || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US') )) ) {
  while (list($key, $value) = each($transreq)) {
    curl_setopt($ch, CURLOPT_POSTFIELDS, $value);
    $transresp[$key] = curl_exec($ch);
  }
}

curl_close ($ch);

// DEV ONLY - dump the returned data to the browser and stop execution
if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Email') mail(STORE_OWNER_EMAIL_ADDRESS, 'Debug: USPS rate quote response', '(You can turn off this debug email by editing your USPS module settings in the admin area of your store.) ' . "\n\n" . $body, 'From: <' . EMAIL_FROM . '>');
//      echo 'USPS METHODS: <pre>'; echo print_r($body); echo '</pre>';

if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Screen') {
  echo ($this->commErrNo != 0 ? '<br />' . $this->commErrNo . ' ' . $this->commError : '') . '<br /><pre>' . $body . '</pre><br />';
}
if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs') {
  // skip debug log if no destination zipcode is set
  $fp = @fopen($logfilename, 'a');
  if ($fp && $this->commErrNo != 0) {
    fwrite($fp, date('M d Y G:i:s') . ' -- ' . 'CommErr (should be 0): ' . $this->commErrNo . ' - ' . $this->commError . "\n\n" . $body . "\n\n");
    fclose($fp);
  }
}
//if communication error, return -1 because no quotes were found, and user doesn't need to see the actual error message (set DEBUG mode to get the messages logged instead)
if ($this->commErrNo != 0) return -1;

// EOF CURL

// old non-CURL method
if (FALSE) {
if (!class_exists('httpClient', FALSE)) require_once(DIR_WS_CLASSES . 'http_client.php');
$http = new httpClient();
$http->timeout = 5;
if ($http->Connect($usps_server, 80)) {
$http->addHeader('Host', $usps_server);
$http->addHeader('User-Agent', 'Zen Cart');
$http->addHeader('Connection', 'Close');

    if ($http->Get('/' . $api_dll . '?' . $request)) $body = $http->getBody();
    if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Email') mail(STORE_OWNER_EMAIL_ADDRESS, 'Debug: USPS rate quote response', '(You can turn off this debug email by editing your USPS module settings in the admin area of your store.) ' . "\n\n" . $body, 'From: <' . EMAIL_FROM . '>');

// echo 'USPS METHODS: <pre>'; echo print_r($body); echo '</pre>';
// BOF: UPS USPS

// translate for US Territories
// if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) {
if ($transit && is_array($transreq) && ( ($order->delivery['country']['id'] == STORE_COUNTRY || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US') )) ) {
while (list($key, $value) = each($transreq)) {
if ($http->Get('/' . $api_dll . '?' . $value)) $transresp[$key] = $http->getBody();
}
}
// EOF: UPS USPS

    $http->Disconnect();
  } else {
    return -1;
  }
} // false

// strip reg and trade out 01-02-2011
$body = str_replace('<sup>&reg;</sup>', '', $body);
$body = str_replace('<sup>&trade;</sup>', '', $body);

// USPS debug to Logs
if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs' || MODULE_SHIPPING_USPS_DEBUG_MODE == 'Screen') {
$body_display = $body;
$body_display = str_replace('<Service ID', (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs' ? "\n\n" : '<br /><br />') . '<Service ID', $body_display);
$body_display = str_replace('</Service>', '</Service>' . "\n\n", $body_display);
$body_display = str_replace('<MaxDimensions>', "\n" . '<MaxDimensions>', $body_display);
$body_display = str_replace('</MaxDimensions>', '</MaxDimensions>' . "\n", $body_display);

7 Mar 2013, 1:29 AM
#38
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

File 3 of 3

$body_display = str_replace('<Package ID', (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs' ? "\n\n" : '<br /><br />') . '<Package ID', $body_display);
$body_display = str_replace('</Package>', '</Package>', $body_display);
$body_display = str_replace('<Postage CLASSID', "\n" . '<Postage CLASSID', $body_display);
$body_display = str_replace('</Postage>', '</Postage>' . "\n", $body_display);

    global $shipping_weight;
    $body_display_header = '';
    $body_display_header .= "\n" . 'Server: ' . MODULE_SHIPPING_USPS_SERVER . "\n";
    $body_display_header .=  "\n" . 'Weight = ' . $shipping_weight . ' Pounds: ' . $this->pounds . ' Ounces: ' . $this->ounces . "\n";
    $body_display_header .= 'ZipOrigination: ' . ((int)SHIPPING_ORIGIN_ZIP == 0 ? '***WARNING: NO STORE 5 DIGIT ZIP CODE SET' : SHIPPING_ORIGIN_ZIP) . "\n" . 'ZipDestination: ' . $order->delivery['postcode'] . (!empty($this->countries[$order->delivery['country']['iso_code_2']]) ? ' Country: ' . $this->countries[$order->delivery['country']['iso_code_2']] : '') . ($order->delivery['city'] != '' ? ' City: ' . $order->delivery['city'] : '') . ($order->delivery['state'] != '' ? ' State: ' . $order->delivery['state'] : '') . "\n";
    $body_display_header .= 'Tare Rates - Small/Medium: ' . SHIPPING_BOX_WEIGHT . ' Large: ' . SHIPPING_BOX_PADDING . "\n";
    $body_display_header .= "\n" . 'RESPONSE FROM USPS: ' . "\n";

    if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Screen') {
      echo '<br />View Source:<br />' . "\n" . $body_display_header . "\n\n" . $body_display . '<br />';
    }
    if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Logs') {
      // skip debug log if no destination zipcode is set
        $fp = @fopen($logfilename, 'a');
        if ($fp) {
          fwrite($fp, date('M d Y G:i:s') . ' -- ' . $body_display_header . "\n\n" . $body_display . "\n\n");
          fclose($fp);
        }
    }
  }

// echo 'USPS METHODS: <pre>'; echo print_r($body); echo '</pre>';

$response = array();
while (true) {
  if ($start = strpos($body, '<Package ID=')) {
    $body = substr($body, $start);
    $end = strpos($body, '</Package>');
    $response[] = substr($body, 0, $end+10);
    $body = substr($body, $end+9);
  } else {
    break;
  }
}

$rates = array();

// translate for US Territories
// if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US')) {
if (sizeof($response) == '1') {
if (preg_match('/<Error>/i', $response[0])) {
$number = preg_match('/<Number>(.)</Number>/msi', $response[0], $regs);
$number = $regs[1];
$description = preg_match('/<Description>(.
)</Description>/msi', $response[0], $regs);
$description = $regs[1];

      return array('error' => $number . ' - ' . $description);
    }
  }

  $n = sizeof($response);
  for ($i=0; $i<$n; $i++) {
    if (strpos($response[$i], '<Rate>')) {
      $service = preg_match('/<MailService>(.*)<\/MailService>/msi', $response[$i], $regs);
      $service = $regs[1];
      if (preg_match('/Express/i', $service)) $service = 'EXPRESS';
      if (preg_match('/Priority/i', $service)) $service = 'PRIORITY';
      if (preg_match('/First-Class Mail/i', $service)) $service = 'FIRST CLASS';
      if (preg_match('/Standard/i', $service)) $service = 'PARCEL'; // Parcel to Standard 2013-01-27
      if (preg_match('/Media/i', $service)) $service = 'MEDIA';
      if (preg_match('/Library/i', $service)) $service = 'LIBRARY';
      $postage = preg_match('/<Rate>(.*)<\/Rate>/msi', $response[$i], $regs);
      $postage = $regs[1];

      $rates[] = array($service => $postage);
      // BOF: UPS USPS
      if ($transit) {
        switch ($service) {
          case 'EXPRESS':     $time = preg_match('/<MonFriCommitment>(.*)<\/MonFriCommitment>/msi', $transresp[$service], $tregs);
          $time = $tregs[1];
          if ($time == '' || $time == 'No Data') {
            $time = '1 - 2 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          } else {
            $time = 'Tomorrow by ' . $time;
          }
          break;
          case 'PRIORITY':    $time = preg_match('/<Days>(.*)<\/Days>/msi', $transresp[$service], $tregs);
          $time = $tregs[1];
          if ($time == '' || $time == 'No Data') {
            $time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          } elseif ($time == '1') {
            $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;
          } else {
            $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          }
          break;
          case 'PARCEL':      $time = preg_match('/<Days>(.*)<\/Days>/msi', $transresp[$service], $tregs);
          $time = $tregs[1];
          if ($time == '' || $time == 'No Data') {
            $time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          } elseif ($time == '1') {
            $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;
          } else {
            $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          }
          break;
          case 'FIRST CLASS': $time = '2 - 5 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
          break;


          default:            $time = '';
          break;
        }
        if ($time != '') $transittime[$service] = ' (' . $time . ')';
      }
      // EOF: UPS USPS
    }
  }
} else {
  if (preg_match('/<Error>/i', $response[0])) {
    $number = preg_match('/<Number>(.*)<\/Number>/msi', $response[0], $regs);
    $number = $regs[1];
    $description = preg_match('/<Description>(.*)<\/Description>/msi', $response[0], $regs);
    $description = $regs[1];

    return array('error' => $number . ' - ' . $description);
  } else {
    $body = $response[0];
    $services = array();
    while (true) {
      if ($start = strpos($body, '<Service ID=')) {
        $body = substr($body, $start);
        $end = strpos($body, '</Service>');
        $services[] = substr($body, 0, $end+10);
        $body = substr($body, $end+9);
      } else {
        break;
      }
    }

    // BOF: UPS USPS
    $allowed_types = array();
    foreach( explode(", ", MODULE_SHIPPING_USPS_TYPES_INTL) as $value ) $allowed_types[$value] = $this->intl_types[$value];
    // EOF: UPS USPS

    $size = sizeof($services);
    for ($i=0, $n=$size; $i<$n; $i++) {
      if (strpos($services[$i], '<Postage>')) {
        $service = preg_match('/<SvcDescription>(.*)<\/SvcDescription>/msi', $services[$i], $regs);
        $service = $regs[1];
        $postage = preg_match('/<Postage>(.*)<\/Postage>/i', $services[$i], $regs);
        $postage = $regs[1];
        // BOF: UPS USPS
        $time = preg_match('/<SvcCommitments>(.*)<\/SvcCommitments>/msi', $services[$i], $tregs);
        $time = $tregs[1];
        $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time);
        $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time);
        $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time);

        if( !in_array($service, $allowed_types) ) continue;
        if ($_SESSION['cart']->total > 400 && strstr($services[$i], 'Priority Mail International Flat Rate Envelope')) continue; // skip value > $400 Priority Mail International Flat Rate Envelope
        // EOF: UPS USPS
        if (isset($this->service) && ($service != $this->service) ) {
          continue;
        }

        $rates[] = array($service => $postage);
        // BOF: UPS USPS
        if ($time != '') $transittime[$service] = ' (' . $time . ')';
        // EOF: UPS USPS
      }
    }
  }
}

return ((sizeof($rates) > 0) ? $rates : false);

}
/**

  • USPS Country Code List
  • This list is used to compare the 2-letter ISO code against the order country ISO code, and provide the proper/expected
  • spelling of the country name to USPS in order to obtain a rate quote
  • @return array
    */
    function country_list() {
    $list = array(
    'AF' => 'Afghanistan',
    'AL' => 'Albania',
    'AX' => 'Aland Island (Finland)',
    'DZ' => 'Algeria',
    'AD' => 'Andorra',
    'AO' => 'Angola',
    'AI' => 'Anguilla',
    'AG' => 'Antigua and Barbuda',
    'AR' => 'Argentina',
    'AM' => 'Armenia',
    'AW' => 'Aruba',
    'AU' => 'Australia',
    'AT' => 'Austria',
    'AZ' => 'Azerbaijan',
    'BS' => 'Bahamas',
    'BH' => 'Bahrain',
    'BD' => 'Bangladesh',
    'BB' => 'Barbados',
    'BY' => 'Belarus',
    'BE' => 'Belgium',
    'BZ' => 'Belize',
    'BJ' => 'Benin',
    'BM' => 'Bermuda',
    'BT' => 'Bhutan',
    'BO' => 'Bolivia',
    'BA' => 'Bosnia-Herzegovina',
    'BW' => 'Botswana',
    'BR' => 'Brazil',
    'VG' => 'British Virgin Islands',
    'BN' => 'Brunei Darussalam',
    'BG' => 'Bulgaria',
    'BF' => 'Burkina Faso',
    'MM' => 'Burma',
    'BI' => 'Burundi',
    'KH' => 'Cambodia',
    'CM' => 'Cameroon',
    'CA' => 'Canada',
    'CV' => 'Cape Verde',
    'KY' => 'Cayman Islands',
    'CF' => 'Central African Republic',
    'TD' => 'Chad',
    'CL' => 'Chile',
    'CN' => 'China',
    'CX' => 'Christmas Island (Australia)',
    'CC' => 'Cocos Island (Australia)',
    'CO' => 'Colombia',
    'KM' => 'Comoros',
    'CG' => 'Congo, Republic of the',
    'CD' => 'Congo, Democratic Republic of the',
    'CK' => 'Cook Islands (New Zealand)',
    'CR' => 'Costa Rica',
    'CI' => 'Cote d Ivoire (Ivory Coast)',
    'HR' => 'Croatia',
    'CU' => 'Cuba',
    'CY' => 'Cyprus',
    'CZ' => 'Czech Republic',
    'DK' => 'Denmark',
    'DJ' => 'Djibouti',
    'DM' => 'Dominica',
    'DO' => 'Dominican Republic',
    'EC' => 'Ecuador',
    'EG' => 'Egypt',
    'SV' => 'El Salvador',
    'GQ' => 'Equatorial Guinea',
    'ER' => 'Eritrea',
    'EE' => 'Estonia',
    'ET' => 'Ethiopia',
    'FK' => 'Falkland Islands',
    'FO' => 'Faroe Islands',
    'FJ' => 'Fiji',
    'FI' => 'Finland',
    'FR' => 'France',
    'GF' => 'French Guiana',
    'PF' => 'French Polynesia',
    'GA' => 'Gabon',
    'GM' => 'Gambia',
    'GE' => 'Georgia, Republic of',
    'DE' => 'Germany',
    'GH' => 'Ghana',
    'GI' => 'Gibraltar',
    'GB' => 'Great Britain and Northern Ireland',
    'GR' => 'Greece',
    'GL' => 'Greenland',
    'GD' => 'Grenada',
    'GP' => 'Guadeloupe',
    'GT' => 'Guatemala',
    'GN' => 'Guinea',
    'GW' => 'Guinea-Bissau',
    'GY' => 'Guyana',
    'HT' => 'Haiti',
    'HN' => 'Honduras',
    'HK' => 'Hong Kong',
    'HU' => 'Hungary',
    'IS' => 'Iceland',
    'IN' => 'India',
    'ID' => 'Indonesia',
    'IR' => 'Iran',
    'IQ' => 'Iraq',
    'IE' => 'Ireland',
    'IL' => 'Israel',
    'IT' => 'Italy',
    'JM' => 'Jamaica',
    'JP' => 'Japan',
    'JO' => 'Jordan',
    'KZ' => 'Kazakhstan',
    'KE' => 'Kenya',
    'KI' => 'Kiribati',
    'KW' => 'Kuwait',
    'KG' => 'Kyrgyzstan',
    'LA' => 'Laos',
    'LV' => 'Latvia',
    'LB' => 'Lebanon',
    'LS' => 'Lesotho',
    'LR' => 'Liberia',
    'LY' => 'Libya',
    'LI' => 'Liechtenstein',
    'LT' => 'Lithuania',
    'LU' => 'Luxembourg',
    'MO' => 'Macao',
    'MK' => 'Macedonia, Republic of',
    'MG' => 'Madagascar',
    'MW' => 'Malawi',
    'MY' => 'Malaysia',
    'MV' => 'Maldives',
    'ML' => 'Mali',
    'MT' => 'Malta',
    'MQ' => 'Martinique',
    'MR' => 'Mauritania',
    'MU' => 'Mauritius',
    'YT' => 'Mayotte (France)',
    'MX' => 'Mexico',
    'FM' => 'Micronesia, Federated States of',
    'MD' => 'Moldova',
    'MC' => 'Monaco (France)',
    'MN' => 'Mongolia',
    'MS' => 'Montserrat',
    'MA' => 'Morocco',
    'MZ' => 'Mozambique',
    'NA' => 'Namibia',
    'NR' => 'Nauru',
    'NP' => 'Nepal',
    'NL' => 'Netherlands',
    'AN' => 'Netherlands Antilles',
    'NC' => 'New Caledonia',
    'NZ' => 'New Zealand',
    'NI' => 'Nicaragua',
    'NE' => 'Niger',
    'NG' => 'Nigeria',
    'KP' => 'North Korea (Korea, Democratic People's Republic of)',
    'NO' => 'Norway',
    'OM' => 'Oman',
    'PK' => 'Pakistan',
    'PA' => 'Panama',
    'PG' => 'Papua New Guinea',
    'PY' => 'Paraguay',
    'PE' => 'Peru',
    'PH' => 'Philippines',
    'PN' => 'Pitcairn Island',
    'PL' => 'Poland',
    'PT' => 'Portugal',
    'QA' => 'Qatar',
    'RE' => 'Reunion',
    'RO' => 'Romania',
    'RU' => 'Russia',
    'RW' => 'Rwanda',
    'SH' => 'Saint Helena',
    'KN' => 'Saint Kitts (St. Christopher and Nevis)',
    'LC' => 'Saint Lucia',
    'PM' => 'Saint Pierre and Miquelon',
    'VC' => 'Saint Vincent and the Grenadines',
    'SM' => 'San Marino',
    'ST' => 'Sao Tome and Principe',
    'SA' => 'Saudi Arabia',
    'SN' => 'Senegal',
    'RS' => 'Serbia',
    'SC' => 'Seychelles',
    'SL' => 'Sierra Leone',
    'SG' => 'Singapore',
    'SK' => 'Slovak Republic',
    'SI' => 'Slovenia',
    'SB' => 'Solomon Islands',
    'SO' => 'Somalia',
    'ZA' => 'South Africa',
    'GS' => 'South Georgia (Falkland Islands)',
    'KR' => 'South Korea (Korea, Republic of)',
    'ES' => 'Spain',
    'LK' => 'Sri Lanka',
    'SD' => 'Sudan',
    'SR' => 'Suriname',
    'SZ' => 'Swaziland',
    'SE' => 'Sweden',
    'CH' => 'Switzerland',
    'SY' => 'Syrian Arab Republic',
    'TW' => 'Taiwan',
    'TJ' => 'Tajikistan',
    'TZ' => 'Tanzania',
    'TH' => 'Thailand',
    'TL' => 'East Timor (Indonesia)',
    'TG' => 'Togo',
    'TK' => 'Tokelau (Union) Group (Western Samoa)',
    'TO' => 'Tonga',
    'TT' => 'Trinidad and Tobago',
    'TN' => 'Tunisia',
    'TR' => 'Turkey',
    'TM' => 'Turkmenistan',
    'TC' => 'Turks and Caicos Islands',
    'TV' => 'Tuvalu',
    'UG' => 'Uganda',
    'UA' => 'Ukraine',
    'AE' => 'United Arab Emirates',
    'UY' => 'Uruguay',
    'UZ' => 'Uzbekistan',
    'VU' => 'Vanuatu',
    'VA' => 'Vatican City',
    'VE' => 'Venezuela',
    'VN' => 'Vietnam',
    'WF' => 'Wallis and Futuna Islands',
    'WS' => 'Western Samoa',
    'YE' => 'Yemen',
    'ZM' => 'Zambia',
    'ZW' => 'Zimbabwe',
    'PS' => 'Palestinian Territory', // usps does not ship
    'ME' => 'Montenegro',
    'GG' => 'Guernsey',
    'IM' => 'Isle of Man',
    'JE' => 'Jersey'
    );
return $list;

}

// translate for US Territories
function usps_translation() {
global $order;
global $selected_country, $state_zone_id;
if (SHIPPING_ORIGIN_COUNTRY == '223') {
switch($order->delivery['country']['iso_code_2']) {
case 'AS': // Samoa American
case 'GU': // Guam
case 'MP': // Northern Mariana Islands
case 'PW': // Palau
case 'PR': // Puerto Rico
case 'VI': // Virgin Islands US
// which is right
case 'FM': // Micronesia, Federated States of
return 'US';
break;
// stays as original country
// case 'FM': // Micronesia, Federated States of
default:
return $order->delivery['country']['iso_code_2'];
break;
}
} else {
return $order->delivery['country']['iso_code_2'];
}
}
}

7 Mar 2013, 1:35 AM
#39
jusmejim avatar

jusmejim

New Zenner

Join Date:
Feb 2013
Posts:
41
Plugin Contributions:
0

Re: Free Shipping Within US/Charge for international

Here is the item with no free shipping and 1# of weight.

http://itsyourgifts.com/index.php?main_page=product_info&cPath=3&products_id=5

I also have a couple of items under iphone cases that are both marked...one free and one not free if you want to use them to play around with.

Ajeh:

As to showing USPS and Free Shipping at the same time for the US on the Products marked as ALWAYS FREE SHIPPING ...

If you were able to have Free Shipping on Products marked as ALWAYS FREE SHIPPING for the US and show regular USPS shipping prices that they can "upgrade" to, then would you want all of the USPS shipping methods to show or just some of them?

In regards to the above. If it can be done all I'd care about is priority and express showing besides the free option.

7 Mar 2013, 1:51 AM
#40
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Free Shipping Within US/Charge for international

While I am looking at this ... add this to your stylesheet.css

.hiddenField {
    display: none;
}
.visibleField {
    display: inline;
}

Also if you look at your Zone Definition for zone_id 4 ... can you do a screen shoot of the DETAILS on the first page?