In the uc_store/countries/canada_124_2.cif file, the Canadian address format is incorrect. Reference: http://www.canadapost.ca/tools/pg/manual/PGaddress-e.asp#1416995

Canada_124_2.cif, starting at the 44th line, should read:

variable_set(
    'uc_address_format_124',
    "!company\r\n".
    "!first_name !last_name\r\n".
    "!street1\r\n".
    "!street2\r\n".
    "!city, !zone_name  !postal_code\r\n".
    "!country_name"
);

Note: there are two spaces between the province (zone_name) and the postal code.

Comments

Anonymous’s picture

Issue summary: View changes
tr’s picture

Priority: Normal » Minor
StatusFileSize
new467 bytes

I'm surprised no one from Canada has mentioned this before - it's always been like that in Ubercart, since the first release 7 years ago.

Minor because this is just the default, you can customize your address format at admin/store/settings/countries/formats
Apparently this is what all Canadians have been doing?

According to your link, the comma should be removed after the city, the zone_code should be used, not the zone_name, and the country should not be specified for addresses within Canada.

I think we can make this change without updating the version - forcing an update will just override any custom format that a site may have set. Patch attached.

tr’s picture

Version: 7.x-3.6 » 7.x-3.x-dev

Changing version for the testbot.

longwave’s picture

I agree with not changing the country version at this stage as this is only a format change.

My only question is does the double space get output correctly? HTML output will generally collapse multiple spaces into one, so does this actually work as expected in all the places we output addresses? And if not, how would we handle that?

Anonymous’s picture

  to enforce the second space? That's how I've always done it in my HTML.

If the Ubercart addressing format is meant to follow that country's official postal conventions as closely as possible, then the patch is fine. The most important thing is to get the city, province and postal code ordering correct (and, ideally, the double space between the province and postal code). Canadians are pretty firm about that.However, you'll find a lot of variation in punctuation and abbreviations.

A few observations about Canadian addressing conventions (or: where and why Canadians deviate from the official postal guide):

  • Canada and the US have very similar addressing conventions. This isn't a co-incidence. An overwhelming amount of our international mail either goes to or comes from the United States. It appears that Ubercart uses the state code in the US postal template (and also the comma, which may or may not be correct) instead of the state name. Accordingly, Ubercart's Canadian postal template should follow its American template, within reason.
  • Canada Post advises using the provincial/territorial abbreviation to optimise processing by the post office's automated sorting machines. However, in 'non postal' use, the province or territory is often written out (example: http://gg.ca/document.aspx?id=325). I personally find using the provincial abbreviation terse when I'm not addressing an envelope and prefer to use the full province name.
  • I think dropping the 'Oxford comma' is a recent postal change (which may or may not have followed a change in the US addressing scheme). I remember Canada Post guides into the mid 2000s specifically instructing people to use it. The Parliament of Canada website shows both the comma and the full province name: http://www.parl.gc.ca/ContactUs.aspx?Language=E . Likewise, the City of Toronto uses the provincial abbreviation and a comma: http://www.toronto.ca/city_directory/ . This shows that even the government doesn't follow Canada Post's guidance.
  • 7 of Canada's 13 provinces and territories need at least one space in their names. Using the full province name without a breaking comma can lead to a bit of an eyeful: "St. John's, Newfoundland and Labrador" v. "St. John's Newfoundland and Labrador". (The latter could also the the sign of a ma and pa pet shop).

@TR: Being the chill Canadians that we are, eh, I guess the incorrect address format never really bothered us. :-P

Anonymous’s picture

Title: canada_124_2.cif has an incorrect address fromat » canada_124_2.cif has an incorrect address format

Ugh. I can spell… sometimes

longwave’s picture

  might be problematic in some cases, such as where the address is included in a plaintext email. Would need some testing, I guess; maybe we should just commit this patch as-is (please RTBC TR's patch if it works for you!) and follow that up later.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

#WorksForMe

longwave’s picture

Version: 7.x-3.x-dev » 8.x-4.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed #2. Needs porting to 8.x-4.x, and perhaps we should do something about the double space issue, if that is actually a problem.

Anonymous’s picture

Fixing the double space issue will make the patch pretty much 100% correct. Granted, Canadians will live fine without it. Who knows, maybe Canada Post will change the standard to a single space before you figure out how to do it. Still, if it can be done, it should be done for correctness.

Is it possible to insert a non-breaking space character through a Unicode escape or possibly some other PHP character escape.

longwave’s picture

Status: Patch (to be ported) » Active

Cherry picked to 8.x-4.x. Back to active to figure out the double space issue at some future time.

  • longwave committed 6f250a0 on 8.x-4.x authored by TR
    Issue #2215825: Fixed Canadian address format.
    
Anonymous’s picture

Good man, longwave. Thank you for your hard work :-)

tr’s picture

Title: canada_124_2.cif has an incorrect address format » Support both HTML and plain text output for Address formats
Category: Bug report » Feature request
Status: Active » Needs review
StatusFileSize
new1.12 KB

Renaming this issue and changing it to a feature request.

What we have left to do here is to figure out how to support addresses being displayed in an HTML document (on a website or in an HTML e-mail) and also support addresses in plain text (in a plain text e-mail or for export to a label printer, fulfillment house, or the like).

Right now, Address objects have a __toString() function which returns text including <br> tags. So because we're already returning HTML here we might as well go ahead and also replace the spaces with &nbsp;. That will solve the HTML formatting issues.

But we also need another function to return plain text. Semantically, __toString() probably should be returning the plain text version, not the HTML version like it does now. Then we can add a toHtmlString() function for when we need HTML.

Then we have to look through the Ubercart code and use the correct functions in the correct places because right now we use PHP's implicit type conversion to output addresses, which calls __toString() when we implicitly cast an Address object to a string. All those places where we actually need HTML should have an explicit toHtmlString() call instead. But since this is an implicit cast, there's no easy way to grep for this usage.

Anyway, here's a patch for the &nbsp; issue, which is a first step.

Status: Needs review » Needs work

The last submitted patch, 14: 2215825-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.89 KB

I forgot to change the test - because we're now using &nbsp; instead of spaces, we have to alter the test to expect that when we test addresses.

Here's a new patch with an updated test.

Status: Needs review » Needs work

The last submitted patch, 16: 2215825-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.9 KB

Whoops, missed a spot.

Status: Needs review » Needs work

The last submitted patch, 18: 2215825-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.91 KB

Sigh. Missed another spot.

Status: Needs review » Needs work

The last submitted patch, 20: 2215825-20.patch, failed testing. View results

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.9 KB

Re-rolled #20 against HEAD.