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

rszrama’s picture

Category: Bug report » Task
Status: Active » Postponed

This 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.

rei’s picture

hi Ryan,
if it's the case then how to bypass the country selection, since I only have 1 default country

rszrama’s picture

Title: customer profiles created at order edit page » Hide the customer profile add form on order edit pages by default
Category: Task » Feature request
Status: Postponed » Active

I'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.

recidive’s picture

Assigned: Unassigned » recidive
Category: Feature request » Task
Status: Active » Needs work
StatusFileSize
new5.89 KB

I'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:

  1. When saving a profile after expanding the form click on the "add profile", the other profiles in the order are removed
  2. When clicking the "cancel" button after expanding the form, the form is not removed, since a profile entity is already created

For #1, I figured out the $items argument of the hook_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.

recidive’s picture

Status: Needs work » Needs review
StatusFileSize
new8.4 KB

The 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.

Status: Needs review » Needs work

The last submitted patch, 5: commerce-hide-profile-forms-order-edit-2274833-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rszrama’s picture

From a code review standpoint,

  if (empty($profiles)) {
    $should_add = !empty($form_state['add_profile_' . $profile_type['type']]);
    array_push($profiles, $should_add ? commerce_customer_profile_new($profile_type['type']) : array());
  }

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.

rszrama’s picture

StatusFileSize
new136.14 KB

Forgot the image.

recidive’s picture

Status: Needs work » Needs review
StatusFileSize
new10.52 KB

Test bot should now be happy.

recidive’s picture

I'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.

recidive’s picture

Some minor corrections.

axle_foley00’s picture

I tested the patch in #11 and the issue is resolved.

rszrama’s picture

Thanks 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

  • rszrama committed 8b1a337 on 7.x-1.x authored by recidive
    Issue #2274833 by recidive, rszrama, axle_foley00: Hide the customer...
rszrama’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

steveganz’s picture