Posted by dianikol on December 17, 2012 at 8:53am
3 followers
Jump to:
| Project: | Address Field |
| Version: | 7.x-1.0-beta3 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (cannot reproduce) |
| Issue tags: | Feeds |
Issue Summary
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.
<?php
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
#1
Better title.
Marked #1858454: Unable to save customer address fields upon import with Commerce Feeds. as a duplicate of this one.
#2
Tagging.
#3
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.
#4
Apparently this may also be considered a duplicate of #1365216: Provide Feeds Tamper plugins to use default values for missing data, map country names to codes, etc..