I have a custom order type created via commerce_order_types; this order type doesn't have a shipping field (it doesn't need one) therefore I've been receiving this error:
EntityMetadataWrapperException: Unknown data property commerce_customer_shipping in .../sites/all/modules/entity/includes/entity.wrapper.inc on line 335
and I think it's because of commerce_addressbook_commerce_order_insert($order); the function, if I understand correctly, is used to set the customer profile fields to its default value. it doesn't check though, whether the order object actually "have" this field. I say, we add a check if the order has this field:
if (variable_get('commerce_' . $pane_id . '_addressbook', FALSE)) {
if (($field_name = variable_get('commerce_' . $pane_id . '_field', '')) && empty($order->{$field_name})) {
$field = field_info_field($field_name);
// Add check whether the field is in the entity object
if (in_array($order->type, $field['bundles']['commerce_order'])) {
$default_profile_id = commerce_addressbook_get_default_profile_id($user->uid, $field['settings']['profile_type']);
if ($default_profile_id) {
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->{$field_name} = $default_profile_id;
$order_wrapper->save();
}
}
}
Comments
Comment #1
mglaman#2217441: Make sure profile fields exist before attempting to set default value has patch for this issue, marking this as duplicate so discussion can take place on andyg5000's patch