I am trying to use a rule to add a product to a profile. Also, I am using an autocomplete entity reference widget for the product reference field.
Currently I can see the product being added but not saved/updated.
If I dpm() the profile at the end of the function I can see that the product is being added correctly, but when I review the profile it is not there.
Here is the rule I have created:
function mymodule_add_product_rule ($account,$sku){
$uid = $account->uid;
$product = commerce_product_load_by_sku($sku);
$product_id = (string)$product->product_id;
$profile = profile2_load_by_user($account, 'profile_machine_name');
$wrapper = entity_metadata_wrapper('profile2', $profile);
$wrapper->field_product->set($product_id);
//dpm($profile);
}
$wrapper->save()
? – Clive♦ Oct 16 '14 at 12:17