Threre is part of commerce_customer_field_widget_form():

function commerce_customer_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  // Define the complex customer profile reference field widget.
  if ($instance['widget']['type'] == 'commerce_customer_profile_manager') {
    $profile_type = commerce_customer_profile_type_load($field['settings']['profile_type']);

    // Do not attempt to render the widget for a non-existent profile type.
    if (empty($profile_type)) {
      drupal_set_message(t('Field %field_name attempted to use the non-existing customer profile type %type.', array('%field_name' => $field['field_name'], '%type' => $field['settings']['profile_type'])), 'error');
      return array();
    }

    // Build an array of customer profile IDs from this field's values.
    $profile_ids = array();

    foreach ($items as $item) {
      $profile_ids[] = $item['profile_id'];
    }

And in ajax callback $items can contain profile fields and profile object (and not a profile_id):

$items = array(
  'profile' => array(
    'profile_id' => 11,
    /*...*/
  ),
  'field_first_name' => array(/*...*/),
  /*...*/
);

($items is filling in commerce_order_order_form_validate() function)
So, if profile is already loaded, there will be notice at "$profile_ids[] = $item['profile_id'];" string:

Notice: Trying to get property of non-object in commerce_customer_field_widget_form

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Evgeny_Yudkin’s picture

eugene.ilyin’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: commerce_already_loaded_profiles_2470687_1_D7.patch, failed testing.

rszrama’s picture

Category: Bug report » Support request
Status: Needs work » Closed (cannot reproduce)

I'm sorry, I actually can't reproduce this issue and suspect there to be something else wrong. For starters, your patch actually seems most likely to blame given the notice you pasted - there is no property access in the current code; that's introduced by your patch when you try to get $items['profile']->profile_id.

Additionally, I only ever see profile IDs in the $items array across Ajax refreshes. The $items array is always meant to be an array of value for the field, so it should never been anything other than arrays with profile IDs in them. Some other module may be using an illegitimate form_set_value() here that's causing the behavior you're seeing.

Also, maybe you just used it as an example, but do you know you can configure the Address field on the customer profile to separate out first and last name instead of using a single name line? Just checking since your array snippet shows a field_first_name on your customer profile type.