My products have multiple variations as enitities (size, color etc). I want to display a flag link on a product display page. When a visitor uses it, I want them to be able to flag the selected variation, not the node. Is it possible? Here is a related discussion on drupal.org: http://drupal.org/node/1050872
2 Answers
I wrote a way to use Flag for product variations here: http://drupal.org/node/1911568
Here is my solution:
- Add a flag "add to wishlist" for commerce_product entity type.
- Install computed field module.
- Add a computed field to the product (not the display content type)
In Display Code (PHP) area of the field:
$entity_id = array_shift(entity_extract_ids($entity_type,$entity)); $display_output = flag_create_link('add_to_wishlist', $entity_id);
(Computed Code (PHP) part can be left empty, we dont want to store anything in database) 5. Go to Manage Display of the product and set the newly created computed field's format: "unsanitized" and make sure it is visible. 6. Go to Manage Display of the product display content type (not the product) and use your product's wishlist computed field there.
Now you can create a view to display a user's products in his wishlist. It is straitforward. You just add any field, add a relation: your flag and tweak the view as you like. You can also use view's menu system to create tabs on the user profile: http://drupal.org/node/326580
-
So, how would this be different from a flag on the product display node?– nizz0kCommented May 30, 2014 at 19:37
In case anyone comes here looking for a solution, I have created a module that will do this without needing you to do any custom coding.
Have a look at Commerce Product Reference Flag.