1

I have Drupal Commerce shop, that sells products that by their nature are most of the time not useful to buy twice. Exceptions do exist.

So what I want is to show a field or add a class on products page to mark it in very visible way, if current use has at some point bought this product, ie. if this product can be found in current users order history.

I will also want to show this mark in the product listings.

Lastly, I want to tell you that I do have some experience with templates in drupal, but not that much, especially with commerce. I also have Display Suite installed, if the code field way of doing things would be easier.

  • Please perform a rollback of your question to the prior version of it. Because as per the edit of your question, you invalidated my answer (which you also un-accepted around the time of your edit), and this is not allowed on this site. After you applied such rollback, post your "edit" as a new question, as a followup-question related to this question, if you want with a link to this question also. I understand you're new to this site, so I trust it's just a matter of knowing some of the basic Rules (oeps: rules) of this site ... – Pierre.Vriens Jul 18 '17 at 11:06
  • merci @Nenotek for the rollback you just performed (so that the edit of your question no longer invalidates my existing answer). Looking forward to your followup-question (please drop me a comment after you posted it) .. – Pierre.Vriens Jul 18 '17 at 13:01
  • Hi. Here is the link: drupal.stackexchange.com/questions/241916/… Sorry for misconduct. I kind of thought its part of this question, but looking back I see that its actually a separate question. – Nenotek Jul 18 '17 at 13:16
1

This really seems like a perfect fit for the Flag module. Excerpt from its project page (bold markup added here):

... Flag is a flexible flagging system that is completely customizable by the administrator. Using this module, the site administrator can provide any number of flags for nodes, comments, users, and any other type of entity. Some possibilities include bookmarks, marking important, friends, or flag as offensive. With extensive views integration, you can create custom lists of popular content or keep tabs on important content.

Flags may be per-user, meaning that each user can mark an item individually, or global, meaning that the item is either marked or it is not marked, and any user who changes that changes it for everyone.

In this way, additional flags (similar to published and sticky) can be put on nodes, or other items, and dealt with by the system however the administration likes.

If you're not familiar with the Flag module, checkout the set of 8 video tutorials about the flag module.

Refer to Flag's Community documentation for (way) more details.

You should configure an appropriate (non-global) flag, which you should then use to (automagically) flag products each time a user buys some product. And next time some products are shown to such user, you use that info about "has this product yes or no been flagged by this user already".

To actually flag such products, you should use the Rules module, which integrates extremely well with the Flag module. All that's left is to find the appropriate Rules Event for such rule to be triggered (somewhere along the lines of "checkout completed" I would assume).

If you'd want to take this even a step further, you could also consider what is described in the accepted answer to "How to add a custom icon or symbol to a flag link?".

  • Hi This seems like a good solution. But in that case I have one additional question: Since the shop is live already, how would I create these flags for products that have already been purchase before I make these changes? – Nenotek Jul 10 '17 at 6:30
  • I added the new question here: drupal.stackexchange.com/questions/241323/… – Nenotek Jul 10 '17 at 11:06
  • I have installed flag now, and I have set the non-global flag called "Product already purchased". But what I'm not sure about now is: Am I supposed to flag the line item or the node that displays the line item? – Nenotek Jul 14 '17 at 10:25
  • @Nenotek Ithink you need to flag the product that each line item is about. – Pierre.Vriens Jul 14 '17 at 10:33
  • So far I have managed to create flags for products, and then with the help of commerce_product_reference_flag-module, I have managed to show this as a field on the product display page and made it look the way I want with the help of some JavaScript. Now I'm trying to create rule to flag products on event "Completing the checkout process". I thought I would create a loop, that goes trough orders line items, and then flags each product, but I cant find a way to connect orders line items to the actual products in rules. Am I doing something wrong or do I just misunderstand something? – Nenotek Jul 17 '17 at 12:20

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.