I use Drupal Commerce with Commerce Credits module to let users buy credits which later can be used to submit content.

The module has support for Rules but I can't get a very simple condition to work. The problem is that 'Entity has credits' rule always returns 0 even if my users have credits:

enter image description here

I tried to debug the amount of user credits but without any results:

  • Rules evaluation log shows me that comparison to 0 always returns true but to different values always false, independently if user has credits or no. Before that I check if entity is of type node.

    • Checking if entity is of type commerce_credits and using 'Entity has credits' doesn't give me any result.
  • Devel debug using action "Debug value" to show credits for user fails for node:author and site:current-user as no reference to credits is shown.

  • I tried also to get access to commerce_credits by "Fetch entity by id/property", but couldn't figure out what id/property to define.

Looking at the code of Commerce Credits module it looks like credits get saved to an entity called commerce_credits. But I can't figure out how to use this token.

Any other way to debug Rules and find the credits value related to a user?

  • Perhaps you can look into the $node (submission node) variable and see what's in there by outputting it to watchdog In your rule add an action "Execute custom PHP code" and then set this as it's value watchdog('my debug info', print_r($node,1));
    – devunder
    Feb 20, 2017 at 21:00
  • Thanks to your watchdog hint, I applied it directly in the module code to debug the issue.
    – geraldo
    Feb 24, 2017 at 17:47

1 Answer 1


Looks like you did pretty much everything you can do to "debug" a rule that doesn't seem to do what you want, so I can't give you any other hints to the "how to debug"-part of your questions. But... I may have a solution to get around the actual problem ...

Have a look at the issue "After updating existing content" runs before content is saved, about an event which is a variation of your event here, and somehow explains that "after saving something" actually happens ... "before saving something" (which IMO is not a bug, simply how the Rules module works ...).

A possible compromise to avoid these kind of issues, is to transform what you're trying to do in your Rules Conditions and -Actions in a Rules Component, so that after your First Rules Action you "schedule the execution" (using the Rules Scheduler submodule) of that Rules Component. For example after only a few seconds or minutes later on (if your cron job runs frequent enough, otherwise it'll be next time cron runs).

BTW, there are also scenarios where it is sufficient to just execute the Rules Component (containing the equivalent of your "subsequent Rules Action"), instead of using the Rules Scheduler to schedule its execution.

Update: as per geraldo's comment below this answer, the actual solution to the question here seems to be as described in comment nr 8 of support issue # 2502703, and which is like so:

The problem is line 317 in commerce_credits.rules.inc. Using count($credits->credits) always returns 1. Everything works fine when changing it to:

 if ($credits->credits >= $credit_number) {
  • Thanks for your hints, I have them in mind for other use cases with rules. For this concrete issue it didn't help, the problem seems to be a bug in Drupal Commerce.
    – geraldo
    Feb 24, 2017 at 17:44

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.