With the latest -dev version of Entity module these errors appear when adding a product in a order which is in cart status:

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 179 of /webs/drupalcommerce/includes/entity.inc).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 355 of /webs/drupalcommerce/includes/entity.inc).
Recoverable fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2039 of /webs/drupalcommerce/includes/database/database.inc).

Tested with latest dev version of drupalcommerce (Ryan's branch) and also with alpha4.

It seems that the problems are located in the commerce_cart_commerce_order_presave invoke:

  $wrapper = entity_metadata_wrapper('commerce_order', $order);
  // Get the order directly from the database and compare with the current one.
  $unchanged_order = reset(commerce_order_load_multiple(array($order->order_id), array(), TRUE));
  $unchanged_wrapper = entity_metadata_wrapper('commerce_order', $unchanged_order);

The errors appear as well when changing an existing order to "Shopping cart" status or adding product line items to an existing order already shopping cart status.

CommentFileSizeAuthor
#3 1012888.line_items_list.patch1.42 KBrszrama

Comments

bellHead’s picture

Component: Order » Cart

I believe that #1013428: EntityListWrapper::value() lacks support for fully loaded entities is the cause of this issue.

Not marking this duplicate quite yet since it may still be expected behaviour on Entity's part and a fault in Commerce.

rszrama’s picture

I can confirm the issue, but I'm at a loss as to where the fix will come in. It seems to be a result of changes in entity.wrapper.inc, but that could be a red herring. Reverting that file to revision 1.1.2.2 made the errors disappear, so we'll see what fago says next. : )

rszrama’s picture

Status: Active » Needs review
StatusFileSize
new1.42 KB

Ok, this patch seems to fix the problem... running it by fago and doing some Rules testing.

rszrama’s picture

Status: Needs review » Fixed

Alrighty, I fiddled with this in Rules and could iterate the list just fine. I'm marking this fixed with the commit of that patch above, and I'll play with it some more to see if we really even need to define the line_items property ourselves.

pieterdc’s picture

Status: Fixed » Needs review

Your patch fixes the error of this issue, but it also removes the code I helped to introduce to fix #979846: Rules line items list
Sadly, but logically, your patch reintroduces the "conflict" between line items and the Rules module.

So, either this or the other issue needs reopening, I guess.

rszrama’s picture

Ahh, poo... I hoped it would be a clean fix, but I knew we had just added that code in for some reason not too long ago. This patch was based on fago's comments in #1013428: EntityListWrapper::value() lacks support for fully loaded entities ... but you know, after our chat this afternoon, I wonder if the solution isn't to just remove this code entirely and instead require an "Entity has field" condition to add the line item list to the data selector. I think that might be what fago was referring to in some of his comments in that other issue.

rszrama’s picture

Status: Needs review » Fixed

As far as I can tell, my hunch in #6 is right... I've removed the line_items array from the order property info definition. Line item data can be properly accessed and modified via Rules and the Entity Metadata Wrapper now. For Rules you just have to use the "Entity has field" condition or check the bundle type.

For more information, refer to my comments at http://drupal.org/node/1015574#comment-3918438 and http://drupal.org/node/1013428#comment-3918450.

elvis2’s picture

Status: Fixed » Needs work

If you remove the $properties['line_items'] array in commerce_order_entity_property_info() AND the switch case for 'line_items' in commerce_order_get_properties(), the cart does work. But, I am now getting this error:

'Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column \'commerce_line_item.line_item_id\' in \'field list\''

in views_plugin_query_default->execute() (line 1314 views/plugins/views_plugin_query_default.inc).

Is this strictly a views issue?

elvis2’s picture

Status: Needs work » Fixed

Nevermind, the latest views 7.x-3.x-dev fixed this issue with #6 fix. There is no need to remove the switch case for 'line_items' in commerce_order_get_properties()

pieterdc’s picture

Yay!

Status: Fixed » Closed (fixed)

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