I'm going to mark this as a support request first, since it's entirely possible I'm doing something wrong. However, I can't see what it is...
I'm attempting to send an invoice using a specific invoice template for the product, thus my use of UC Rules. I first load an order by order ID; immediately after that I execute some PHP to log the value of $uc_order_loaded. When I check the log I see that the object is loaded properly, but I also see an error generated (using Rules debug) when the invoice action is to be executed:
68.353 ms Action execution: "Load the order for UC Rules actions"
70.897 ms Successfully added the new variable "Loaded Ubercart Order"
76.081 ms Action execution: "Execute custom PHP code" <-- this just logs the value of $uc_order_loaded
76.683 ms Warning: Unable to get argument "0".
76.721 ms Element "Send an email invoice" has not been executed. There are not all execution arguments available.
I've made the invoice action quite simple: it's sending to a fixed address and -- in further testing -- I switched to the standard customer template. I have no idea what 'argument "0"' is that the action is looking for. All I know is that the message is never sent.
What am I missing?
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | uc_rules-Fix_undefined_uc_order_argument-1280968-4.patch | 1.03 KB | Drave Robber |
| #2 | uc_rules-fix_order_variable-1280968-2.patch | 761 bytes | mrtoner |
Comments
Comment #1
mrtoner commentedAdditional info: I've created a simple rule to do two things:
- Load an existing order
- Send the inoice
It's triggered by viewing content, no additional conditions. All the arguments are the defaults, except for the order ID and the subject of the message. Here's the debug log:
0 ms "Content is going to be viewed" has been invoked.
0.51 ms Executing the rule "Troubleshooting" on rule set "Content is going to be viewed"
9.466 ms Action execution: "Load Ubercart Order by id"
130.581 ms Successfully added the new variable "Loaded Ubercart Order"
131.126 ms Warning: Unable to get argument "0".
131.164 ms Element "Sends the invoice email" has not been executed. There are not all execution arguments available.
131.22 ms Evaluation of "Content is going to be viewed" has been finished.
This is a bit frustrating.
Comment #2
mrtoner commentedI don't pretend to understand all of this. It took me a whole day to figure out some of what was going on and the issue was compounded by what appears to be a bug in Rules debug: the warning it should have been returning is "Unable to get argument 'uc_order'."
So after some more futzing around it appears I can get the "Sends the email invoice" action to work if the "uc_order_loaded" variable is renamed to "uc_order;" This now allows Rules to properly map this variable to the argument. Again, I only partially understand this; I don't know why the argument couldn't have been declared differently (so mapping wouldn't have to take place) or why the variable needs to be exposed to the user as form elements at all.
Given my incomplete understanding, this patch may not be appropriate; however, it changes the default variable name to be in line with what Rules is expecting to find. Users won't have to wonder why the action doesn't work or change the variable name as I did.
Comment #3
Drave Robber commentedI have confirmed this issue in a different context (was unable to change status of an order loaded by ID).
The proposed fix was good for it.
Comment #4
Drave Robber commentedHere's a git-compliant patch.
Note: this may break existing rules.
Comment #5
tinker commentedThe patches provided here fix the immediate problem of 'uc_order_loaded' argument not being passed properly but the reason this does not work is that 'uc_order' is not defined as a rules data type. I have created a new issue #2039405: Define uc_order rules data type, fixes tokens, add new order conditions conditions, split forms to new include file which fixes the root problem and many other issues.
Marking this as 'Closed (duplicate)' since the patches here provide a partial fix. Please review the patch provided in #2039405.