The problem
When editing orders, it is possible to select addresses from the address book (as requested in #396342: addresses in admin orders interface). Currently there are some issues with the zone field. While selecting an address from the address book is possible, the zone value is not correctly updated when the country from the selected address is different from the country currently active on the form. Also, when copying over an address from one address pane to the other address pane, the zone value is not correctly taken over when the currently active countries in the two address panes differ.
The proposed solution
While checkout in Ubercart has been improved on selecting and copying addresses, the order administration uses the same javascript as in Ubercart 6.x-2.x. This makes the order administration less flexible, as I have plans to add support for extra address fields in the future. If the order administration operates the way it does now, the support of extra address fields will be limited to only a few address fields.
The delivery and billing address form on the checkout page makes use of the #ajax property, with which a Drupal form can be updated by a javascript event. The nice thing about it, is that Drupal updates the form by using the same form API, so issues like "An illegal choice has been detected" can be avoided. The order administration form doesn't use this strategy: it just replaces form elements with javascript without going through the Drupal Form API.
I'd like to have the order administration form work in a similar way as the checkout form.
Want to help?
This issue is here for volunteers to be picked up. Assign yourself to the issue first if you want to work on this one. This issue needs to be fixed prior to the release of 7.x-1.0-alpha1.
Comment | File | Size | Author |
---|---|---|---|
#39 | uc-addresses-order-admin-feature-1424038-39.patch | 9.47 KB | MegaChriz |
#37 | uc-addresses-order-admin-feature-1424038-37.patch | 7.64 KB | MegaChriz |
#37 | 1424038-rules-ui-button.png | 2.72 KB | MegaChriz |
#37 | 1424038-order-edit-37.png | 25.46 KB | MegaChriz |
#33 | uc-addresses-order-admin-feature-1424038-33.patch | 8.41 KB | MegaChriz |
Comments
Comment #1
Michael-IDA CreditAttribution: Michael-IDA commentedMegaChriz,
As you said you don't have the time, we'll sponsor this to be fixed by another developer, but, can you bullet point out exactly what you want done?
My first stab at stripping out deliverables:
Please add system paths for clarity.
Best,
Sam
Comment #2
MegaChriz CreditAttribution: MegaChriz commentedThe path the address form is located is at
admin/store/orders/[order_id]/edit
where [order_id] is the ID of the order.
The file uc_addresses.ubercart.inc currently includes the code for generating the delivery/billing checkout panes and the ship_to/bill_to order panes. Ubercart Addresses has overridden the order panes by implementing
hook_uc_order_pane_alter()
. This hook implementation can be found in the uc_addresses.module file.The address book select field is currently loaded with javascript as a separate form, thus it doesn't appear in the order pane callback
uc_addresses_order_pane_address()
. The original address book formuc_order_address_book_form()
is defined in uc_order/uc_order.admin.inc. This form is altered by Ubercart Addresses inuc_addresses_form_uc_order_address_book_form_alter()
in uc_addresses.module. Ubercart Addresses replaces the selectable addresses (that come from previous orders) by addresses from the address book.The address book form should probably become part of the order pane callback
uc_addresses_order_pane_address()
just as is the case with the checkout pane callbackuc_addresses_checkout_pane_address()
. Parts of the form should be updated by the form API by using the#ajax
property on the address book select field and the copy address checkbox.I hope this information helps. If there are still some things unclear, feel free to ask.
Comment #3
Michael-IDA CreditAttribution: Michael-IDA commentedEdit (3/31/12): Bonus has been canceled by client :(
$150 Bonus for fixing uc_addresses, Order admin
http://groups.drupal.org/node/207923
http://drupal.org/node/1430198
Comment #4
Jaypan CreditAttribution: Jaypan commentedI worked on this and tied it into the #ajax system, and while the #ajax properly fires, and I can see that the new address is properly loaded, something in the definition for the element type of 'uc_addresses_address' refuses to load any definition other than the one originally supplied with the form, effectively killing any possible #ajax functionality.
Edit: to add to that, the default address is set in uc_addresses.ubercart.inc in uc_addresses_order_pane_address(). It is set here:
No matter what value is set for $address in this form, it always shows the original form definition. For example, I can put:
The above code should load the default address on page load, and on #ajax submission, will load the address provided in $form_state['values']['ajax_submitted_address']. I have confirmed that in the #ajax submission, the address is properly loaded, but when form is regenerated and sent back to the page to be inserted, it always shows the original address, no matter what address was selected, and even though I have confirmed that the proper address has been loaded.
So I think it's a bug in the 'uc_addresses_address' form element, but I've reached my time limit on this and will be leaving it at this. But maybe this can help someone else if they try to fix this problem.
Comment #5
MegaChriz CreditAttribution: MegaChriz commentedBut on the checkout page (with uc_quote module disabled, see #1421720: [$150 Bounty] Delivery information does not display in checkout) it's working with #ajax.
Comment #6
Michael-IDA CreditAttribution: Michael-IDA commentedDeadline has been removed on bonus.
Comment #7
mesch CreditAttribution: mesch commentedI've run into the same issue as Jay M. I can fetch the user's address book and create the panes with any of those addresses, but it does not seem to want to update via ajax. I can't justify digging through more code to fix this further for this bounty amount, and I don't have the available spare time at the moment.
Re: copying one pane to another, what about just disabling one of the panes (ala the checkout form) and doing the order updating (including copying of addresses among types) in the 'edit-process' op?
Re: the existing javascript, it wasn't working on my fresh drupal7/U3 instance.
Comment #8
MegaChriz CreditAttribution: MegaChriz commented@MEsch, can you post (as a patch) what you got so far? I may be able better to track down the issue you ran into better in this case. On the checkout form, applying addresses from the address book works nicely, so I don't understand why yet this doesn't work in other forms.
I suppose you have adjusted
uc_addresses_select_addresses()
a little? This function now operates the "old way" when the context is "order_form", thus with JSON code as the key of each address. It should use address ID's when the address book select field is part of the order form itself.This (uc_addresses.module, ± line 1111)
should be replaced by this:
when implementing this feature as described.
Comment #9
mesch CreditAttribution: mesch commentedPatch attached.
To be honest it was unclear what the best method of obtaining the addresses was. I tried multiple different ways and neither of them solved the issue. I did notice the context issue, and I decided to use "uc_addresses_get_select_addresses" instead. I also tried the "loadAddress" class method directly, as well as Jay M.'s approach. All of them worked in populating the initial form.
I briefly checked out the classes, and there seems to be lots happening there; I wonder if the addresses need to be loaded in a very specific way in order for the uc_addresses_address form element to be updateable.
The patch doesn't deal w/ saving the changes... I stopped at the ajax roadblock.
Comment #10
MegaChriz CreditAttribution: MegaChriz commentedThanks for posting the patch (sorry for my late reaction).
I had assumed that the hint
would have been enough to know the checkout form already does the trick, and with the uc_addresses_address element (which I should document in the developer's guide). At the other hand, I know very little about how it exactly works on checkout. Most of the working mechanism is copied from Ubercart and some Ubercart code is still involved in the process. That fact makes it harder to fix this issue. But because it works at checkout, it should be possible to work elsewhere too.
I'll take a look at your code and see where exactly you "hit the wall".
Comment #11
MegaChriz CreditAttribution: MegaChriz commentedI have take a look at the patch posted in #9 and I see a lot of wrappers in there which make it confusing for me what exactly happens there. There are not that much wrappers at the checkout form. I suppose it is used as attempts to fix the problem.
I have also made an attempt or at least a start to implement this. I took uc_addresses_checkout_pane_address() as an example as that is working completely. At first, I noticed the same issue as Jay Matwichuk and MEsch, that the address never did update. But when I added the following:
things began slowly sort of working. That piece of code made sure the field "select_address" was named "delivery[select_address]" in the form HTML instead of just "select_address", which is harder to track down because we deal with two address forms on one page (delivery and billing). I've also replaced
$uc_type
by$pane
for consistency (that's what the implementation for checkout uses).The attached patch is capable of updating the address form when selecting an address from the dropdown. To concentrate at one piece at a time, I left out the functionality for copying an address from one pane to the other for now. Unfortunately, there are still some things that aren't working:
I think the changes in the patch gets us closer to the solution, but we aren't there yet.
Comment #12
MegaChriz CreditAttribution: MegaChriz commentedI've examined two of the problems noted #11.
The "Nesting level too deep" error
The "Nesting level too deep" error is caused in the uc_order module: it tries to compare the uc_addresses array from two order objects. In the $order->uc_addresses array live two UcAddressesAddress objects and because an UcAddressesAddress object is connected with an UcAddressesAddressBook object, there is some cross referrencing which is causing the "Nesting level too deep" error.
Zone field issues
For the issues with the zone field, I've found out that when the address form is updated via ajax, the address form element is processed twice (I've tested this with a single address form). This causes the construction of a new address object with an other ID, while it would work for us at best if the form API just takes the address object from the (form) cache. The address ID is used in the zone wrapper element to allow a form to have multiple address forms at a single page. If an address gets a new ID everytime a form is updated, well, then you ask for trouble. I seem to have worked around this problem in all places an address form is used and we can do this for the order form too, but it would be better to deal with the same address object everytime when an address form is updated via ajax.
We could use a developer here who has a deep understanding of the Form API and especially knows what exactly the Form API does when forms are processed/constructed via ajax using the #ajax property.
Comment #13
MegaChriz CreditAttribution: MegaChriz commentedI've opened the issue #1471500: Issues with the uc_addresses_address element to work on the zone field issues reported in #12. This is probably the same issue as Jay Matwichuk encountered in #4.
The "Nesting level too deep" error can be still handled here.
Comment #14
Michael-IDA CreditAttribution: Michael-IDA commentedBoth of these are after turning off Shipping quotes (and dependencies):
In /admin/store/orders/33/edit, I get this after changing the Bill to:, Country and State/Province fields and clicking Submit Changes:
and the address isn't updated.
Possibly related? I get this at /admin/store/orders/view?order_id=&order_status=All&=Apply :
# # #
When turning Shipping Q's dependencies back on, I get this at /admin/modules :
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'fetch_task::sharethis' for key 1: INSERT INTO {cache_update} (cid, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => fetch_task::sharethis [:db_insert_placeholder_1] => 1331317843 ) in _update_create_fetch_task() (line 245 of modules/update/update.fetch.inc).
But it goes away, after clearing cache.
/admin/store/orders/view?order_id=&order_status=All&=Apply still has the same errors.
And if I manually move an order back to "In Checkout" /cart claims I don't have any products in my shopping cart. (huh, nevermind, on an instance that has never had uc_address, this is now happening as well. UC brake something else?)
And that's it for this week, hope you have a great weekend,
Sam
Comment #15
MegaChriz CreditAttribution: MegaChriz commentedI've committed some changes to the 7.x-1.x branch. The patch posted in #11 still applies when using
patch -p1 < uc-addresses-order-form-1424038-11.patch
, but not when usinggit apply uc-addresses-order-form-1424038-11.patch
.@Sam-Inet
The patch isn't finished yet. It's intended to be used as a starting point for fixing this issue. Before we can seriously continue with this one, #1471500: Issues with the uc_addresses_address element need to be reviewed and fixed.
Comment #16
MegaChriz CreditAttribution: MegaChriz commented#1471500: Issues with the uc_addresses_address element is done now. We can now continue with fixing this issue.
Comment #17
MegaChriz CreditAttribution: MegaChriz commentedHere is a new patch to be used as a starting point for fixing this issue. The differences with the patch posted in #11 is it's now in line with the changes done in the uc_addresses_address element (see also #1471500: Issues with the uc_addresses_address element).
It also fixes one of the errors noted in #14 (about undefined properties).
In my installation, selecting an address is working fine and somehow I don't get the "nested level too deep" error anymore (as reported in #12). I think this is no longer an issue since the fundamental changes in the uc_addresses_address element. It can also because I didn't do a wide test yet (with modules turned on and off).
The next steps for fixing this issue:
- Implement "copy address". This should not work exactly the same as on checkout. It should be possible to copy addresses in both directions without collapsing the forms.
- The address selector should be "hidden" by default. That is because the label for a selectable address can be very long and that can cause (very) wide address panes (see image).
- The automated tests should be updated (I will work on that part when the two first bullets are done).
- The fix should be tested with several configurations (for example: with uc_quote module turned on and off)
Comment #18
MegaChriz CreditAttribution: MegaChriz commentedMarked issue #1529960: Addresses not saving when order created through backend as a duplicate of this one.
Comment #19
Saratt CreditAttribution: Saratt commentedHi MegaChriz,
Thank you for your direction on #1529960. From my initial tests, the patch seems to be working great. Also, from the image that you attached along with the patch, i see that you added an extra text box to the address field (i mean, usually street address field has just two text boxes), I would like to know how you achieved that. I am trying to have three text fields for the street address.
Thanks.
Comment #20
MegaChriz CreditAttribution: MegaChriz commented@st455
Ubercart Addresses 6.x-2.x and 7.x-1.x have support for adding extra address fields through the field handler api. I'm working on an example module to demonstrate that. Currently, the example module's documentation is a bit short and it also demonstrates only one type of field (a simple text field) and that's why I hadn't published it yet. However, I think I will include it with the Ubercart Addresses package this week, as it's quite useful to have an example, although it less good documented.
There is no UI for adding extra address fields, it's only possible to do so via the API. For Ubercart Addresses 6.x-2.x, Extra Fields Pane delivered that UI (in the form of supporting only a few field types), but I haven't had the time yet to port that module to Drupal 7. Ideally, the UI would be delivered by the Drupal 7 field API (or maybe it should even replace the Ubercart Addresses field handler API), but that is an idea for the far future. At this point, I'm not even sure if I will ever come to that point.
I'm currently working on this issue; I'm taking the steps as noted in #17. As it less easy as I had expected, I will commit the patch in #17 soon as it fixes also the now broken order administration section.
Comment #21
MegaChriz CreditAttribution: MegaChriz commentedPatch in #17 is committed:
http://drupalcode.org/project/uc_addresses.git/commit/e070d2a
http://drupalcode.org/project/uc_addresses.git/commit/4170010
In two commits this time, I got interrupted when doing changes and forgot to remove debug code and doing a code review when I did the first commit.
New problem detected:
- When an order is created for a customer with no addresses in the address book, but with previous orders, selecting an address will result into errors: the familiar "Illegal choice" error (zone issues).
So, to sum up what needs to be done before this issue is fixed:
- Implement "copy address". Should work just like Ubercart one's except it should be done via Ajax.
- Hide the address selector by default, just like Ubercart does.
- Fix selecting addresses for customers with no addresses in the address book.
- Update automated tests (partly done now).
- Testing with several configurations.
Comment #22
MegaChriz CreditAttribution: MegaChriz commentedEdit: duplicated comment.
Comment #23
Saratt CreditAttribution: Saratt commented@MegaChriz We implemented the field handler and got a new field to display in the checkout form. However, since the field happens to be part of our address field, we want to load it along with our address. Is there any way we can get the "aid" value for a given order id? Currently, there is no explicit relation between aid and order_id since addresses are saved for user. Buy as you know when we have to load orders for "edit" mode in the backend, we need to know which address(aid) should be picked.
Thanks.
Comment #24
MegaChriz CreditAttribution: MegaChriz commented@st455
There is no relation between the uc_addresses and uc_orders table. Addresses for an order should be stored in the uc_orders table.
I have added an example module to the 7.x-1.x version that demonstrates a way of adding address fields that will work with both the address book and Ubercart orders. Hopefully, you will find the answers there. If not, please open a new issue if you have further questions about extra address fields.
Comment #25
patrick.thurmond@gmail.comWhy don't you just create a join table so that you can associate addresses to the uc_orders table? This could be done for any table association with addresses. Just have two columns, the address row id and the order id. The combined key will be the primary key.
Comment #26
MegaChriz CreditAttribution: MegaChriz commentedThe following patch fixes the following for this issue:
- The return of the "copy address" feature, but now implemented via Drupal Ajax Framework/Drupal Form API.
- The address selector is hidden by default (just as is the case in Ubercart). Also done with Ajax technics.
- Selecting addresses from previous orders should work again.
Since this patch changes a lot of code, please test if it doesn't introduce any new bugs or rare side effects.
@pthurmond
The records in the uc_addresses table are pure used for the customer's address book and thus it make no sense to link them with the uc_orders table. Addresses for the Ubercart order are saved in the uc_orders table. This is the default Ubercart behavior and Ubercart expects the addresses to be there.
Comment #28
MegaChriz CreditAttribution: MegaChriz commentedHm, including images to a patch doesn't seem to work. Here's a new patch. The images are attached separately.
Again, this are the fixes:
- The return of the "copy address" feature, but now implemented via Drupal Ajax Framework/Drupal Form API.
- The address selector is hidden by default (just as is the case in Ubercart). Also done with Ajax technics.
- Selecting addresses from previous orders should work again.
Please test if there no new bugs introduced or other side effects.
Comment #29
MegaChriz CreditAttribution: MegaChriz commentedHere's a new patch, with a few changes. The "copy address" feature didn't work at all in the last patch, because I accidentally removed a function that was still used as the ajax callback of the copy address function. For the rest some little fixes/cleanup to the address select field element, that's introduced to fix selecting addresses from previous orders. I would like to separate these two fixes, but since their so tight well together now it will take more time than I can spend now. I'm happy to hear opinions.
Comment #30
Michael-IDA CreditAttribution: Michael-IDA commentedHi Youri,
Started on this, first problem is with Drush not liking the .info dependencies list:
Manually adding dependencies[] = ubercart to the .info didn't help. Drush goes into a dl ubercart loop (and keeps asking to overwrite ubercart). Seems a drush issue? http://drupal.org/node/1511984 "Drush does not yet have any way to do the reverse mapping from the module name to the project name." As there is no drupal.org/project/uc_store . There may be a way to force drush to dl/en ubercart before trying to dl uc_store, but I'm not sure what it is. (I'll open a request for clarification ticket in drush)
Manually dl ubercart and then en uc_store lets drush enable uc_addresses.
Might want to add a note about this to the readme.
I'll work on the rest tomorrow.
Best,
Sam
Comment #31
MegaChriz CreditAttribution: MegaChriz commentedThe dependency should be "uc_store", which is one of the modules Ubercart Addresses depends on. But "uc_store" is not the name of the project. Changing the dependency to "ubercart" wouldn't be right because that's not the name of a module Ubercart Addresses depends on. As I read the issue you posted a link to, it looks like Drush tries to download the dependencies, but doesn't have the sufficient information to do so, because drupal.org doesn't seem to provide enough information for Drush. I guess the easiest to do is to just downloading the dependencies manually. I have not much experience with Drush, but maybe Drush doesn't complain anymore when all the dependency modules are present?
Comment #32
Michael-IDA CreditAttribution: Michael-IDA commented>> Changing the dependency to "ubercart"
No, I was adding “ubercart” to the dependency list. In the vain hopes drush would figure it out, which it didn't.
And yes, it's a drush problem.
Though I do highly recommend using drush, it saves huge amounts of time. Although you're on a MAC/OSX?, which might complicate installing it, but it's still very valuable for quickly building sites. Here's my site install script, which builds a site in a minute or two. If you can't run a bash script, just strip out the drush commands.
Best,
Sam
Rename it to "d-site-install.sh"
Comment #33
MegaChriz CreditAttribution: MegaChriz commentedI have committed a part of #29. This part introduced a new form element called "uc_addresses_address_select" and is there to fix the issue of selecting addresses from previous orders. I have moved this part of the issue, which is related but actually a different issue in #1701324: Selecting addresses from previous orders fails.
Here is a new patch, a sort of "re-roll" of #29. There are no new changes, just the fix for #1701324: Selecting addresses from previous orders fails has been removed from it.
The images folder in images.zip should be placed in the root of the uc_addresses module folder.
Comment #34
MegaChriz CreditAttribution: MegaChriz commentedRemoved the tags. The last piece for the order administration feature - the "copy address" feature - will be implemented later.
Comment #35
jvieille CreditAttribution: jvieille commentedI have the same problem, but with the D6 version.
The selected addresses are not saved in manual orders.
Does this patch exist or is it needed / relevant for D6?
Comment #36
MegaChriz CreditAttribution: MegaChriz commented@jvieille
This issue is about selecting addresses from the address book in the order administration for the 7.x-1.x version. This works differently than for the 6.x-2.x version. For the 7.x-1.x version, Drupal's AJAX framework is used to apply addresses. In the 6.x-2.x version this is done with just javascript.
One piece that is missing for this issue is the ability to copy addresses from the shipping to the billing pane (and vice versa). This feature is originally provided by Ubercart, but Ubercart's version doesn't work with extra address fields as it uses "plain" javascript and only cares for the fields it knows. That's why the feature is removed at the moment with Ubercart Addresses installed. It should be replaced by a solution using Drupal's AJAX framework, but I haven't been able to figure out a neat solution. The patch in #33 needs extra CSS in order to style the copy button similar as in Ubercart, but this CSS may be to aggressive: hard to override by themers. A solution using a simple link is not supported by Drupal's AJAX framework, because there wouldn't be a fallback when javascript is disabled.
Comment #37
MegaChriz CreditAttribution: MegaChriz commentedI never liked the fix in #33 where it was needed to add images to uc_addresses that are already present in Ubercart. I thought a long time how to come up with a nicer fix that doesn't require the extra images. I finally came up the idea to fix the problem the way the Rules module did: on some places in Rules UI, a smaller button is shown:
The following patch implements the copy address button, but doesn't include all the features from the patch in #33.
An overview of the changes:
Plus, compared to the patch in #33:
This is how the address panes on the order admin screen now look like:
This needs some manual testing to ensure all address related features still work (address selecting, zone selecting, copying addresses, etc.). But let first see if it passes the automated tests.
Comment #39
MegaChriz CreditAttribution: MegaChriz commentedIn addition of the patch in #37, this patch adjusts the order test case: it informs the test that the element in the form has changed from "billing" to "bill_to".
No other changes were made.
Comment #40
MegaChriz CreditAttribution: MegaChriz commentedI manually tested address selecting, zone selecting and copying addresses and didn't encounter issues with it. I even tested together with Extra Fields Pane. In combination with that module copying addresses doesn't work properly (extra field values aren't copied over), but that should be fixed in Extra Fields Pane which will I do later.
Committed #39.
Comment #41
MegaChriz CreditAttribution: MegaChriz commentedA patch for Extra Fields Pane is available in #1997842: Adjust order administration. It will be committed after a new release of Ubercart Addresses 7.x-1.x is made.