I keep getting rules logging errors whenever I create a conditional tax rule. The errors are as follows:

(1) Unable to evaluate condition commerce_order_compare_address.
(2) The variable or parameter commerce_order is empty.

I followed the suggested setup here for setting up conditional rules based off of the address. (http://www.drupalcommerce.org/node/454).

When I don't have a session for commerce is puts these errors into the log as soon as I add something to the cart and create the session it stops.

Attached is the comparison rule i was using

Comments

afoster’s picture

I noticed this one too - subscribed

rszrama’s picture

Category: bug » support

Do you get these errors when you update to Entity API 1.0-beta11 and Rules 2.0?

rszrama’s picture

Status: Active » Postponed (maintainer needs more info)

I'm going to need more information to be able to help here. Can you export the Rule and post it in here?

invisibleink’s picture

I'm having the same issue, but it only happens when the address comparison is based on Shipping address. It works fine with billing address components.
I hope that helps find the source of the error.
Thanks!

rszrama’s picture

Please export the rule as I said above. I can't debug it without seeing the whole thing.

erichomanchuk’s picture

Here is the export of the rule:

{ "commerce_tax_rate_gst" : {
"LABEL" : "Calculate GST",
"PLUGIN" : "rule",
"REQUIRES" : [ "commerce_order", "commerce_tax" ],
"USES VARIABLES" : { "commerce_line_item" : { "type" : "commerce_line_item", "label" : "Line item" } },
"IF" : [
{ "commerce_order_compare_address" : {
"commerce_order" : [ "commerce-line-item:order" ],
"address_field" : "commerce_customer_billing|commerce_customer_address",
"address_component" : "administrative_area",
"value" : "CO"
}
}
],
"DO" : [
{ "commerce_tax_rate_apply" : {
"commerce_line_item" : [ "commerce-line-item" ],
"tax_rate_name" : "gst"
}
}
]
}
}

erichomanchuk’s picture

StatusFileSize
new56.27 KB
new48.17 KB

I just tried it again today when I create a new tax and configure the component to apply the tax rate on the address component using the administrative_area (state/province) when a anonymous user, a user with no session, views a page of the site it adds these warnings to the logs.

rules 11/10/2011 - 12:33 Unable to evaluate condition commerce_order_compare... Anonymous (not verified)
rules 11/10/2011 - 12:33 The variable or parameter commerce_order is empty. Anonymous (not verified)
rules 11/10/2011 - 12:33 Unable to evaluate condition commerce_order_compare... Anonymous (not verified)
rules 11/10/2011 - 12:33 The variable or parameter commerce_order is empty. Anonymous (not verified)

When you do add a product to your cart it does go away. Its just that I created all these rules for GST, PST, HST for Canada so I get like 50 of these messages in the log files every time a user with no session looks at a page, so my log files are long. Its not effect my site at all.

Also I noticed today as well when adding a new tax that I didn't get the "configure component" action, it did show up when I added another tax but the new taxes "configure component" action was missing. Attached is a screenshot showing how PST is missing "configure component" action and another screenshot showing how after adding a new tax HST, the "configure component" shows up for PST.

rszrama’s picture

Status: Postponed (maintainer needs more info) » Active

Oooh, I bet I know the problem. I'll do some testing with a cartless anonymous session, too. I'm guessing all my testing of that condition involved users with carts because I knew that's what I was looking to test, but without a cart it is apparently receiving an empty order object.

rszrama’s picture

Status: Active » Needs review
StatusFileSize
new1.25 KB

Alrighty, finally figured it out. What threw me off in the other reports is that you're only seeing these notices in the recent log messages. I never saw them on screen as error messages, so I assumed there was something about the environment causing the problems. It is as I mused above - newly created line items that did not have an order ID set (such as when a user didn't have a cart order, whether you were authenticated or anonymous) resulted in an empty value being passed to the various hooks for the Order.

It was simple enough to fix; in both the line item and payment transaction getter callbacks for their order_id properties I've added a check to see if order_id is empty before returning it. If it is, we return a new order object instead. Let's see what the test bot has to say about this approach.

rszrama’s picture

Status: Needs review » Fixed

Alrighty, committing this. I'm pretty sure there are related issues in the queue that this resolves, but I'll be darned if I can find any of them. I was just talking with someone about in IRC today, even. It's a mystery. If anyone knows of related issues reporting Rules log spam, please mark them duplicate and link to this issue.

erichomanchuk’s picture

Thank you very much, i will try the patch.

erichomanchuk’s picture

problem solved, Thanks Again.

rszrama’s picture

Awesome, glad to hear it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.