I am trying add a commerce product to a node when a person fills out a content node. I am generating the product, but can't add it back to the node.
When I try to add the data to the node, there is no product reference field data when Do not show a widget is selected in the content type > Manage fields.
Do not show a widget seems to remove the field from the node completely.
If I try to load in hook_node_presave():
$product = commerce_product_load_by_sku($sku); $field_studio_pass_product = array( LANGUAGE_NONE => array( 0 => array( 'product_id' => $product->product_id, ) ) ); $node->field_studio_pass_product = $field_studio_pass_product;
It won't work since there is no current field. I don't want to show the field to editor as they can't change it.
Further. This above code does work if the product field has a widget, or the ideal code:
$node_wrapper = entity_metadata_wrapper('node', $node); $node_wrapper->field_studio_pass_product->set($product->product_id);
Again, if you set the field type to Do not show a widget there is no property on the node object, and as a result no ability to add a value.