at order edit page (admin/commerce/orders/x/edit),
if I 'Add line item' whether product or shipping, and click 'Save order',
then customer profiles is created again(duplicating) even if I didn't edit the existing customer profile.
at order edit page (admin/commerce/orders/x/edit),
if I 'Add line item' whether product or shipping, and click 'Save order',
then customer profiles is created again(duplicating) even if I didn't edit the existing customer profile.
Comments
Comment #1
rszrama commentedThis is really an issue with Address Field accepting a country selection as a value for that field. There's an open issue in that module's queue that will need to be resolved, but we can leave this issue open here to review it once Address Field is patched.
Comment #2
rei commentedhi Ryan,
if it's the case then how to bypass the country selection, since I only have 1 default country
Comment #3
rszrama commentedI'm repurposing this issue to address this in Commerce itself. The issue with hoping for a solution in the Address Field module is that we intentionally strip the "required" property of address field form elements in the context of the order edit form. Otherwise we could make a more robust "empty" check that ignores an address field that only has the default country selected.
The solution I'm proposing is that we add a button in the customer profile manager that has to be clicked to expand the embedded customer profile form. The administrator can then input whatever they want to create the profile, but we will only ever attempt to save if the form is expanded. There should be a cancel button when it is expanded to collapse the form back down as well.
Comment #4
recidive commentedI've started working on this, but got stuck into some peculiarities of the customer profile widget. I'm posting a WIP patch here to get a review on the direction I'm taking. It still needs work.
The problems I'm having:
For #1, I figured out the
$itemsargument of thehook_field_widget_form()is missing the existing profiles, for the other profile fields/types, but for the newly created one.For #2 I figured out the profile entity is created on the widget validation, so maybe we'll need to change this, to create the profile only when the form is actually submitted.
Any help is appreciated.
Comment #5
recidive commentedThe patch is now complete and working, maybe it still needs some cleanup or better approach to manage triggering elements and form states.
I'm posting it here for review.
Comment #7
rszrama commentedFrom a code review standpoint,
It would be nice if we could split this out vs. using the ternary operator within the array_push() statement.
Additionally, not entirely sure why we're getting the duplicate warning message related to unsaved line items, but in addition to trying to ensure it shows only on the line item refresh (and not in the context of customer profile manager fieldset refreshes), it might actually be nice to include a warning message in these contexts re: the need to save the order itself after adding a new profile.
Comment #8
rszrama commentedForgot the image.
Comment #9
recidive commentedTest bot should now be happy.
Comment #10
recidive commentedI've made the changes Ryan suggest regarding the ternary operator. Also fixed the duplicated line item warning.
Regarding adding a warning for the customer profile creating only being saving on order saving, I think it doesn't make sense, since there's no "Save" button in the profile form to make it trigger this warning. I could add the message when the "Add profile" button is clicked, but I think it looks intuitive the user needs to save the order.
Comment #11
recidive commentedSome minor corrections.
Comment #12
axle_foley00 commentedI tested the patch in #11 and the issue is resolved.
Comment #13
rszrama commentedThanks much for your work, recidive, and for the review, axle_foley00! Committing now. Will see if there's anything else we should hit before a point release, but this feature's too good to hold for long. : D
Comment #15
rszrama commentedComment #17
steveganz commentedThis feature has a caused a critical regression. Please see https://www.drupal.org/project/commerce/issues/3248497