I'm working with a few clients who sell products worldwide, but where the majority of their customers reside in Ireland or the UK. They've requested the ability to "promote" these two countries to the top of the list.
The attached patch adds in a textarea in the addressfield widget settings form where they can enter in a list of country codes (one per line) in the preferred order of their choice. These countries get automatically bumped to the top of the country drop-down list.
The only addition I'd like to add is a '----' type divider between the promoted countries and the rest of them. However, when I did that I got the following error when the user selected the '----' option and tried to continue to the review step of checkout:
EntityMetadataWrapperException: Unable to get the data property type as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 442 of entity/includes/entity.wrapper.inc).
This isn't the same as the -none- option discussion on-going at #968112: Allow addressfield to be optional as I do want them to enter a country - I just want them to get a missing required field error when they select the empty value in the drop-down. However, perhaps that's a separate discussion, but would be a nice enhancement to the patch.
Comment | File | Size | Author |
---|---|---|---|
#6 | addressfield_preferred_countries-1816030-6.patch | 2.82 KB | ponies |
addressfield_preferred_countries.patch | 2.68 KB | stella |
Comments
Comment #1
mengi CreditAttribution: mengi commentedPatch works for me. Using 7.x-1.0-beta5.
However, at first when I try to edit the address field in Billing Information I get 100+ instances of the following type of errors (it seems to be an error per country code);
Notice: Undefined index: AF in addressfield_sort_countries() (line 883 of ../sites/all/modules/contrib/addressfield/addressfield.module).
Notice: Undefined index: AX in addressfield_sort_countries() (line 883 of ../sites/all/modules/contrib/addressfield/addressfield.module).
Then I put in a country code into the 'Preferred countries' text box click save and that big list of errors disappears and the country I choose is now on the top of the list. So it works except for the errors that appear when nothing is entered into the preferred countries text box.
Comment #2
bojanz CreditAttribution: bojanz commentedAccording to #1.
Comment #3
tchopshop CreditAttribution: tchopshop commentedHow do I add a divider line to the list below preferred countries?
Nothing I'm putting in is working. Or is this not implemented?
I would also like to be able to sort them, rather than having them re-ordered alphabetically.
Ideally I'd love to be able to have list appear in sections by continent with headers!
Comment #4
Dr.Osd CreditAttribution: Dr.Osd commentedCan't apply this patch for latest dev or latest stable release..
Comment #5
tchopshop CreditAttribution: tchopshop commentedI had to patch it manually.
Comment #6
poniesRerolled against 7.x-1.x ( fc5ef89e79786b656125820d6adf78d993108db7).