Description:
My drupal commerce line-item's have extra "add-to-cart form" fields attached to the line-item type.
One of the fields is a field-collection that contains 2 fields:
- A customer_profile_reference field with a custom widget (basically the same as an address field)
- A custom field for time-window
When I loop through the line-items on "Checkout:Complete" with a rule action, I get the field value in the field collection as the field collection entity id, which I suppose is fine. When I now load the field_collection_item i get this:
Problem:
The field_delivery_profile, which is the customer_profile_reference field, does not show a value, and now I find out that the values aren't stored.
For the custom field + custom field widget I've created, everything works as intended.
The field widget for the custom customer_profile_reference field is basically a select list with profile_id's as the value, and I'm not sure now do I have to somehow specifically write some sort of a save hook? Because for the custom field + field widget module, all I've done is a presave for the field. By default this field stores only an id (for the profile to reference) and shouldn't need anything extra.
Or is there a specific way I have to build the options list? Currently the options list gets built like this:
foreach (commerce_customer_profile_load_multiple($profiles) as $profile) {
$options[$profile->profile_id] =
$profile->commerce_customer_address["und"][0]["name_line"].", ".
$profile->commerce_customer_address["und"][0]["thoroughfare"].", ".
$profile->commerce_customer_address["und"][0]["postal_code"].", ".
$profile->commerce_customer_address["und"][0]["country"];
}
And implemented as the element like this:
$element['select_address'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => $default,
'#title' => t('Address'),
'#required' => TRUE,
'#id' => $element_id,
);
Edit:
I have found out, that at one point it used to work, and has values in the db, however I've no way of pinpointing what has changed. Comparing the older versions of the module file, I see that they're essentially same, and even when reverting back to the older one, it doesn't seem to store data. What else could be causing this?
Edit 2:
Added a custom validation function to the widget element, and the $element['#value'] exists and is proper. I am however clueless as to why it's not being stored to the database.
Edit 3:
I've been struggling with this issue now for 3 days without any clear idea what could be causing it. I've debugged everything I can think of, and yet the code from when it was working does not differ by much, and even using the old code doesn't seem to remedy the situation.
This is the $element array from a validation function:
function _validate_cosmobutler_address($element, &$form_state, $form) {
dpm($element);
}
As can be seen, it has the value of a profile id, as it's supposed to. Also the database table commerce_profile_reference field created when first creating the field is the following:
Table: field_data_field_delivery_profile
Columns:
entity_type varchar(128) PK
bundle varchar(128)
deleted tinyint(4) PK
entity_id int(10) UN PK
revision_id int(10) UN
language varchar(32) PK
delta int(10) UN PK
field_delivery_profile_profile_id int(10) UN
I've also tried changing the element creation from:
$element['select_address']
to:
$element['value']
But that didn't seem to help either.
Edit 4:
I've deducted that the problem must come somewhere from the custom widget implementation, as the same field with a different widget stores data well.
The complete widget code can be found here:
TL;DR Summary:
I'm unable to store data for customer_profile_reference field from a custom field widget. The storeable data should only require an id (of the profile), which are my select list options values anyway. The code for both options list and element implementation is above. The field seems to have stored values in the past but isn't any longer, so I'm hoping someone can give me more debuging insights or maybe can pinpoint the issue based on these descriptions.
Hope someone has a solution I may have overlooked.
Best,
Alari