When a customer has previous orders, but no addresses in the address book, selecting an address will fail. When repeating the attempt to select an address, Drupal will display the famous "illegal choice" error.
I have been working a long time on this to fix it. Originally, a fix for this issue was included in patches from the issue #1424038: Order administration: "copy address" feature starting from comment #26. Although the two issues are related, it are two different issues.
To fix this, I'll introduce a new form element called "uc_addresses_address_select". This form element will be used especially for selecting addresses. The big difference with the standard select element is that you can specify which address in the form must be updated when an address is selected and thus this will reduce the amount of the code needed when implementing address selectors in your own module. It works still a bit geeky, though: you have the specify where in the form array the address fields can be found and where in the form state's "input" the address values can be found when the form is submitted.
A fix will be committed shortly. After that, a new documentation page will be added to the The developer's guide to Ubercart Addresses that will explain the new form element.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | uc_addresses-select-address-1701324-10.patch | 5.63 KB | megachriz |
| #8 | uc_addresses-select-address-1701324-8.patch | 5.63 KB | megachriz |
Comments
Comment #1
megachrizA fix for this issue has been committed. I'll leave this issue open until the documentation page is added.
Comment #2
megachrizDocumentation about the new form element has been published:
The uc_addresses_address_select form element
Comment #4
mandreato commentedThis issue seems to apply also to 6.x-2.0-alpha1+12-dev (2012-Ago-03).
I'm trying to install uc_addresses + uc_extra_fields_pane on a website where there are already users with orders.
I simply activate both modules and add an extra mandatory field (fiscal code) which was not present in the past.
If I simulate a checkout with a new user, filling in the address fields on the registration form, all is OK.
But if I simulate a checkout with an old user, the cart/checkout page allows me to select the old orders' address (showing it on the address book list) and filling in the fiscal code. When the review button is pressed the invalid choice error is shown.
Then I have to leave the address book list empty ("select one") and the address fields filled to proceed.
Now the address is present on the address book and the future orders will go just fine.
It would be great if, during the installation phase, the address book is compiled for every users with their last order informations.
Comment #5
megachrizThis looks like the feature request reported in #932102: Migrate uc_orders addresses to uc_addresses. If I'm right, then we'd better continue there with discussing this feature request.
For the other issue, I'll check this out. To be sure, you followed these steps:
1. Logged in as a customer with previous orders, but no addresses in the address book.
2. Went to checkout, select an address + filling in the extra field. What kind of type is this extra field? A text field, a select field or something else?
3. Hit the review button, illegal choice is shown. Was the error on the address selector or on your extra field?
Comment #6
mandreato commentedThose steps are exactly what I've done.
The extra field is:
- label: Codice fiscale / P.IVA
- field name: ucxf_cf_piva
- description: Indicare il codice fiscale (privati) oppure la partita IVA (aziende). Questa informazione serve per generare la fattura che accompagna il materiale.
- shown on both Delivery and Billing panes
- field type: Textfield
- required: yes
- display options: all checked
Now I'm unable to replicate the problem because I've filled an address to every old user with orders (I'll post the query I used into thread #932102: Migrate uc_orders addresses to uc_addresses)... but, if I remember correctly, the error was on address selector (not on the extra field).
I'm on the following environment:
- Drupal 6.26
- Ubercart 6.x-2.9
- Ubercart 2 VAT support 6.x-1.2
- Ubercart Addresses 6.x-2.0-alpha1+12-dev (2012-Ago-03)
- Ubercart Checkout Tweaks 6.x-1.x-dev (2011-Feb-25)
- Ubercart Discount Coupons 6.x-1.7
- Ubercart Out of stock Notification 6.x-1.7
- UC Tracking Links 6.x-1.0
Comment #7
megachrizI've been able to reproduce the problem! Now I need to figure out how to fix it. The problem only occurs when following these steps:
1. Log in as a customer with previous orders, but no addresses in the address book.
2. Go to checkout, select one of the available addresses. Omit filling in one of the required fields (or do something else that will result into form errors).
3. Hit the review button. A form error is shown about a required field not being filled in.
4. Fix the form errors, hit the review button again.
5. The "illegal choice" error is shown on the address selector.
Note: when hitting the review button again after this error is shown, the customer goes to the checkout review page with no further errors.
Comment #8
megachrizThis patch fixes the issue by not including the address ID in the keys of the options in the address selector. When the checkout page is reloaded after a form error happens, the selectable addresses sometimes get different (temporary) address ID's. By not including the address ID's, the option keys will stay the same and thus no "illegal choice" error will occur.
The patch also adds an automated test that tests the case noted in #7. The tests has been added to the 'Cart and checkout' test case.
Comment #10
megachrizI manually removed a line from the previous patch. Apparently, that didn't work. I should have removed that line in the original source file and create a new patch.
Here is a new patch.
Comment #11
mandreato commentedI'd like to test #10 but all my customers have now an address, so I cannot replicate the testcase #7.
Is there a way to delete an address from a user (using GUI, not deletes on db) ?
I've tried user/.../addresses/.../edit, but it just let you to update, not delete... (#963560: isn't possible delete address)
Comment #12
megachriz@mandreato
No, there is no way to delete default addresses using the GUI (and also not via the API). However, you can replicate the case by adding a new user as admin (without adding an address), and create an order for this user.
Actually, I posted the patch here so it would run through all automated tests. I didn't have the time to do that on my local machine yesterday (executing all tests takes about 20 - 30 minutes). Since it passes all tests, I think it's ready (or near ready) to commit it. The only thing left to do for me now, is checking if I'm fine with this fix if I compare it with the fix done in the 7.x-1.x version.
Comment #13
mandreato commented@MegaChriz on admin/user/user/create there are the mandatory address fields, so I can't create an user without address.
BTW, I you think that patch is ready... ;-)
Comment #14
megachriz@mandreato
On the address settings page (admin/store/settings/addresses/edit), you can disable the option "Require admins to enter an address upon user creation" (which is enabled by default) and then admins don't have to enter an address when creating a new user.
Comment #15
megachrizI've committed the patch posted in #10. This includes the fix for the issue + an automated test that follows the steps noted in #7. I've ported the automated test also to the 7.x-1.x version: see 7.x-1.x commit.