* Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\xampp\htdocs\drupal\includes\entity.inc).
* Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of C:\xampp\htdocs\drupal\includes\entity.inc).
* Recoverable fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2039 of C:\xampp\htdocs\drupal\includes\database\database.inc).

Look attachment

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

Title: Drupal Commerce Bug » Add to cart: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load()
Project: Drupal core » Commerce Core
Version: 7.0 » 7.x-1.x-dev
Component: base system » Product reference
Assigned: alexpua » Unassigned
PieterDC’s picture

Status: Active » Postponed (maintainer needs more info)

Which version of the Views module are you using?

Are you using the latest dev version of the Views module? ... as mentioned in #1012888: Error adding products to a order in cart status

alexpua’s picture

Views 7.x-3.0-alpha1
Drupal 7.0

alexpua’s picture

Status: Postponed (maintainer needs more info) » Active
PieterDC’s picture

Could you try updating your Views module to 7.x-3.x-dev
and report if that fixes your problem?

alexpua’s picture

FileSize
26.27 KB

Problem did not fixed
I have tried two combination:
- drupal 7.0 + Views 7.x-3.x-dev
- drupal 7.x-dev + Views 7.x-3.x-dev
result is same, look attach

Haza’s picture

Had the same error here.

Using lastest dev release of commerce and views seems to fix it.

rszrama’s picture

Status: Active » Needs review

Hmm, those errors could have been a Views bug in alpha1 that was fixed, but they also come from the Entity module. That's what causes the problems for me when I get them, anyways... has to do with an invalid load request using objects instead of IDs.

It looks like your problem may stem from not having the proper version of Drupal Commerce's dependent modules. Per the installation instructions on the project page, you need to use the dev versions of all the dependencies. e.g. Views 3.x-dev, Entity 1.x-dev, Rules 2.x-dev. Update all your dependencies and try again, and then if it still doesn't work I'll need you to attempt an installation with the Commerce Dev installation profile - that's what I use to build test sites, and I don't get any problems on Add to Cart atm.

alexpua’s picture

Status: Needs review » Fixed

First change core and views:
-Views 7.x-3.x-dev
-Drupal 7.x-dev
but the error remained
After change Entity API from 7.x-1.0-beta6 to 7.x-1.x-dev bug fixed
Thank you!!!

PieterDC’s picture

You're welcome

rszrama’s picture

Excellent. Always check the installation instructions on the project page, as I keep them up to date with the current working versions of dependencies for either our latest point release or the current dev release.

thersitz’s picture

Just loaded drupal 7 -- upgraded from a fresh 6.20 install on my host. When I select add content I get this error. I have views installed but do not have commerce or entity api installed. A minute ago I attempted to add content again and the error did not appear. So in a matter of minutes it appeared and then did not.

Bèrto ëd Sèra’s picture

I confirm the error and I also confirm that installing from the commerce profile and using the master modules from git solves all problems (possibly time to make a new alpha release for those using the modules from the drupal site, though)

Status: Fixed » Closed (fixed)

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

sun-fire’s picture

Status: Closed (fixed) » Active

The same warning messages with:

Core: 7.9
Commerce: 7.x-1.0
Views: 7.x-3.0-rc1
Entity API: 7.x-1.0-rc1

When i try to execute this code:

 global $user;
 $order = commerce_cart_order_load($user->uid);

I recieve the list of warnings:

Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /home/www/somesite/includes/entity.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of /home/www/somesite/includes/entity.inc).

for each line item. (For examle, I receive 4 warnings for two different products in the cart).

When the cart is empty the same code return results with no warnings.

khiminrm’s picture

subscribe

rszrama’s picture

Do you get the error on 1.x-dev? There have been almost 90 commits since 1.0, so this may have been fixed since then. I haven't done any complete testing w/ Entity API 1.0-rc1, but I wouldn't expect there to be a break between then and now.

sun-fire’s picture

I get the same error for the latest dev version of commerce.

rszrama’s picture

Are you using any contributed modules in addition to Commerce?

tscadfx’s picture

I'm getting the same error as well with Commerce Custom Line Items in use.

rszrama’s picture

Category: bug » support

Do you get the same error without that module in use? Someone needs to help narrow this down, so feel free to post some research so I don't have to keep asking follow-up questions. : D

Murz’s picture

I have the same problem, I use commerce dev version, commerce_stock 2.x, commerce_shipping 2.x.
I debug the problem and find that in includes/entity.inc line 177 Drupal try to do array_flip of
array ( 0 => array ( 'product_id' => '6', ), )

Murz’s picture

I have found the problem and solve for me: I use function

   $order = commerce_order_new(NULL, 'pending');

but this is wrong, I change it to $order = commerce_order_new(0, 'pending'); and warning go away.

rszrama’s picture

Ahh, nice. Where was that code located? That definitely needs to be fixed, as NULL is not a valid uid but 0 is (for the anonymous user).

Murz’s picture

This code is in my module, I do the wrong function call, module works normally.

rszrama’s picture

I gotcha. Maybe it's something we can look out for in other modules or Rules then.

Pedro Lozano’s picture

This can be fixed by adding a validation criteria to the "Order ID" argument of the "Shopping cart form" view to check that the argument is numeric.

The problem happens when you create a block using this view to display the cart and you change the contextual filter to have a default value to the current users' order id.

The default argument handler returns FALSE if the user still doesn't have an order in the commerce_order table.

By adding a validation setting to make sure it is numeric we avoid a call to entity_load('commerce_order', array(FALSE)) and we keep this warning from appearing.

Pedro Lozano’s picture

Status: Active » Needs review
Pedro Lozano’s picture

Added the same fix to other views that need it.

DamienMcKenna’s picture

Looks good, anyone else to review it so we can make this RTBC?

Umayal’s picture

Title: Add to cart: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() » I also have this proplem

I used
Core: 7.10
Views: 7.x-3.0-rc1
Entity API: 7.x-1.0-rc1
and
Core: 7.10
Views: 7.x-3.x-dev
Entity API: 7.x-3.x-dev

When i load the user,I get same error.
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /......./includes/entity.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of /........./includes/entity.inc).

I don't know what is the problem?

Pedro Lozano’s picture

Title: I also have this proplem » Add to cart: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load()
Umayal’s picture

Title: Add to cart: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() » I remove flip error.

I removed flip error
It's my code problem not module or core versions.

Haza’s picture

Please keep the title.

rszrama’s picture

Title: I remove flip error. » Add to cart: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load()
Issue tags: +1.3 review

Tagging.

helior’s picture

Status: Needs review » Postponed (maintainer needs more info)

Sigh. I'm having a really hard time replicating this issue. I basically keep following Pedro's steps from #27, but to no avail. Has anyone been able to reproduce this on a fresh install of Drupal Commerce? The patch is about 3 months old, so maybe there's a chance that the underlying problem has been fixed by a previous commit. If someone can leave some steps to reproduce on a fresh install of Commerce, I'll be happy to review it so we can get this committed in the next point release.

Murz’s picture

helior, you can reproduce this error via creating new order via API with Order ID = NULL (not 0).

rszrama’s picture

Status: Postponed (maintainer needs more info) » Fixed

Ok, I was able to reproduce it by clearing out my cart order, adding a page display to the cart form View, and updating the Order ID argument to provide a default value using the user's current cart order ID. Visiting the path for the View results in the error, because the argument was returning a FALSE when no order ID was found, which is invalid for commerce_order_load(). Instead of the fix suggested above, I've patched the handler to return an explicit 0 instead of FALSE if it cannot find a current cart order ID. Because that appears to fix the issue at a closer level than Views configuration, I'm going to go ahead and mark this fixed.

However, in my testing, I turned up a little disturbing discovery. Basically, because we're depending on a contextual filter, I don't see any way to not allow users to throw in any random order ID they want to try in that form. And then if they have access to the order - such as an order they just placed - they'd be able to update its contents. Granted, using the shopping cart form to update its contents would then remove it from the pending / complete orders list and make it a shopping cart again, but it's still a hack (albeit a silly one, because now you've paid money and won't get your product).

I'm wondering, does anyone who's using this have a strategy to prevent people from adding an Order ID to the URL? What I mean is, if I add a page View to the shopping cart form at /my-cart and update the argument like I said above (to validate using the current cart order ID in the absence of a URL provided argument), how can I prevent the URL /my-cart/123 from showing the shopping cart form for order 123.

Also, testing shows me that even though we determined we should implement #1030128: Convert shopping cart block and form Views to use Views block / page displays in a contrib module, we should still put into core the form altering that prevents buttons from showing on an empty shopping cart form. Otherwise even though a user may not be able to see the line items on other peoples' orders, they could still submit the form and potentially jack up their order statuses.

rszrama’s picture

And wow, this issue has been open for 16 months! Glad it's closed now. : )

Commit: http://drupalcode.org/project/commerce.git/commitdiff/8ba3ecc

Status: Fixed » Closed (fixed)

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

MGParisi’s picture

Status: Closed (fixed) » Active

Just got it when running CRON, Not the exact error, but the same line number on the first warning

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of /home/mgparisi/public_html/includes/entity.inc).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /home/mgparisi/public_html/includes/entity.inc).
rszrama’s picture

Status: Active » Closed (fixed)

Are you sure you're having the same issue? This issue is for the error as produced by a Views argument handler, and unless you aren't running Commerce 1.3 I don't know how you can still be getting it.

ljgra’s picture

Used the patch, problem still on (even if this post was years ago)...