When building an order for a customer, billing and shipping disappears when saved.
After adding billing and shipping info for customer, hit save and the info is there. But when I add a product and hit save, billing and shipping info is removed from the order. Using Commerce Addressbook to save addresses for customers.
Any suggestions?
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 3248497-12.prevent-disappearing-profiles.patch | 4.97 KB | rszrama |
| #11 | 3248497-11.prevent-disappearing-profiles.patch | 3.93 KB | rszrama |
Comments
Comment #2
pnigro commentedI am encountering the same issue. It also occurs when adding a shipping line item.
Comment #3
pnigro commentedMarking as critical since there is loss of data on user input.
Comment #4
rebuildermed commentedAny new update on this? Still experiencing the same issue. Thanks.
Comment #5
steveganz commentedWe are also experiencing this bug.
Comment #6
isholgueras commentedI've been investigating this and I can confirm this is a regression introduced in commerce 1.16, and in my opinion, this seems to be a critical issue due to sometimes the editor gets a 500 error, or some others could delete addresses.
What I've compared is both versions working in the same installation with the following structure:
the
commercedirectory is a symbolic link pointing 1.15 or 1.16, depending on what I want to verify.The steps to reproduce I do, in our custom, but simple, commerce installation are:
After this, I get the line item correctly added with commerce 1.15, but the following error with 1.16:
The error is in the commerce_order.forms.inc:285
Before the execution of this function, the
$orderobject has thecommerce_customer_addressfield, but after it, it's removed, so then both addresses are emptyAnd inside the
field_attach_submit, the error happens in:I've made a diff between the two order objects that are sent into the field_attach_submit and here is the only difference, the Commerce 1.16 seems to add/activate the revision:
Don't know if this makes sense or not, but I couldn't find anything different or strange in the new code added. I'm a bit lost yet on what is happening.
Comment #7
steveganz commentedIt appears as though this regression was introduced in https://www.drupal.org/node/2274833. I narrowed down the issue that causes the EntityMetadataWrapperException when adding a line item via the admin order edit form to the handling of empty profiles in commerce/modules/customer/commerce_customer.module. Reverting to the 7.x-1.15 version of commerce_customer.module, and more specifically just the code block on lines 1001-1008, allows us to to add line items on the admin order edit form and also prevents the removal of the billing and shipping info from the order.
Comment #8
steveganz commentedConsider this only as a possible workaround for this issue until the maintainers can get into it.
Comment #9
rszrama commentedSteve, thanks for digging into this, and terribly sorry to see the problem rear its head. It appears to be an issue with the way the new code interacts with the fact that the Ajax process uses #limit_validation_errors, causing form input for the profile reference field to be ignored. Apparently that's leading to the unsetting of the reference field values. Going to be digging into a solution to roll a new release ASAP. (Brant from Bluespark brought this to my attention ... lovely that it didn't turn up in a year of testing / use in our customer's production site. 🤦🏻♂️)
Comment #10
rszrama commentedAlso, fwiw, this happens even if you don't add a line item. It's the use of an Ajax button anywhere on the edit form that causes the data loss.
Comment #11
rszrama commentedMy hunch was correct, and the issue is resolved by changing the way the widget form and custom element validate handler function when processing the widget during a button's "limited validation errors" submission. The attached patch will let you add new line items just fine without causing data loss, and I'd appreciate a +1 review.
That said ... fiddling with this turned up another issue with the way the form is built. I discovered a scenario where adding two new profiles on an order edit form and canceling one will result in a loss of context, causing the second cancel button click to fail. At first I thought I needed to make the "Cancel" buttons more specific (i.e. via unique #value labels), but that didn't appear to resolve the matter. You can see that represented in the current patch. I'm not sure I'll leave that in once I find the ultimate solution ... it's related to this fix, so I'm inclined to solve the matter in this ticket, but if I can't sort it out this weekend, we'll commit just the data loss bug fix and worry about the cancelation UX fix in a follow-up.
Comment #12
rszrama commentedAlright, one last patch that I think resolves all issues.
I couldn't make everything work without differentiating the button text. I don't mind being more specific in the UI, but I know this impacts translations. Better to have an ironclad UX imo, so in testing, please abuse the Ajax enabled buttons on the order edit form to see if you can produce a scenario where the wrong form elements are replaced post-Ajax.
The reason this was failing is the custom element validate handler for profiles was testing a false negative condition when it checked to see if the validation was occurring for a related Ajax operation. It only checked to see if a property existed in the $triggering_element without checking to ensure the $triggering_element was within the scope of the particular customer profile reference $element being validated.
After correcting for that, the $form no longer loses the customer profile specific cancel button, the absence of which was causing Drupal to wrongly assume the "Add line item" button had been submitted. We've seen this in other contexts where Drupal will just default to the first submit button on a page if it can't find an exact match. Not sure the rationale, but it's certainly tricky to trace down!
Comment #13
steveganz commentedI gave #12 a good workout and it fixes both the original reported issue as well as the line item issue in #6. Thank you, Ryan!
Comment #14
rszrama commentedThanks, Steve. Committed!
Comment #16
rszrama commented