This problem is to do with the following modules:
- Drupal Commerce
I have the following code in an "Execute custom PHP code" Rules action. It creates a product display to go with a product (also created by Rules).
The problem is, it does not populate the product reference field (
field_product_reference) and gives an error.
$product = $contact_details_product; $display = new stdClass(); $display->type = 'product_display_regular'; node_object_prepare($display); $display->title = "Product display"; $display->language = LANGUAGE_NONE; $display->field_product_reference['und']['product_id'] = $product->product_id; echo "TYPE: " . gettype($product->product_id); node_save($display);
$contact_details_productis a variable available in Rules due to the previously created 'product' (as opposed to the display). This product was created in the same rule by a previous action.
product_display_regularis the product display content type.
field_product_referenceis the machine name of the product reference field.
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /home/test/public_html/includes/entity.inc).
Hacking entity.inc to display some values showed that at some point the variable on line 178 gets a null value, so I'm guessing there's a problem with the php code in the rule. Output of gettype and print_r in entity.inc:
TYPE: string Array (  => 170 ) TYPE: string Array (  => 170 ) TYPE: NULL Array (  => ) ...
That's about all I have right now. Can give more info if needed. Cheers!