I would like to request a Canadian patch. I will look into it and see if I can figure one out by some miracle later; but figured I'd start the conversation. I have submitted a sample structure and marked mandatory fields with a '*'.

*Street Address: (Text)
Unit/Suite: (Text)
P.O. Box / Rural Route: (Text)
[note: The above three lines could be combined into "*Address Line 1:" and "Address Line 2:"]
*City: (Text)
*Province: (options: AB, BC, MB, NB, NL, NT, NS, NU, ON, PE, QC, SK, YT)
*Postal Code: (i.e. A1A 1A1)
Phone: (Would be nice.... i.e. 555-555-5555)

Comments

Ceb’s picture

Alright, I know nothing about patches. But here's what I've 'tried' to do. Being that Canada is very similar to the US, I modified their files and came up with the following but am definitely missing something because of the errors I'm getting. All is detailed below.

Created an addressfield_form_ca

<?php

/**
* Address handler for Canada.
*/
class AddressFieldForm_ca implements AddressFieldForm {
  public function form($address, $field, $instance, $langcode, $items, $delta, $element) {
    $required = $delta == 0 && $instance['required'];

    $form['thoroughfare'] = array(
      '#title' => t('Address Line 1'),
      '#type' => 'textfield',
      '#required' => $required,
      '#default_value' => $address['thoroughfare'],
    );
    $form['premise'] = array(
      '#title' => t('Address Line 2'),
      '#type' => 'textfield',
      '#default_value' => $address['premise'],
    );
    $form['locality'] = array(
      '#title' => t('City'),
      '#type' => 'textfield',
      '#size' => 30,
      '#required' => $required,
      '#default_value' => $address['locality'],
    );
    $form['administrative_area'] = array(
      '#title' => t('Province'),
      '#type' => 'select',
      '#default_value' => $address['administrative_area'],
      '#required' => $required,
      '#options' => array(
        ''   => t('--'),
        'AB' => t('Alberta'),
        'BC' => t('British Columbia'),
        'MB' => t('Manitoba'),
        'NB' => t('New Brunswick'),
        'NL' => t('Newfoundland'),
        'NT' => t('Northwest Territories'),
        'NS' => t('Nova Scotia'),
        'NU' => t('Nunavut'),
        'QC' => t('Quebec'),
        'SK' => t('Saskatchewan'),
        'YT' => t('Yukon Territory'),
      ),
    );
    $form['postal_code'] = array(
      '#title' => t('Postal Code'),
      '#type' => 'textfield',
      '#size' => 10,
      '#required' => $required,
      '#default_value' => $address['postal_code'],
    );
    return $form;
  }
}

Then I created an addressfield-formatter--CA:

<?php

/**
 * @file
 * TODO: Describe what this template is here for.
 */
?>

<div class="xnal address-ca">
  <div class="street-address">
    <?php
   
print implode('<br />', array_filter(array(
      !empty(
$address['name_line']) ? $address['name_line'] : $address['first_name'] . ' ' . $address['last_name'],
     
$address['organisation_name'],
     
$address['thoroughfare'],
     
$address['premise'],
     
$address['sub_premise'],
     
$address['dependent_locality'],
    )));
   
?>

  </div>
  <div>
    <span class="locality"><?php print $address['locality'] ?></span>
    <span class="administrative_area"><?php print $address['administrative_area'] ?></span>
    <span class="postal-code"><?php print $address['postal_code'] ?></span>
  </div>
  <div>
    <span class="country"><?php print $address['country_name'] ?></span>
  </div>
</div>

I then modified the addressfield.module to read:

/**
* Default mapping of address forms to countries.
*/
function addressfield_default_mapping() {
  return array(
    'default' => 'AddressFieldForm_default',
    'BR' => 'AddressFieldForm_br',
    'CA' => 'AddressFieldForm_ca',
    'GB' => 'AddressFieldForm_gb',
    'US' => 'AddressFieldForm_us',
    // TODO: complete the mapping.
  );
}

and finally the addressfield.info to have:

files[] = addressfield.module
files[] = includes/addressfield_form.inc
files[] = includes/addressfield_form_default.inc
files[] = includes/addressfield_form_br.inc
files[] = includes/addressfield_form_ca.inc
files[] = includes/addressfield_form_gb.inc
files[] = includes/addressfield_form_us.inc

....
So NOW when I go to the page that would ask the user for their address I get the error:

Fatal error: Class 'AddressFieldForm_ca' not found in /home/umicha03/public_html/sites/all/modules/addressfield/addressfield.module on line 566

and even scarier, if I go to my modules page in admin... I get:

Notice: Undefined index: name_format in addressfield_standard_xnl_form() (line 426 of /home/umicha03/public_html/sites/all/modules/addressfield/addressfield.module).
Notice: Undefined index: name in _update_process_info_list() (line 181 of /home/umicha03/public_html/modules/update/update.compare.inc).
Notice: Undefined index: name in system_sort_modules_by_info_name() (line 909 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_sort_modules_by_info_name() (line 909 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_sort_modules_by_info_name() (line 909 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_sort_modules_by_info_name() (line 909 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_sort_modules_by_info_name() (line 909 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_sort_modules_by_info_name() (line 909 of /home/umicha03/public_html/modules/system/system.admin.inc).
Warning: uasort() [function.uasort]: Array was modified by the user comparison function in system_modules() (line 769 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in _system_modules_build_row() (line 942 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in field_help() (line 338 of /home/umicha03/public_html/modules/field/field.module).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).
Notice: Undefined index: name in system_modules() (line 806 of /home/umicha03/public_html/modules/system/system.admin.inc).

Ceb’s picture

Apparently, what I was missing was an entry into the 'registry' table of the database. It looks like this code and these files should work if somebody from the developer team wants to insert it accordingly with whatever is needed to make it add the database entry.

Ceb’s picture

Personally, I just modified the GB entry into the registry table, as I don't need that one right now.

jcarlson34’s picture

Hi Ceb,

I just copied and pasted your code into the Address Module (with the latest dev version) and it worked fine for me. There are no errors. Did you try clearing the site cache before trying it out?

Ceb’s picture

I don't remember. I messed around a lot... and it got worse before it got better. :) Good to see it's just working. It's nice to be able to contribute.

ourvalley’s picture

Hi Ceb,

I really appreciate it. I just copied and pasted your code as well and it worked great!

Thanks,
Sandy

nate_the_great’s picture

$form['administrative_area'] = array(
'#title' => t('Province'),
'#type' => 'select',
'#default_value' => $address['administrative_area'],
'#required' => $required,
'#options' => array(
'' => t('--'),
'AB' => t('Alberta'),
'BC' => t('British Columbia'),
'MB' => t('Manitoba'),
'NB' => t('New Brunswick'),
'NL' => t('Newfoundland'),
'NT' => t('Northwest Territories'),
'NS' => t('Nova Scotia'),
'NU' => t('Nunavut'),
'ON' => t('Ontario'),
'PE' => t('Prince Edward Island'),
'QC' => t('Quebec'),
'SK' => t('Saskatchewan'),
'YT' => t('Yukon Territory'),
),
);

forgot a few provinces

nicoz’s picture

Status:Active» Reviewed & tested by the community

Just tested and works perfectly. Marking as review and tested, unless someone else has any issues?

nicoz’s picture

Upon further testing, I noticed that the "province" label for the province field does not appear in the checkout. (it does appear in the admin area for creating customer profiles)

jonskulski’s picture

Status:Reviewed & tested by the community» Needs work
StatusFileSize
new3.84 KB

Threw the work done in #1 as a patch. Works for me, does not address #9 however.

sonar_un’s picture

I tested the patch and it works without an issue. I was able to see the Province label as well. I think it can be comitted.

sonar_un’s picture

StatusFileSize
new1.63 KB

I have attached a lastest commit for Canadian Addresses based on the Beta-1 from July 13th. It works on my test machine.

sonar_un’s picture

Version:7.x-1.0-alpha1» 7.x-1.0-beta1
Status:Needs work» Needs review

Updated version info to reflect latest version.

Ceb’s picture

Looking much better. Only problem left is that it reads 'state' and not 'province'.

sonar_un’s picture

Mine switches back and forth from state to province and zip code to postal code ok.

Can we have someone confirm that this works in another environment?

mparker17’s picture

Subscribe

Damien Tournoud’s picture

Status:Needs review» Fixed

In the interest of keeping this moving, I committed that to 7.x-1.x (#032ec93). This type of things will move into the ISO3166-2 handler that I plan on working on next week.

sonar_un’s picture

Thank you very much Damien!

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mvc’s picture

Version:7.x-1.0-beta1» 7.x-1.x-dev
Category:feature» bug
Status:Closed (fixed)» Needs review
StatusFileSize
new555 bytes

there's a small problem with Canadian addresses: the province of Newfoundland's name was officially changed to "Newfoundland and Labrador" in 2001 (see http://en.wikipedia.org/wiki/Newfoundland_and_Labrador).

trivial fix attached.

j0nathan’s picture

Status:Needs review» Reviewed & tested by the community
j0rd’s picture

Title:Canadian Address Fields» Canadian Address Fields with pluggable way to do other countries.

updated title for super ticket.

j0rd’s picture

Issue tags:+pluggable regions

This is a duplicate of
#1829900: [meta] Address Field 2.x needs pluggable administrative areas and an actual API

If you think so to, please close your ticket.

rszrama’s picture

Component:Code» Address formats
Category:bug» task
Status:Reviewed & tested by the community» Closed (fixed)

Yeah, no reason to leave this open. I committed the name fix in #20, re-closing this out.