Adding a product to the cart gives me this error. I haven't got a clue where to put this...

Warning: call_user_func(rules_events_entity_unchanged) [function.call-user-func]: First argument is expected to be a valid callback in RulesState->get() (Line 148 of /sites/all/modules/rules/includes/rules.state.inc).

Line 148 would be:


$data = call_user_func($this->info[$name]['handler'], rules_unwrap_data($this->variables), $name, $this->info[$name]);

Comments

rszrama’s picture

Do you have any custom Rules on the site or additional contributed modules running?

brianlp’s picture

No custom rules only standard stuff that come with modules like currency, tax, Paypal WPS, Invoice, Flatrate, shipping etc. .

Contrib modules are

  • Commerce Email
  • Commerce Feeds
  • Commerce VBO Views
  • Invoice
  • Invoice Receipt
  • Invoice UI
  • Commerce Extra Price Formatters
  • Commerce Paypal
  • Commerce Shipping
  • Commerce Product Enhancements (Attributes, Budle)

The message shows every time the cart is changed, thus also if I change the amount of items in the cart or empty the cart.

Everett Zufelt’s picture

We are also getting this error on cart and checkout. We definitely have custom rules firing on those pages. I've only recently noticed the errors.

On cart update (when some custom rules fire) we get the error 3 extra times.

rszrama’s picture

Status: Active » Postponed (maintainer needs more info)

Ok, of the modules on the list, I've never used Email, Invoice, Invoice Receipt, Invoice UI, or Product Enhancements. Any one of those could be the culprit, so your best bet is to just disable them one by one and see when the error disappears. Then we'll know which queue to move this issue to. : )

brianlp’s picture

Now I have deactivated eveything possible and cleared cache inbetween. Nothing changed exept for additional messages due to missing components.

Back to Rules I did also some deactivation tryouts without any success.

Display an Add to Cart message
Set the currency price
Go to cart page after add to cart
Reset the cart order status on product add or remove

If I remove aproduct from the cart, the message gets displayed twice. I guess one for removal and one for "loading" the remaing one. What rule related action could that be?

Everett Zufelt’s picture

Status: Postponed (maintainer needs more info) » Active

The custom rule that is throwing this error executes on the order updated event.

The first condition is entityHasField (with a field that is on the commerce_order bundle of the commerce_order entity.

The second condition compares:

commerce-order:field-my-field

with

comerce-order-unchanged:field-my-field

When I remove that condition and replace it with my own Execute PHP condition where I do the comparison manually everything works fine.

Everett Zufelt’s picture

Possibly related, I'm also getting a Rules warning when I use a data comparison condition with commerce-order-unchanged:status

WD message: "Unable to evaluate condition data_is."

rszrama’s picture

Thanks for the follow-up, Everett. Any chance you can share the Rules in question or are they tied too intimately to custom elements on the site?

Everett Zufelt’s picture

Hi Ryan,

I can't send the Rule. I did do some more digging and found that the value of the two fields is empty.

Using a Execute PHP condition

print_r(var_dump($commerce_order->field_my_field));
print_r(var_dump($commerce_order_unchanged->field_my_field));
exit;

Each of the above statements returns an empty array. I suspect that since the fields aren't yet initialized that the Rules data comparison condition handler is throwing a warning when trying to evaluate. I haven't looked yet, but I suspect that I can resolve the error either by doing 2 additional data comparison conditions to check the value of each field prior to comparing to one another, or by doing the comparison completely in PHP, though I try to avoid that where possible.

I should work on this today, I will post the solution back to the issue when I do.

chriscalip’s picture

Error also sighted.

" Reacting on event After updating an existing commerce order."
0 ms Reacting on event After updating an existing commerce order.
13.715 ms Evaluating conditions of rule Delete shipping line items on shopping cart updates. [edit]
17.064 ms The condition data_is evaluated to TRUE [edit]
157.055 ms Unable to load variable commerce_order_unchanged, aborting.
198.2 ms Unable to evaluate condition data_is. [edit]
198.5 ms AND evaluated to FALSE.
198.836 ms Finished reacting on event After updating an existing commerce order.
" Reacting on event After updating an existing commerce order."
0 ms Reacting on event After updating an existing commerce order.
1.708 ms Evaluating conditions of rule Delete shipping line items on shopping cart updates. [edit]
3.289 ms The condition data_is evaluated to TRUE [edit]
5.225 ms The condition data_is evaluated to TRUE [edit]
5.269 ms AND evaluated to FALSE.
5.368 ms Finished reacting on event After updating an existing commerce order.
chriscalip’s picture

In my case i made a custom page; every time authenticated users come to it. it does some order update logic.

milekium’s picture

I had the same error, I’d modify the rule ""Delete shipping line items on shopping cart updates" with new condition on top for "NOT Path has URL alias: checkout/%/checkout" and the error disappear. I guess is not the better way, but I don´t think is needed to delete any shipping line items on the checkout page, any other page the rule still working ok.

Witch’s picture

Same error here! Dont know what this could be.

5n00py’s picture

Still have this issue.

I'm trying to check if some field changed after order save.

{ "rules_update_order_type_to_wholesale" : {
    "LABEL" : "Update order type to wholesale",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "order" ],
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : { "commerce_order_update" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-order" ], "field" : "field_type" } },
-->{ "entity_has_field" : { "entity" : [ "commerce-order-unchanged" ], "field" : "field_type" } }, <<-------
      { "data_is" : { "data" : [ "commerce-order:field-type" ], "value" : "wholesale" } },
      { "NOT data_is" : { "data" : [ "commerce-order-unchanged:field-type" ], "value" : "wholesale"  } }
    ],
    "DO" : [
      { "entity_save" : { "data" : [ "commerce-order" ], "immediate" : 1 } }
    ]
  }
}

I remove my custom action from DO section because its my own rules component.

Unable to load variable commerce_order_unchanged, aborting.
Unable to evaluate condition entity_has_field.

So problem located in IF section.

5n00py’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Component: Cart » Rules integration
Category: support » bug
finex’s picture

Hi, this bug is still reproducible with latest commerce, rules and commerce_shipping (tested with stable and -dev).

finex’s picture

Probably it happens because the commerce-order-unchanged doesn't exists until the order has been created, what do you think about?

JustBlackBird’s picture

Have this issue with commerce fees module.

5n00py’s picture

Yes, I think You are right. But anyway it need to be fixed, rules tell me that I have this value.
Just some check can solve issue. Or not ?

rszrama’s picture

If you're using this on the event "commerce_order_update", then this should only be triggered when an existing order is updated.

finex’s picture

By default the shipping module create the following rule which trigger this issue:

{ "commerce_shipping_cart_update_delete" : {
    "LABEL" : "Delete shipping line items on shopping cart updates",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_shipping", "entity" ],
    "ON" : { "commerce_order_update" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "cart" } },
      { "NOT data_is" : { "data" : [ "commerce-order-unchanged:status" ], "value" : "cart" } }
    ],
    "DO" : [
      { "commerce_shipping_delete_shipping_line_items" : { "commerce_order" : [ "commerce-order" ] } }
    ]
  }
}

Where should this bug corrected? Why there is a reaction on "After updating an existing order" when you visit /cart url even if the order has not yet been created? I think that rules module should check the availability of the order before triggering the rule.

What do you think about?

rszrama’s picture

Once you add a product to the shopping cart, an order is created. Drupal Commerce uses a full order object to model the shopping cart, so the unchanged entity should be present at that time.

finex’s picture

@Ryan, it should but it doesn't :-(

P.S: should #2108375: Rules Error Message be closed as duplicate of this bug?

StuddMan’s picture

Looks like lots of people having this issue. I found this post with a work around but there is clearly a problem with this rule.

https://drupal.org/node/2120421 - Warning: call_user_func() expects parameter 1 to be a valid callback, function 'rules_events_entity_unchanged' not found.

Note the patches jsacksick has loaded, maybe some how related to the patches:
http://drupal.org/files/d7_rules_are_lost_0.patch http://drupal.org/files/d7_rules_owner_recover.patch

We have those patches loaded as well to get our payment rules to show backup after upgrading to Rules 2.5. After applying the patches is when we starting having out logs fill up with this error.

rszrama’s picture

Hmm, do you have issues on previous versions of Rules? Because of bugs in Rules 2.4 / 2.5, I still haven't updated and am doing all of my testing / development still on Rules 2.3. That make a difference?

astutonet’s picture

I'm upgrading a production site on localhost.

I installed version 2.6 and I also have a problem in line 148 of the file rules.state.inc, but with a different message:

Warning: call_user_func() expects parameter 1 to be a valid callback, function 'rules_events_entity_unchanged' not found or invalid function name in RulesState->get() (line 148 of C:\wamp\www\mysite\sites\all\modules\rules\includes\rules.state.inc).

In the remote version, I'm using version 2.3 and I haven't errors.

For those using the Commerce module and derivatives, I remember that rules are overridden when we change the payment methods by entering personal information, so they are overriden rules.

Any ideas?

Tks.

rszrama’s picture

Ok, so it sounds like this actually may be an issue introduced in Rules 2.4 and beyond. Any other confirmations?

torgospizza’s picture

rszrama’s picture

Title: Checkout Error: Warning: call_user_func(rules_events_entity_unchanged) » Checkout Error: Warning: call_user_func(rules_events_entity_unchanged) (Rules 2.6 bug)
Category: Bug report » Support request
Issue summary: View changes
Status: Active » Postponed

Thanks for the connection, torgos. I'll go ahead and leave this issue open to point people there, but I'm not going to focus on it myself. We can close this out when Rules is fixed.

bojanz’s picture

I have resolved the problem and posted a patch to the Rules issue yesterday.

rszrama’s picture

Status: Postponed » Closed (duplicate)

Given bojanz's patch in the other and the discoveries in #2140165: While reloading $entity->original in the controller, track the save_depth, I'm going to go ahead and close this one out as a duplicate. In the event that multiple updates happen at once, your $order->original might be unset in the current scenario, though the issue I just linked has a patch that would prevent that from happening.