2

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);
}
  • Try adding $wrapper->save()? – Clive Oct 16 '14 at 12:17
  • I have tried that, also tried entity_save. This shouldn't be required due to the set() method. I have also tried $profile->field_product[LANGUAGE_NONE][0]['product_id'] = $product_id; and then saving. – themic8 Oct 16 '14 at 12:24
  • Issue was with using user/account over profile/profile2 for rules. – themic8 Oct 20 '14 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.