verbb / postie

A Craft Commerce shipping calculator plugin.
Other
12 stars 18 forks source link

Canada Post cannot retrieve rates for destinations outside of Canada #84

Closed amphibian closed 2 years ago

amphibian commented 2 years ago

When using the Canada Post integration, rates cannot be retrieved for destinations outside of Canada. This is because Postie will always send the destination to Canada Post's API using the <domestic> node, as opposed to the <united-states> or <international> nodes as needed. Thus a US destination returns an error from Canada Post such as:

element postal-code is not a valid instance of type PostalCodeType

(This is because it's actually a US zip code.)

Fix

In the Canada Post provider file, replace the contents of the <destination> node with something like this:

if($order->shippingAddress->countryIso == 'CA') {
    $payload .= '<domestic>
        <postal-code>' . $orderZipCode . '</postal-code>
    </domestic>';
} elseif($order->shippingAddress->countryIso == 'US') {
    $payload .= '<united-states>
        <zip-code>' . $orderZipCode . '</zip-code>
    </united-states>';
} else {
    $payload .= '<international>
        <country-code>' . $order->shippingAddress->countryIso . '</country-code>
    </international>';
}

Additional info

engram-design commented 2 years ago

Completely overlooked this for international shipments at the time, thanks for that. I've just added/fixed this for the next version. To get the fix early, change your verbb/postie requirement in composer.json to:

"require": {
  "verbb/postie": "dev-craft-3 as 2.4.15",
  "...": "..."
}

Then run composer update.

amphibian commented 2 years ago

Thanks Josh, appreciated!

engram-design commented 2 years ago

Released in 2.4.16