1

I'm trying with following simplified rule but nothing happens if using maro_credits as payment method!?

{ "rules_pay_with_maro_credits" : {
"LABEL" : "pay with maro credits",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules_conditional", "rules", "commerce_payment", "commerce_pos" ],
"ON" : { "commerce_pos_transaction_completed" : [] },
"DO" : [
{ "CONDITIONAL" : [
{
"IF" : { "commerce_payment_selected_payment_method" : { "commerce_order" : [ "order" ], "method_id" : "maro_credits" } },
"DO" : [ { "drupal_message" : { "message" : "aklfjaipwoejfipasjfijasdfas" } } ]
}
]
},
{ "LOOP" : {
"USING" : { "list" : [ "order:commerce-line-items" ] },
"ITEM" : { "list_item" : "Current list item" },
"DO" : []
}
},
{ "drupal_message" : { "message" : "test pos event" } }
]
}
}

However the orders in admin - store - orders show up with the payment method, as shown in this screenprint:

http://imgur.com/a/XZeHy

Anyhelp?

Edit: I used the mentioned selected_payment_method comparison method that pierre referenced below from start on.

cant add more than 2 links, so i have to add multiple pictures like this i guess: first you see the selected_payment_method input for the version in the actions with conditional and the rule in the view also with what happens

i after changed the rule to use the conditions directly to show that also there it does not work

http://imgur.com/a/5Ekiu

is this more clear now? or you need more specification?

edit2: in the end i added some screens showing the fields that could be found (nothing with payment method)

Edit3: Ok I added some descriptions in the pictures on imgur to clarify a bit. In the end I want to be able to subtract user points form users that pay with "maro credits" (that part already works)

As you see in the screenshots I changed the rule having only the event pos transaction completed (that works!)

then condition selected payment method as shown

and action post a message

as you see in following screenshot that does not work (in the orders list you see there is the order with the payment method maro credits

I hope its clear now?

Ah forgot: in the last screenshots you see all the fields I would be able to chose from and there is none with payment method (and i think that is the problem...?)

  • "is this more clear now?" ... not to me ... "or you need more specification?" yes. Nowhere I see anything in your question WITHOUT using "conditional rules", I still wonder what you get (or not) if you use ONLY a rules condition related to that "selected payment method comparison" (as in my answer), combined with "entity has field". Completely different attempt: why does your rule depend on "commerce_pos"? And what is, in plain english, the business logic you try to implement with rules (you never explained that in your question). Sorry for all these question, but I don't get it ... – Pierre.Vriens Aug 10 '17 at 20:53
  • tried to be more specific clear now? – Rocky Aug 12 '17 at 9:27
  • Feedback about your "edit3": answer to your "I hope it is clear now = NO , sorry. About your "Ah forgot": your question contains ZERO screenshots, only LINKS to another site. And in the last LiNK I DO NOT see anywhere "al the fields" (I just see "order"). it's not that I don't want to help, but you really, really need to improve your question. Get rid of all those links, replace them by ".JPG" files (or post a comment with links to such .JPGs and I'd be happy to edit your question to integrate them). And replace your edit 1, edit 2, edit 3 by a single question (no updates) .... – Pierre.Vriens Aug 13 '17 at 13:19
  • ... (continued). And include a copy/paste (in text format) of those "see all the fields" (I just see "order"). Let me know (extra comment) when you reworked your question. Sorry I still don't understand your real question, but I doubt I'm the only one who doesn't get it. – Pierre.Vriens Aug 13 '17 at 13:22
  • Hi Pierre, I understand your concerns, however before I rewrite everything: on this link imgur.com/a/5Ekiu to imgur, don't you see all the screenshots? It contains 11 screens - did you scroll down? I cannot add more than 2 links / pictures included in here count as links on stackexchange with my status... – Rocky Aug 13 '17 at 17:04
1

The condition you are using checks $order->data['payment_method'], which is the payment method selected by the user during checkout. An order can actually have multiple payment methods, 1 per transaction, although on a standard setup usually only 1 can be selected initially. Since POS doesn't run through a checkout and allows the customer to pay with multiple methods, such as cash and then the remainder on card, it does not have a "selected" payment method.

I don't see any easy way to get the specific transaction info in rules, so it seems like you have 2 options.

  • Hacky - Add code to the completeTransaction action that the orders selected payment to the most recent transactions type
  • Better - Create a custom condition that will check if any of the transactions in an order contain the specific payment_method
  • for now I did option 3 hacky 2 :) I made a rule on event "After saving a new commerce payment transaction" and just subtract the points there - I don't see a faster way atm – Rocky Aug 16 '17 at 6:09
1

Part 1 - Getting your rule to work

Try to add a Rules Condition Entity has field to make the appropriate field available for further processing in your Rules. That's also what is mentioned in the Rules UI when you're adding a "data comparison" condition: somewhere it says:

The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type').

Don't believe me (yet) about my recommendation here ... first add an extra Rules Action as your very first Rules Action, to simply display the actual value of that field you try to use within the "If" of your Conditional Rules construct ... Without such "entity has field" Rules Condition, I bet the value of that field will be shown as empty (or blank). Which would then also explain why your "If" always results in a FALSE ...

For a video tutorial that illustrates the importance of this Entity has field condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in that video.

Note: it's hard to tell from the current content of your question what the exact field (for which to add such Rules Condition) should be in your case. But my best guess is some field about the payment method (possibly method_id?)

Part 2 - Simplify your rule

From the current content of your rule, it seems that you want to perform a Rules Loop as a Rules Action, but only if some condition (the "If" you added using "Conditional Rules" module) is true. And then as the very last Rules Action the rule shows that test pos event message.

If this very last message is just for debugging (i.e if it is not really needed after you get it to work anymore), then it seems to me that you could replace that "If" (added using Conditional Rules) by a regular Rules Condition. And by doing so your rule would not require the Conditional Rules module anymore.

Plan B

As per the comment posted below this answer, you may want to try a completely different approach ... which is based on this commit, and related to issue # 1278156:

  • Use the Rules Condition Selected payment method comparison, located within the Commerce Payment group.
  • Check if its value is equal to your 'maro_credits'.
  • Hi there thanks first so the Loop was just wrongly in there, there rule has to do much more in the end but im trying to debug so simplified it the test pos is just for debug, to show the event works so now the problem that selected payment method comparison wants an "order" as input and then has a dropdown showing what payment methods i can compare to. ok BUT when i search for a payment method field (as you specified with entity has field or in the data selector somewhere in the rule) I cannot find any "payment method" field anywhere? :( – Rocky Aug 10 '17 at 17:18
  • additional comment: i put it down to action with conditional to debug, cause in conditions it does not work and i couldnt test the test pos message to check the event ;) – Rocky Aug 10 '17 at 17:22
  • comment plan b: that is exactly what i did, im using that conditional you specified and that asks for an order to then compare to a payment method form a drop down where i chose maro credits – Rocky Aug 10 '17 at 17:46
  • imgur.com/a/5Ekiu – Rocky Aug 10 '17 at 17:48
  • Sorry but I don't understand your latest comments ... please EDIT (expand) your question and include relevant screenprints (not links to images somewhere else). And clarify if those screenprints relate to the "if" (conditional rules) or to a regular Rules Condition. Then try to include 1 (and only 1) actual question. Without doing so, I have no other feedback/answer on top of what I already wrote. OK? – Pierre.Vriens Aug 10 '17 at 18:01

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.