Canada Post Shipping

Contrib type: 
Module
Status: 
Complete and working
Moderation: 
Limited approval
Latest version: 
0.4
Compatibility: 
Ubercart 1.x

Originally created by gregmac, this module has been updated and is now maintained by TR.

Module that interfaces with Canada Post's "SellOnline" service (http://sellonline.canadapost.ca) to obtain shipping quotes. Works for both domestic and international shipments.

Module description from gregmac:

Right now, for simplicity, I am totally ignoring product dimensions. It sends the quote with dimensions 1x1x1cm and marked as "ready to ship" so Canada Post does not attempt to pack it into boxes for you. The shipping price is based entirely on weight. In my very limited testing so far this seems to work fine, but I'd love some feedback.

I chose to leave dimensions out of the picture for a number of reasons - mostly that it is incredibly complex. It is a lot of extra work when adding products to the store. There are no dimensions fields for a product, so they would have to be supplied by this module (much like the UPS module does), which is redundant and makes it even more tedious for the store admin. Canada Post will do the "box packing" for you (based on predefined box sizes you set up on your SellOnline account) -- which is fine unless you're a small business (like the one I'm writing this for) that just ships with whatever boxes happen to be available.

The implication of this is that for large but light objects, you'll have to enter the weight a bit higher than usual. There is a calculation the shipping companies do to calculate what they call "dimensional weight" - if it's higher than the real weight, they base the price on that instead (to simplify it).

It also means that prices for multi-box shipments will be off - perhaps this can be handled by splitting up shipments into separate "boxes" for every x kg.

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

This module has been updated by TR to version 0.2 to include splitting boxes for every x kg. View the details in his comment below.

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

Version 0.3 implements the missing "Markup" functionality on the admin page. Now you can apply a rate markup to the Canada Post rates before presenting the quote to your customer.

Version 0.4 adds minor fixes:

  • An updated Canada Post services list (see comment #62)
  • A new theme function theme_uc_canadapost_option_label() for displaying the quote line items on the checkout page
  • A .pot file to facilitate translations
  • Integration with the I18N module, to request French language quotes from Canada Post when I18N is set to 'fr' (see comment #63)
  • Use of format_plural where needed

PreviewAttachmentSize
uc_canadapost-5.x-0.4.tar.gz10.36 KB
Joined: 08/07/2007
Juice: 6673

Products have dimension fields, and have had them since alpha7e at least. They are available to the shipping method via node_load().

 
Joined: 09/19/2007
Juice: 89

I have messed around with the module to get it working, turns out it isn't that bad.

Two things need changing:

1 - Change the switch line that calculates the weight into KG as the variable changed at some point:

function _uc_canadapost_make_request($products, $details) {
  $cpcid = variable_get('uc_canadapost_cpcid', '');
  $turnaround = variable_get('uc_canadapost_turnaround', false);
  $from_postalcode = variable_get('uc_canadapost_postalcode', false);
 
  $weight = 0;
  $price = 0;
  foreach ($products as $product){
    $product->weight *= $product->qty;
    // convert to kg
    switch ($product->units){

To:

    switch ($product->weight_units){

2 - Add the new workflow_ng function: (Copied the one from USPS and modified it)

/******************************************************************************
* Workflow-ng Hooks                                                          *
******************************************************************************/

function uc_canadapost_configuration(){
  $enabled = variable_get('uc_quote_enabled', array('canadapost' => true));
  $configurations = array(
    'uc_canadapost_get_quote' => array(
      '#label' => t('Shipping quote from Canada Post'),
      '#event' => 'get_quote_from_canadapost',
      '#module' => 'uc_canadapost',
      '#active' => $enabled['canadapost'],
    ),
  );
 
  $action = workflow_ng_use_action('uc_quote_action_get_quote', array(
    '#label' => t('Fetch a shipping quote'),
  ));
  $configurations['uc_canadapost_get_quote'] = workflow_ng_configure($configurations['uc_canadapost_get_quote'], $action);
 
  return $configurations;
}

Note: Work still needs to be done as some countries return nothing at all, and orders that exceed the 30KG limit don't display an error.

Let me know if you have any questions.

I am also attaching a copy of my modified module, replace your own module file

AttachmentSize
uc_canadapost.module 19.93 KB
 
Joined: 02/06/2008
Juice: 200

this mod is just what I'm looking for, eh ? I'm also hoping for a canada post tracking mod ??

Unfortunately the link seems broken. Please repost ?

 
Joined: 02/06/2008
Juice: 200

Does anyone have a copy of this mod that you can pm to me ? The link here seems broken.

 
Joined: 02/09/2008
Juice: 47

Has anyone implemented this module on a live site, what kindof problems will this module give me if I start using it.

Do I have a choice on how to do Canadian shipping without this?

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220
rolandk wrote:

Does anyone have a copy of this mod that you can pm to me ? The link here seems broken.

The link appears broken because the default Drupal .htaccess forbids serving .module files. I'm sure the file actually exists on the server, but you'll have to get one of the admins to zip it up and fix the above link so it can actually be served.

<tr>.
 
Joined: 02/06/2008
Juice: 200

Ryaaaaaaaaaaaaaaaaaaaaan !

 
Joined: 02/06/2008
Juice: 200

Admins have confirmed and I look forward to seeing the zip attachment soon.

 
Joined: 08/07/2007
Juice: 15046

Forgot about it by the time I got to work yesterday. Eye-wink

AttachmentSize
uc_canadapost.tar 24 KB
 
Joined: 01/11/2008
Juice: 315

Not live but I tried it out yesterday and the quotes were a bit off. Probably because dimensions are not used. It would be really beneficial to have dimensions as this is how CP would let you know how many boxes would be needed for multiple items.

For example with Zen cart CP addon a customer will be shown how many boxes are going to be used if you have multiple items.

 
Dan
Dan's picture
Joined: 03/05/2008
Juice: 2

I'm about to set the shipping for my site and wondering how you're doing with the CP module? Would it be possible to chat with you about it? I can be reached at 250-612-9161.

 
Joined: 01/11/2008
Juice: 315

Discovered a problem today with weight and box sizes.

I have an item that I set the weight to 5kg and box size to 20-20-20cm. I've also created a box on the Sellonline profile page size 25-25-25cm.

Whats happening is the module keeps giving me quotes until I get over 30kg in product weight. So if I have 6 of my 5KG items I'm ok but on the 7th one I just get an error and the module doesn't allow to put items into several boxes.

There were problems getting a shipping quote. Please verify the delivery and product information and try again.
If this does not resolve the issue, please call in to complete your order.

When I was running Zencart every time a box reached its limit in weight or the items filled the dimensions the CP module would list the amount of boxes need for the shipment and then adjust the shipping cost accordingly.

What are the chances of modifying this modules to perform the same task. I'm willing to put up money to get it done as this kinds puts a crinkle in getting my site live.

 
Joined: 01/11/2008
Juice: 315

I did some more testing and I can't get CP quotes if the total weight of all the items reaches past 30K. Also I've attached a screen shot of how Zencart CP modules handles boxes.

AttachmentSize
zen_cp.gif 23.42 KB
 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

Development of this new version of uc_canadapost was sponsored by PnwGardenSupply.com / MyGreenPlanet.com

The differences between this version and the previously posted versions are listed below. The main feature of this version is the automatic division of order products into packages of 30kg or less. 30kg is the Canada Post weight limit for a package. This version will calculate how many packages need to be sent, calculate the cost of shipping each package, and display the total number of packages and the total shipping cost to the customer.

Modifications to the uc_canadapost.module posted at the top of this thread include:

  • Added uc_canadapost_package_products() which limits the weight of a package to 30kg and returns an array of packages and their weights.
  • Modified uc_canadapost_make_request() to accept $packages (an array of packages to be shipped) as an argument instead of $products (an array of products to be shipped).
  • Modified uc_canadapost_quote() to call the packaging function, get a quote for each package, and calculate the order shipping quote as the sum the package shipping quotes.
  • Added Workflow-ng configuration hook uc_canadapost_configuration() so Workflow-ng can be used to set conditions for uc_canadapost. (For example, free shipping on orders over $x, etc.). This makes uc_canadapost behave like all the other shipping modules.
  • Added code to strip spaces from postal codes.
  • Changed some formatting to conform to Drupal coding standards. Changed some formatting for readability.
  • Added comments.
AttachmentSize
uc_canadapost-5.x-0.2.tar.gz 7.32 KB
<tr>.
 
Joined: 01/11/2008
Juice: 315

Thanks TR for the quick work Smiling

I have attached a screen shot for those who want to see what this will look like when I user gets a quote at checkout time.

AttachmentSize
uc_canadapost.gif 26.17 KB
 
Joined: 08/07/2007
Juice: 15046

You da man, TR. gregmac hasn't been around in a couple of months, so I'm going to go ahead and add your version to the project page. I don't want to rope you into supporting something long term that you got paid to improve once, but let me know if you'd want this contrib to be assigned to you if he has no objections.

 
Joined: 02/06/2008
Juice: 200

TR, On behalf of all Canada-based Ubercarters, thanks - appreciate the work on this mod.

 
Joined: 06/30/2008
Juice: 2

No matter what I do, I always get a timeout error ('110 Connection timed out') when opening the socket in _uc_canadapost_drupal_http_request() (line 391).

Anybody else is having the same error message or knows how to fix it? I tried increasing the connection timeout parameter from 15 seconds to 30 but to no avail.

Thanks in advance!

 
Joined: 01/11/2008
Juice: 315

I haven't had time to work on my sites but I just tried it and it works fine here. Did you make sure port 30000 is open? If not ask your host to open it. If they don't find and new host Smiling

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

The error means that the application can't open a socket (network connection) to the Canada Post server - 99.99% sure that's due to your server configurations. Perhaps your web host doesn't allow outgoing socket connections, perhaps your host requires outgoing connections to go through a proxy, etc. You should look at your host's FAQ or call their support to find out.

<tr>.
 
Joined: 01/11/2008
Juice: 315

Wrong port. It's port 3000

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220
end user wrote:

Wrong port. It's port 3000

No, you were right the first time. It's port 30000 (with four zeros).

<tr>.
 
Joined: 11/21/2007
Juice: 10

Markup isn't being applied

In uc_canadapost_quote it grabs the value you set in admin and assigns it to a variable but it doesn't actually do anything with it

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

A curious omission in the original code! I added the code to do the markup - download version 0.3 at the top of this thread.

<tr>.
 
Joined: 11/21/2007
Juice: 10

thanks

 
Joined: 07/25/2008
Juice: 24

It doesn't work for me. I don't know what I'm doing wrong, but when I click calculate shipping, its just a blank screen, no error or anything, anyone mind helping me?

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220
<tr>.
 
Joined: 07/25/2008
Juice: 24

Thanks but none of those worked, here's what shows up:

http://img177.imageshack.us/img177/6023/ucerrorob8.jpg

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

Please be a little more specific. That screen shot is from the /cart page. And it's not blank. Does any shipping module work for you? Have you set your store address? Have you entered your Canada Post credentials (& are they valid)?

<tr>.
 
Joined: 07/25/2008
Juice: 24

Yes, UPS was working, Yes I have entered my store address, and I'm pretty sure my Canada Post credentials are correct.

 
Joined: 07/25/2008
Juice: 24

I still haven't gotten it to work, I am 99% sure my Canada Post credentials are correct. If ANYONE can help me, I would truly, truly, appreciate it.

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

Give me a URL to look at, otherwise all I can do is guess.

<tr>.
 
Joined: 07/25/2008
Juice: 24
 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

I can see nothing obviously wrong from looking at your site. The fact that the quote doesn't return anything really seems to be a configuration problem on your end. You can uncomment lines 268 and 269 in uc_canadapost.module to print out some debugging information - that will show the request being sent to the Canada Post server, and the reply from the server. You should also verify that your Canada Post SellOnline preferences are configured properly on the Canada Post server. You should also make sure your web host allows outgoing http requests without a proxy - maybe you have to open a port in the firewall. You can test from your server command line with wget http://sellonline.canadapost.ca/ - this command should save the contents of index.html to your local disk. If it fails then the problem is with your web host.

<tr>.
 
Joined: 07/25/2008
Juice: 24

Turns out my host doesn't allow outgoing port access, and in order to gain access to it I must purchase a dedicated IP address.

You think this is the issue here? Because I am really not wanting to spend money on a dedicated IP if its not the problem at all.

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

Well YES it's a problem. This module obtains quotes by connecting to the Canada Post server, passing details about the package, and receiving a quote from Canada Post in response. There's no other way to get information from Canada Post except by making an outgoing web request. That whole thing about purchasing a dedicated IP is bogus - it's not needed for any technical reasons. Shared hosts / shared IPs can do this without a problem. It must be a business policy for your web host, rather than a technical limitation.

<tr>.
 
Joined: 07/25/2008
Juice: 24

Yeah they said shared IP's cannot access some ports because it creates security loopholes an can compromise the security and what not.

 
Joined: 01/11/2008
Juice: 315

Do you already have a dedicated SSL certificate for your account/site? If so you're already on a dedicated IP other wise there is no serious reason why they would need to charge you for a dedicated IP just to open a port. How much are they asking for the IP?

 
Joined: 07/25/2008
Juice: 24

$2.50 per month.

I did it, yet its STILL not working, I'll try talking with their customer support.

 
Joined: 07/25/2008
Juice: 24

I have tried this command and it seems successful. I used the windows program called Putty and got this response:

--08:52:44-- http://sellonline.canadapost.ca/
=> `index.html'
Resolving sellonline.canadapost.ca... 66.110.6.131
Connecting to sellonline.canadapost.ca|66.110.6.131|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,650 (1.6K) [text/html]

100%[====================================>] 1,650 --.--K/s

08:52:45 (80.12 MB/s) - `index.html' saved [1650/1650]

Any idea what to try next?

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

You have to run that command from your web host, not your personal computer. The object is to try to see if an application running on your web host can connect to the Canada Post server.

<tr>.
 
Joined: 07/25/2008
Juice: 24

Yes, I got my webhost to run the command, that was their reply.

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

I'm finding it really hard to help you when you give incomplete and inconsistent answers, and don't provide any background information. Your site runs on Unix, yet you say you ran the command with Putty, a Windows program. If you simply used Putty to telnet to your web server then ran the wget command from your web server, why mention Putty at all?

You don't say anything about how you've set up the shipping, what you did with Workflow-ng, what version of Drupal, Ubercart and uc_canadapost (& Workflow-ng) you're using, why you know your CPCID is correct, etc. You don't say anything about how you've set up your Canada Post SellOnline account. It's clear to me that the problem is a configuration problem on your side, but you don't give me any of the information I need to help you, so all I can do is guess at things. If you uncommented the lines like I asked and sent me the output I could tell whether you forgot to set some of your configuration options, or whether your CPC ID is valid, or whether you've even selected any valid Canada Post services for your product types. There's a lot of information about debugging shipping quotes here in these forums. Right now I'm just blindly guessing what's wrong on your end.

<tr>.
 
Joined: 07/25/2008
Juice: 24

I did uncomment the 2 lines, but nothing showed up, tell me if this is the right line:

//if (user_access('configure quotes') && variable_get('uc_quote_display_debug', FALSE)) {
// not quite right - need to get response object before JSimpleXML ...

Its Drupal 5.2, Ubercart 1.0

latest version of uc_canadapost

I'm not sure which version of Workflow but I'll check for a new one. I also noticed theres a new Ubercart version so I'll upgrade.

I know my CPC ID is correct because I have a VentureOne card from Canada Post, and I put that number into my Shipping Profile on the Sell Online site, and I put the same number in on the module

I now noticed theres a new drupal, 5.9, so I'll try upgrading to that also.

EDIT:

Now I've updated everything, still no luck, in my Canada Post client info thing, I have for general info:

my legal company name, website, email, postal code, my CPC #, my distribution agreement number is #0, turnaround time is 12 hours, and the sell online status is Live/En Production

for my shipping services I have everything enabled. and the calculated rate for everything is Small Business Rate

for the boxes I have the default Purolator box, and a Small Package which is 38.1 x 38.1 x 7.6

the handling fees are set to flatrate 3 dollars

in Ubercart, for the Canada Post Settings, the CPC ID is the same CPC # in my Canada Post profile, the interface URL is sellonline.canadapost.ca:30000, all services are checked, markup type is addition, and shipping rate markup is 3, turn around 24 hours, delivery date format is estimated delivery: Wednesday, July 30, 2008 and the shipping from postal code is the same as the one in my Canada Post profile.

And also, since I'm in desperate need, if you think it'll help you find whats wrong, I'm willing to give you my Canada Post user and pass and create you an administrator account on the site.

 
Joined: 07/25/2008
Juice: 24

Please tell me if the lines I uncommented were the right ones..

//if (user_access('configure quotes') && variable_get('uc_quote_display_debug', FALSE)) {
// not quite right - need to get response object before JSimpleXML ...

 
Joined: 06/17/2008
Juice: 53

What're the chances of some nice person updating this to run with the v6 ubercart?

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

Ubercart for D6 doesn't even have an alpha release yet - it is still a work in progress. It makes no sense for me to update this module until Ubercart D6 is ready for testing.

<tr>.
 
Joined: 08/28/2008
Juice: 2

Hello,

I've got a couple of problems with the Canada Post module in that:

1) The user is only requested to provide their postal code, and not country when estimating shipping cost.
2) When they do enter their postal code, they get the standard error message of:

"There were problems getting a shipping quote. Please verify the delivery and product information and try again.
If this does not resolve the issue, please call in to complete your order."

What I have done is:

1) Installed and configured this module for shipping quotes with the "Ubercart Deluxe Installation".
2) Enabled port 30000 (that is thirty thousand) on my server (am using Hostgator).
3) I tried this with the CPC_DEMO_XML ID, as well as an illegal ID. When I used the illegal ID, I saw in the logs:

Merchant CPC Id not found on server.

That verified we were communicating with Canada Post. I don't get any log entries if we use CPC_DEMO_XML and valid postal codes.

5) I made sure I had a product to chose from, that it was in my shopping cart, and that the product had a weight of 5 grams.
6) I'd also enabled several Canada Post shipping methods, such as Canada Post Xpresspost, Air US, Xpresspost US.
7) I enabled logging errors to the watchdog and debug information to the administrator.
Cool When I entered a postal code of 999 (remember, there was no place to enter the country on the shipping estimation form, only a postal code), I saw in the logs:

(Note: this may not show up properly)

Shipping failed. Request was: <?xml version="1.0" ?>encpc_demo_xml2429111111 itemsCA999, response was <?xml version="1.0" ?> ]> -3001 Destination Postal Code/State Name/ Country is illegal. 2103102

9) In country settings, I have enabled both Canada and the US.

Any idea of what I may be doing wrong or is there other information you'd like?

 
TR
TR's picture
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220
atuline wrote:

I've got a couple of problems with the Canada Post module in that:

1) The user is only requested to provide their postal code, and not country when estimating shipping cost.
2) When they do enter their postal code, they get the standard error message of:

It sounds like you're referring to the optional "Estimated shipping cost" field on the cart page. uc_quote is the module that handles this field, not uc_canadapost. When the button is pressed, uc_canadapost is passed the postal code and the store's default country (set at admin/store/settings/store/edit). If you enter a Canadian postal code, and your store's address is set to Canada, this will work, but if you enter a US postal code it won't. Nothing else uc_canadapost can really do here, since the customer's country information isn't passed in.

Note this is only a problem if you're using Canada Post to ship worldwide - if you are just shipping within Canada you'll never see an error.

As a workaround, you can turn off that estimate calculation at admin/store/settings/cart/edit/panes. Your customers will still see the calculated shipping cost on the cart/checkout page, before they complete the purchase. The shipping calculation on cart/checkout will always work because all the address information is available at that point, not just the postal code.

The place for a proper fix is in uc_quote, to request the country in addition to the postal code.

<tr>.
 
Joined: 09/17/2008
Juice: 2

Hi there, I'm getting this error in my drupal/ubercart store. I'm logged in as a store admin and am trying to ship an order with Canada Post:
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, '' was given in /home/sitename/public_html/includes/form.inc on line 218.

Any ideas?