Shopp USPS plugin and the British Empire

KOL Discovery entering Vancouver Harbour Feb 05-09 3PM

photo credit: Grantsviews

If you are a fan of Shopp (http://shopplugin.net/), you’ve probably been happy that there’s a built-in solution for shopping carts from inside the WordPress interface.  You’ll also be happy to learn that it’s themeable and extendable much like WordPress itself.  But you are also going to be aware that quite a few features are there, but just haven’t been polished enough to work out of the box.  Shopp is young, and while it doesn’t have the bloat of old standbys such as Opencart or Zen Cart, it doesn’t have the patches and bug fixes for a completely bumpless ride, either.

In this ongoing series, I’m going to document my bouts with Shopp and, more importantly, my solutions to the problems I have found.

Yesterday, a client had a customer from Kent, GB who had a checkout error during shipping computation:

USPSRates: Missing value for Country.

They fell back to our other shipping method, UPS, which happened to compute to $77 from our US location.  The customer emailed, asking if we were crazy, and the process went up the chain to me.

Poking in the the /wp-content/plugins/shopp/plugins/USPSRates.php file, I noticed that the Shopp developers had already included some code to try to handle GB/UK:

[php]
$country = $countries[$country][‘name’];
if ($countries[$country] == "UK") $country .= ‘ (Great Britain)’;
[/php]

But this didn’t quite handle the situation, which sets $country to ‘United Kingdom (Great Britain)’. Looking further down the plugin code, I saw that they were not using the $country variable when sending data to USPS:

[php]
$_[] = ”.$countries[$country][‘name’].”;
[/php]

Looking at the USPS website Postal Codes Listing, there are many codes for shipping to Great Britain, including the “United Kingdom (Great Britain)”. My change that worked was setting the following up, directly in the international part of the site:

Find:

[php]
$_[] = ”.$countries[$country][‘name’].”;
[/php]

and replace with:

[php]
if($country == ‘United Kingdom’){
$_[] = ‘Great Britain and Northern Ireland’;
}
else {
$_[] = ”.$countries[$country][‘name’].”;
}
[/php]

This only solves the issue for shipping to Great Britain, and quite a few of the USPS names are different from the ones stored in Shopp. The real solution is for the database to store the alternate names for countries as USPS calls them. In the meantime, I believe I’ll make an array inside the USPSRates.php file, and map the correct names to the correct USPS names for international shipping. I’ll post that full patch here when I do it.

The shipping plugins for Shopp are an additional nominal charge (In USPS’s case, it’s $25) from the Shopp website..  You’ll have to have an API key from USPS to use the plugin.

If you are interested in hiring us for Shopp customizations or other design / programming needs, send us a message.