I was using commerce feeds to import some customer profiles but If one of the required field is missing then it doesn't fill in the others. My workaround is this code in addressfield_set_target($source, $entity, $target, $value) function in addressfield module.

function addressfield_set_target($source, $entity, $target, $value) {

  if ($target == 'commerce_customer_address:country') {
      $value = 'your counties initials';
  } 
  if ($value == '' && $target != 'commerce_customer_address:country' ) {
      $value = ' ';
  }

  list($field_name, $sub_field) = explode(':', $target, 2);

  // Handle non-multiple value fields.
  if (!is_array($value)) {
    $value = array($value);
  }

  $field = isset($entity->$field_name) ? $entity->$field_name : array();

  foreach ($value as $i => $v) {
    $field['und'][$i][$sub_field] = $v;
  }

  $entity->$field_name = $field;
}

Not ver pretty but it is a quick fix :)

Comments

johnv’s picture

Title: Unable to save customer address fields » Unable to save customer address fields upon import with Commerce Feeds.
rszrama’s picture

Issue tags: +Feeds

Tagging.

rszrama’s picture

Category: bug » support
Status: Active » Closed (cannot reproduce)

I can't reproduce this issue. I'm using the addresses.txt file we've added to the module as a data source, and it has addresses that lack administrative areas (and various other parts of an address). The import works fine, even in cases where I imported and then re-imported with some data intentionally deleted. Thanks for sharing your snippet, but it's not something we can use (and doesn't seem necessary).

Looking at your proposed fix, though, I see that what you're specifically having issues with is an address field lacking a country value. That's simply owing to the way the field works - it requires a country to know that a value exists for an address field. Without one, we don't know how to build the address form, for example. I've added the country requirement to the Address Field Feeds documentation:

http://drupal.org/node/1988472

If you have a data source with a country missing, I suggest using the Feeds Tamper module to provide a default value.

rszrama’s picture