I tested this module on a site which is using a dataset of countries and zones that are not Ubercart stock, but I'm sure that some of the same problems would carry over even with a stock set of data. I found a total of 652 provinces which could not be matched throughout the entire dataset (of about 4000 provinces in the cart set) and 3 countries which didn't even have Location datafiles (and would therefore throw PHP errors by trying to include nonexistant files).
Among the areas that failed were all British addresses (Location expects the reserved UK code, while my dataset has the official GB code), and armed forces addresses (such as US zone AP - Armed Forces Pacific). This makes sense actually, because it's perfectly reasonable to want to allow military personnel to purchase from your online store, but not reasonable to expect to geocode and show Google maps and driving directions for their locations. That is, the modules serve different purposes, and we can't expect the data to always match 100%. Of course, there would also be the issue of adding revised or new .inc's to location or .cif's to Ubercart - we can't expect these datasets to always be in synch, even when using stock data.
I would suggest some additional checking in, for instance _uc_location_order_to_location() to validate that the country and province being pulled from the Ubercart data actually match something in the Location module's dataset (and vice-versa in _uc_location_to_uc_address()) before saving or presenting the data. If data from one dataset is invalid in the other, the best course is probably just to log the mismatch and abort the translation. As long as this module is just being used as a convenience for users, having to enter another address is better than having errors or bad data.
In case it's being used for something that requires that the translation happen successfully, it may be useful to have some sort of hook that is called if a mismatch is detected, so that people can create an add-on translation table module (especially useful if you have custom datasets) or some other handler to deal with special cases (ex: if nothing else works, use code 'xx') depending upon their own datasets, use cases, and business needs.
Comments
Comment #1
mearnest commentedYour ideas sound good. We have looked into trying to integrate the Location and Ubercart data sets, but since Ubercart uses a table with zone ids as the primary key and Location uses associative arrays keyed by province codes, it seems like code modification in one or both modules would be necessary.
For example, if you save a zone / province that exists in Ubercart but not Location, even if you bypass the location_save_locations and write straight to the table, then when the user profile is edited and saved, it will cause a validation error on the province (or the country in cases where the country code differs).
And if you try to save a province into Ubercart that it doesn't have, then you'd have to add it to the table and assign a zone id. Not to mention the cases where the zones exist in both sets but have different codes. And then if we wanted to allow for other data sets, that just makes the issue even trickier (you can't just hard code translations for differing country codes such as you can when you know it's just gb = uk).
Unfortunately, it doesn't seem like a straightforward solution involving mapping functions is possible. Certainly not without submitting patches to Ubercart and Location.
So, would you be interested in providing a patch for uc_location along the lines of what you are suggesting?
Comment #2
Anonymous (not verified) commentedHi,
Is there some progress with the management of states/provinces ?
Is the module abandonned ? I'll look thurther inside the module to find a solution, so if some work as already been done, it would help me.
Comment #3
mearnest commentedThe module is not abandoned, but it hasn't been worked on for a while. Other things came up for both of us. The goal is still to find a solution.
Comment #4
mearnest commentedA solution such as the one mentioned in the OP needs to be added at some point going forward with the 7 release.