1

I'm trying to award some User Points to users who select a certain plan during his checkout process.

Here is the explanation of my website functionality.

  1. When a user register with a role, the user will get access to the website with certain functionality.
  2. Some users will be having permission to create new nodes.
  3. During the node creation, the user needs to select a plan (I'm using Commerce Node Checkout module to add product as plan).
  4. Based on the user's selection, the user will be redirected to the checkout page.
  5. After completion of the checkout process, the user will receive some User Points. For this I have created a rule, but it is not working as expected.

Here is the export of my rule:

{ "rules_per_day" : {
    "LABEL" : "Per day",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "per day" ],
    "REQUIRES" : [ "commerce_order", "userpoints_rules", "commerce_checkout" ],
    "ON" : { "commerce_checkout_complete" : [] },
    "IF" : [
      { "commerce_order_contains_product" : {
          "commerce_order" : [ "site:current-cart-order" ],
          "product_id" : "day_4dxivfX2oFRAqQH-Ij6VBFnBheZBRIo744cF46KKPSI",
          "operator" : "=",
          "value" : "1"
        }
      }
    ],
    "DO" : [
      { "userpoints_action_grant_points" : {
          "user" : [ "site:current-user" ],
          "points" : "50",
          "tid" : "0",
          "entity" : [ "commerce-order" ],
          "description" : "You have received  the points for selected plan.",
          "operation" : "Insert",
          "display" : 1,
          "moderate" : "approved"
        }
      }
    ]
  }
}

The Rules Condition checks whether the order contains a specific product withe the product id n.

I don't understand what I did wrong or what I have missed in this rule. Any suggestions to make this rule work?

  • The condition checks whether the order contains a specific product withe the product id n. – James Oct 17 '16 at 16:46
  • @Pierre.Vriens, Thanks for the answer. The specified reasons in your answers are correct. I had posted this question almost 2 years ago and I really don't remember on which project I've faced this issue and the cause. – James Oct 30 '16 at 19:22
1

In order for your Rules Condition to be satisfied, ALL these criteria must be true:

  • Order contains the product whereas the SKU of that product must be "day_4dxivfX2oFRAqQH-Ij6VBFnBheZBRIo744cF46KKPSI".
  • The quantity of the specified product on the order must be "= 1".

Since the user does not seem to receive the userpoints, it must be because of either of these reasons:

  • Reason 1: your Rules Condition is not satisfied. Assuming that there is no typo in the SKU value, it could be because the quantity is NOT "= 1".

    As a quick check to find out if this is what is causing your issue, simply do a test in which you (temporary) change this rules condition to the opposite, by using the "negate" checkbox for that Rules Condition. If in that scenario the userpoints are granted, you can be sure that the quantity is indeed NOT "= 1" (even though you may think/expect that to be the case ...).

  • Reason 2: your Rules Condition is OK, but your Rules Action for some unknown reason does not actually grant the points to the user.

    As a quick check to find out if this is what is causing your issue, just add another Rules Action (before the one you have already) to simply "Display a message" (which you find within "System"). All the message should be is something like "Rules Action triggered". If in that scenario such message is actually shown, you can be sure that the cause of your problem is something related to your Rules Action (to grant points) that is not working as you think/expect it to work.

If none of the above helps, then it's time for Rules debugging, as detailed in "How to debug a rule that doesn't want to fire?".

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.