Can't Complete Registration Orders with Embedded Field Collections

I'm working on a Event Registration system using Commerce, Registration, and Commerce Registration
A registration type has an embedded field collection for information on items the registrant is bringing.
If the number of embedded collections is "unlimited," the "Add Another Item" button element throws this PHP error in PHP Fatal error: Call to a member function save() on a non-object in .../field_collection/field_collection.module on line 612.
The problem is that the isset check on line 608 returns true for the string "Add Another Item."

Proposed resolution

Recommend adding a check for is_object to line 608:
if (isset($item['entity']) && is_object($item['entity'])) {

Remaining tasks

This does not completely solve the problem, as now I get:
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'add_more' for column 'delta' at row 1: INSERT INTO {field_data_field_sibling} (entity_type, entity_id, revision_id, bundle, delta, language, field_sibling_value) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => registration [:db_insert_placeholder_1] => 14 [:db_insert_placeholder_2] => 14 [:db_insert_placeholder_3] => sibling_class [:db_insert_placeholder_4] => add_more [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => A ) in field_sql_storage_field_storage_write() (line 449 of /var/www-virtual/saintlukeshealthsystem.org/htdocs/modules/field/modules/field_sql_storage/field_sql_storage.module).

I'm busy tracking this down now, and I'm not certain it resolution belongs in this module's issue queue. However, the above change at least strikes me as worthwhile.

CommentFileSizeAuthor
#3 field_collection_module.jpg115.18 KBblattmann

Comments

tauno’s picture

The remaining task (Incorrect integer value: 'add_more' for column 'delta' error) looks like it might be a commerce_registration error. I'm seeing the same error with a multi-value entity reference field on my registration type. Sounds like this is typically caused by field_attach_form_validate() not being called before saving the entity. I'm looking into it now as well...

jmuzz’s picture

Status: Needs review » Postponed (maintainer needs more info)

Is this still an issue?

What function was line 608 in?

Why would $item['entity'] ever contain anything other than field collection items? I don't think this happens under normal operations so I'm not sure it's something we need to support.

Pehaps a fatal error is the correct response.

blattmann’s picture

StatusFileSize
new115.18 KB

The function was `field_collection_field_presave`, which is no longer in the .module file though there are some references to it (lines 530 and 1784). This remains an issue for me using 7.x-1.0-beta8.

function field_collection_field_presave

jmuzz’s picture

Status: Postponed (maintainer needs more info) » Active

That code was moved to hook_field_update. The comments could be updated.

I think 'entity' is getting overwritten by one of these modules. As evidence I grepped this line out of commerce_product_reference.module: $items[$id][$delta]['entity'] = $products[$item['product_id']]; .

'entity' is a generic identifier. I think something module specific would be better, possibly field_collection_item, though I am not 100% sure this is the cause of the issue.