2

I have a Drupal Commerce site which uses user points (= coins) for paying.

I have a special case - the product, which the user should buy with his/her coins, needs some fields filled out by the user. So I used a content type for this case and when the user adds a new one, 10 coins will be reduced from the user's account - this works already fine.

Now I have also a taxonomy in this content type and the user can add terms to it, which are shown later in the form when the user fills it.

Problem :

I need to count how many checkboxes of the taxonomy terms are checked and multiply the costs with them. So if 3 of 5 are checked, then 10 coins * 3 = 30 coins will be the final price when the user adds a new content type.

Is this possible with Rules? I have no clue how to realize that (I´m front-end developer and no PHP coder).

3
  • hi, thanks for your answer, was not able to test it yet because the project got postponed.
    – JOKER
    Commented Feb 2, 2018 at 9:06
  • sorry, had to google how to accept an answer, i´m a totally stackexchange newbie
    – JOKER
    Commented Feb 3, 2018 at 12:35
  • merci for the accept ... maybe you were looking for drupal.stackexchange.com/help/someone-answers ...? Commented Feb 3, 2018 at 12:41

1 Answer 1

2

Yes this is perfectly possible with Rules, and you don't need any PHP to get the job done. In your case, the crucial part of such rule is a Rules Action to perform a Loop. If you're not familiar with such loops, then I strongly recommend to have a look at the tutorial titled "Lists and loops".

In your case, you should use (at least) these Rules Actions:

  • "Add a variable" (say with a machine name like nr_of_checked_terms), with initial value "0".
  • Add a loop related to your taxonomy terms. After you do, you should iterate over each item in that list (= each taxonomy term). And for each iteration you should then perform a Rules Action to "Set a data value", whereas you actually increment the value of nr_of_checked_terms with "1".

After the loop finished, the value of nr_of_checked_terms will be the actual number of terms that were checked. Just add another Rules Action near the end to do your actual multiplication using nr_of_checked_terms as one of the available tokens.

Done

PS 1: Refer to my answer to "How to set multiple values to an unlimited Term Refence field with Rules" for some sample rules that are like a variation of your question here.

PS 2: I assume this is about D7 ...

1
  • hi, thanks a lot for your answer, yes, it was about D7
    – JOKER
    Commented May 19, 2022 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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