Situation:
Store has default address set to Canada, so when a new user registers, the "Country" field comes up as Canada by default.

Problem:
When registering as a user in the US, I set the Country field to United States and set the Zone field to Washington. However, upon submitting the form, validation fails saying Zone is not valid. The Country field was accepted, and now reads United States, but the choice of Zones (in red, because setting the Zone failed) shows the provinces of Canada instead of States.

Workaround:
At this point, if I leave the Country = United States and select Zone = British Columbia I can re-submit the form successfully; it validates properly and registers the user account. Afterward, I go to user/#/addresses and change the zone to Washington.

Not sure if the problem is in your code or (more likely) the UC form you're using.

Comments

freixas’s picture

Assigned: Unassigned » freixas
freixas’s picture

You know, early on (before RC1), someone complained about something similar. Since I hadn't yet created a Drupal project for this, I don't have any change logs that I can use to remember what that was about or how I fixed it. I vaguely recall that I was failing to save the country information in the database.

During the course of reaching V1.0, I may have made changes that re-introduced the problem.

Don't know if you are a programmer, but if you are and could try to figure out where the problem occurs, it would be a great help. The uc_addresses_get_address_form_submit() is where I hook in to grab the data entered during registration (or various other places). If the user is registering, the $view value is 'new' and _uc_addresses_db_add_address() is called.

Using var_dump($addresses) at key spots might help track down the problem.

I'll try to replicate and fix as time permits.

migueljds’s picture

I found the problem.

In the uc_addresses_address_pane.inc

find $_POST['panes']['address']['country']
and replace with $_POST['country']

tr’s picture

Nice. That did fix the exact problem I described above. That value has to be changed in four places in the .inc

There's a similar problem however that this doesn't fix: On the admin/store/orders/create page, the admin can create an order, select the customer, then choose one of the customer's pre-defined addresses to autofill the billing and shipping fields. The Country field gets populated properly, but if the customer's country is different from the store default country, the Zone field doesn't show the correct zones.

freixas’s picture

I don't believe the uc_addresses code has anything to do with the uc_orders addresses.

The uc_order address system was built first and is part of core. It only finds addresses for customers who have placed orders. The uc_addresses module started out by copying portions of the uc_orders code and modifying it. I came along and made a ton of changes to the work that had been started.

To make sure nothing broke, and because uc_orders is part of Ubercart core, the linkage between the two systems is as minimal as possible. Since the uc_addresses started as a copy of uc_orders, it is possible that the same bug with the $POST variables will appear there. I suspect you'll find a uc_orders_addresses_pane.inc in the uc_orders module.

tr’s picture

Status: Active » Fixed

Thanks - that was enough information to get me going on the right track without having to slog through too much code.

I found the bug on the create order page, and you're right it has nothing to do with your code. For reference, I solved it by changing one line in uc_order.js:
Original: uc_update_zone_select('#edit-' + type + '-country', address['zone']);
Fixed: uc_update_zone_select('edit-' + type + '-country', address['zone']);

The jQuery selector wasn't getting passed properly, so the zone select box never got updated when the country was changed. I've posted a bug against uc_order for this (http://drupal.org/node/289126).

I'm marking this issue closed!

freixas’s picture

Thanks for your investigation! I have a question:

Comment #3 says that there's a bug in the uc_addresses_address_pane.inc file (multiple instances) and recommends using $POST['country']. Are you saying that the fix in uc_order.js also fixes your original problem without requiring any changes to uc_addresses_address_pane.inc?

tr’s picture

Status: Fixed » Reviewed & tested by the community

No. They are two separate issues and require two separate fixes. I guess I marked this thread as fixed prematurely, since you hadn't made the changes to your code yet. Moving it back to open - I'll let you close it after you've made the fix.

The fix that migueljds posted in #3 still needs to be applied to uc_addresses_address_pane.inc - there are four lines of code that contain $_POST['panes']['address']['country'] that need to be changed to $_POST['country'].

The bug fix I reported for uc_order.js fixes a different problem unrelated to your code, even though to me it initially appeared related.

freixas’s picture

Status: Reviewed & tested by the community » Fixed

Changed checked into CVS. Please wait for a dev build dated 2008-aug-1 or later. Thanks for all your work on this problem.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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