After adding product to cart, I got the error:
Fatal error: Unsupported operand types in commerce/modules/cart/commerce_cart.module on line 830
Reinstalling module, clearing cache, etc didn't help.
As I see in code, in this place there are string:
$data = $line_item_wrapper->commerce_unit_price->data->value() + array('components' => array());
If I do the debug, I see that $line_item_wrapper->commerce_unit_price have empty "data" array - krumo($line_item_wrapper->value()):

commerce_unit_price (Array, 1 element)
    und (Array, 1 element)
        0 (Array, 3 elements)
            amount (String, 3 characters ) 790
            currency_code (String, 1 characters ) R
            data (Boolean) FALSE

but if I do krumo($current_line_item_wrapper->value());, the data array isn't empty:

commerce_unit_price (Array, 1 element)
    und (Array, 1 element)
        0 (Array, 3 elements)
            amount (String, 3 characters ) 790
            currency_code (String, 1 characters ) R
            data (Array, 1 element)
                components (Array, 1 element)
                    0 (Array, 3 elements)
                        name (String, 10 characters ) base_price
                        price (Array, 3 elements)
                            amount (String, 3 characters ) 790
                            currency_code (String, 1 characters ) R
                            data (Array, 1 element)
                                components (Array, 0 elements)
                        included (Boolean) TRUE

Installing module on fresh install works normally, I can't reproduce issue on it, but I need to keep my orders and other data in current site. Where I must search and how I can solve this problem?

CommentFileSizeAuthor
#36 error.JPG65.15 KBTapendra Singh
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Ralf Eisler’s picture

I have the same error message here trying to delete a product.

msamavi’s picture

I have the same problem when trying to edit any content type.

Murz’s picture

I try to delete this product, create new product, but always got this error when adding product to cart.
Maybe because I have the custom currency:

 function mymodule_commerce_currency_info() {
  return array(
    'R' => array(
      'code' => 'R',
      'symbol' => 'р.',
      'name' => 'Рубли',
      'thousands_separator' => '',
      'decimal_separator' => '.',
      'decimals' => 0,
      'numeric_code' => '999',
      'symbol_placement' => 'after',
      'code_placement' => '',
      'minor_unit' => 'копеек',
      'major_unit' => 'рублей',
    ),
  );
}

But also I try to use only default currencies without my custom, this also don't solve the problem. What can I try more?

rszrama’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

Shouldn't have anything to do with your currency code. The big question here is how you all ended up with a FALSE value for data. It should be getting initialized to an empty array. Do you have any other modules or custom Rules on here interacting with prices?

Murz’s picture

Category: support » bug
Status: Postponed (maintainer needs more info) » Active

I try to install Shipping and Stock modules, but at now I disable and uninstall it, so at now there are only standard commerce module enabled, with standard rules.
At now there are enabled modules:

Cart
Checkout
Commerce
Commerce UI
Customer
Customer UI
Line Item
Line Item UI
Order
Order UI
Payment
Price
Product
Product Pricing
Product Pricing UI
Product Reference
Product UI
Commerce AutoSKU
Commerce Repair

Can you describe how I can debug the price data creating process? Or how can I reset all to default without removing products and orders?
In which file and function there are done generation process for this array? I can try to do the debug in it for find which operation adds false.

j_ten_man’s picture

Same issue here. A couple of things to note for me:
- I have 3 items in my cart. 2 of them were added before upgrading to the latest version of commerce.
- The 3rd item was added after.
- The 2 items that were added before work fine. In other words, the data array is there and no error is thrown.
- The 3rd item is the one throwing the error. Data value is null for me.

This leads me to believe that it's the adding to the cart that has caused the issue but I have no idea where to begin since I don't know how it used to work...

j_ten_man’s picture

All of my items added after upgrade have field_data_commerce_unit_price.commerce_unit_price_data equal to Array. In other words, prior to upgrade, I was getting a serialized array. Now it is just the word Array, meaning that for some reason it's not getting serialized on save...

j_ten_man’s picture

After stepping through this for some time, the problem has something to do with the way Drupal is delaying the database transaction. What I found was that the query to be run was correct (it has the serialized array as expected to be written to the database). However, between the time it writes that value and unserializes the data, it is changing what is written to the database. Anyways, by commenting out line 168 on commerce_price.module I was able to fix the problem. While this is not the correct solution to the problem, it has fixed it for me to allow users to checkout again.

// This function is called after db_write_record but before the transaction is completed/committed.
function commerce_price_field_attach_insert($entity_type, $entity) {
  //_commerce_price_field_attach_unserialize_data($entity_type, $entity); // line 168
}
rszrama’s picture

Hmm, yeah, thanks for the lead. I wonder if something has indeed changed in either Drupal itself or the execution of our insert / update hooks to screw up the order of serialization / unserialization. I can say with certainty that there are no issues on a vanilla install - i.e. Commerce by itself - so maybe there's an API change that other modules aren't taking into consideration or something. : ?

chrisjlee’s picture

+1 having same issue this happens when just adding a product to the cart. I'm getting a fatal error:

Fatal error: Unsupported operand types in /home/chris/xxx/sites/all/modules/contrib/commerce/modules/cart/commerce_cart.module on line 830

A lookup on that page brings up where the failure exists if i comment the whole else statement (below) the issue doesn't occur anymore. I don't get a fatal error:

<?php
    else {
      // Compare the refreshed unit price to the original unit price looking for
      // differences in the amount, currency code, or price components.
      $data = $line_item_wrapper->commerce_unit_price->data->value() + array('components' => array());
      $current_data = $current_line_item_wrapper->commerce_unit_price->data->value() + array('components' => array());

      if ($line_item_wrapper->commerce_unit_price->amount->value() != $current_line_item_wrapper->commerce_unit_price->amount->value() ||
        $line_item_wrapper->commerce_unit_price->currency_code->value() != $current_line_item_wrapper->commerce_unit_price->currency_code->value() ||
        $data['components'] != $current_data['components']) {
        // Adjust the unit price accordingly if necessary.
        $line_item_wrapper->commerce_unit_price->amount = $current_line_item_wrapper->commerce_unit_price->amount->value();
        $line_item_wrapper->commerce_unit_price->currency_code = $current_line_item_wrapper->commerce_unit_price->currency_code->value();

        // Only migrate the price components in the data to preserve other data.
        $data['components'] = $current_data['components'];
        $line_item_wrapper->commerce_unit_price->data = $data;

        // Save the updated line item and clear the entity cache.
        commerce_line_item_save($line_item_wrapper->value());
        entity_get_controller('commerce_line_item')->resetCache(array($line_item_wrapper->line_item_id->value()));

        $line_item_changed = TRUE;
      }
    }
?>

Finally, i narrowed it down to just 830. If i comment out this line:
<?php // $data = $line_item_wrapper->commerce_unit_price->data->value() + array('components' => array()); ?>

The fatal error stops occuring.

But i'm also getting this error before

Notice: Array to string conversion in DatabaseStatementBase->execute() (line 2139 of /home/chris/xxx/html/includes/database/database.inc).

But that's a different issue and is apparently solve-able via this issue: #1253114: Notice: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes

chrisjlee’s picture

Finally, I did some var_dump'ing and revealed the following (hope it this helps i'm pretty unfamiliar with this process):

<?php
// ... line 826
    else {
      // Compare the refreshed unit price to the original unit price looking for
      // differences in the amount, currency code, or price components.
      var_dump($line_item_wrapper->commerce_unit_price->data->value()); // returns false
      var_dump(array('components' => array())); //  returns: array(1) { ["components"]=> array(0) { } } 
      $data = $line_item_wrapper->commerce_unit_price->data->value() + array('components' => array());
      $current_data = $current_line_item_wrapper->commerce_unit_price->data->value() + array('components' => array());

//.. line 833 ?> 
rszrama’s picture

Out of curiosity, does running with this patch solve this for you?

#1253114: Notice: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes

You'd likely need to remove the items from the cart and try to produce the error again.

j_ten_man’s picture

@rszrama That patch does not fix the issue. It's still saves "Array" into the database and not the serialized array.

What type of pricing rules do people have? My only other thought is that this might be causing it. I have two rules that add a tax to the product price. Maybe this is causing the issue?

chrisjlee’s picture

Sorry i guess fatal cart error was fixed when i patched #1253114: Notice: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes.

batigol’s picture

Same here:

Fatal error: Unsupported operand types in \sites\all\modules\commerce\modules\cart\commerce_cart.module on line 830

After:
adding product to a cart (/cart),
trying to delete product,
trying to edit content type with the products display,
and when editing menu items (views path).

batigol’s picture

Priority: Normal » Major

Patch from http://drupal.org/node/1253114 does not fix this issue for me.

EDIT: I honestly don't know WTF is going on but after server restart everything seems to work fine... I DID update.php (no database upgrades) and clear cache after install commerce module but it wasn't enough then. Now everything is working like it should from the beginning.

EDIT2: Again I have this issue. There are probably some dependencies but I don't see any.

Store/Orders/Shopping [admin/commerce/orders] carts give me this error.

kelutrab11’s picture

Fatal error: Unsupported operand types in commerce\modules\cart\commerce_cart.module on line 830 got it all the time after install commerce module (with shipping, stock, paypal modules). Actually this could be critical. Cause it makes commerce completely unusable/broken. Above patch don't fix the issue.

henrix34’s picture

Same error here. After disable and enable commerce modules I can add products to the cart.

Store/Orders/Shopping [admin/commerce/orders] carts give me this error.

This is the only place I get this error now.

rszrama’s picture

Hey guys, we can't really escalate this beyond major because there's no set way to reproduce it. In other words, it may just be a module conflict or edge case configuration that results in the error. I'll commit the patch referenced above soon, and I wonder if people trying the patch are not realizing that the patch does not include an update process. In other words, you may need to resave the products that have invalid price field data arrays so they are no longer throwing this error. If it then works, then the patch is what's needed, and we should try harder to get an update function in place for it.

That said, I still have not been able to reproduce this error. I see several people +1'ing this, but everyone seems to have a different way of getting to the error. Can someone please list all the steps you would take from installing with Commerce Kickstart on to produce the error? Without that, I can't really take this any further.

If you're having issues disabling / re-enabling Commerce, first I'd say not to do that, and then second I'd say there's another issue that discusses changes to prevent that from malfunctioning... but I may have already committed it to -dev. : P

Murz’s picture

Priority: Major » Normal

rszrama, I send you full access to my test site, files and database for debugging this issue and "how to reproduce", hope it helps find problem.

henrix34’s picture

I have updated my site to 7.12 and all modules the site is using to latest stable releases. Install commerce and it's needed modules + paypal, stock, shipping. After enabling it, run database update (no changes), run cron, clear cache, rebuild permissions, restart server, and set only the basic things like enable example shipping plugin, enable PayPal WPS, add simply VAT tax rate and add some basic products.

After all this I couldn't add an item to cart... After re-enabling commerce modules I was able to do it. But as I said:

Store/Orders/Shopping [admin/commerce/orders] carts give me this error.

I can't get to it cause Fatal error: Unsupported operand types in commerce\modules\cart\commerce_cart.module on line 830

Re-saving nodes/product is not working.

I will check this on clean commerce kick-start install, however I have disable all my site modules besides commerce and still have this error. The next step will be to check it with commerce 1.1... As you can see there is nothing unordinary.

j_ten_man’s picture

Also using the stock module here and getting this issue. Maybe it's the cause somehow...

Murz’s picture

Because too hard to find the way how to reproduce this issue on fresh install, I think that better is to provide for Commerce Developer ftp, mysql and site admin accesses on test site, they can debug this error on working site quicker that find an non-reporoducible on fresh install bug :)

henrix34’s picture

@Murz I agree. Cause commerce is completely unusable now. I don't know whats going on but now I can't even display views with product and not getting this error... Wherever there is something to do with product I get this error. It is strange cause I could browse products before. I did absolutely nothing, not even one change... and now I can't browse my site... Magic :)

EDIT: /admin/structure/types/add is not working. I can't add content type - how can this be related with commerce ?

rszrama’s picture

Are you all using the Stock module then? If so, what versions?

Murz’s picture

rszrama, I try both versions of Stock module - 7.x-1.0-rc1 and 7.x-2.x-dev, but try to disable and uninstall it, but this isn't help.

slavosek’s picture

SOMEONE solve this problem??

j_ten_man’s picture

Using Stock 7.x-1.0-rc1

slavosek’s picture

Thanks for the advice, this is the result : Fatal error: Unsupported operand types in /home/www/transylvania-nabytek.cz/subdomeny/www/sites/all/modules/commerce/modules/cart/commerce_cart.module on line 830
Notice: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes ve funkci commerce_price_field_load() (řádek: 88 v souboru /home/www/transylvania-nabytek.cz/subdomeny/www/sites/all/modules/commerce/modules/price/commerce_price.module).

rszrama’s picture

@slavosek - It can't be solved until it can be reproduced from scratch. It looks like Stock may be the issue... are you using the Stock module? If so, have you tried the patch linked above to solve the problem?

Murz’s picture

@rszrama, I have disable and uninstall Stock and Shipping modules on site http://test2.caramba-nn.ru/ to which I send you access, did you receive passwords via mail?
This is test site special for you, you can reproduce this error on page http://test2.caramba-nn.ru/node/33 after clicking "Add to cart", also you can debug, upgrade, reinstall, and broke anything in it :)
I want help to debug this issue, but don't know how, please tell me how I can help.

Issue is reproducible in my site on rendering Cart block after I add product to it (as anonymous user too). If I hide Cart block, it reproducible on Cart page.

Also I try patch from #1253114: Notice: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes but it isn't solve the problem.

I don't know how to reproduce it on fresh install, so better is to do some breakpoints, print_r, look on database and do other debug things in working site with reproducible error instead of trying to find the way for reproduce it.
If we found the source of the problem, will be easier to reproduce it on fresh site.

no2e’s picture

I got this error after deleting an order in /admin/commerce/orders/carts.
Now I can't visit /admin/commerce/orders/carts again: it's a white screen with this error message.

Have no Stock installed.

("fixed" it by deleting all orders from the database)


---

Btw, related (same?) issue:
#1433438: Filefield Pathss 7.x-1.0-beta3 and Drupal Commerce (/edit: ah, already marked as duplicate)

rszrama’s picture

You got the same error message on the Shopping Carts View? This is indeed exceeding strange... there's nothing special about that. What other modules do you have enabled if not stock?

no2e’s picture

You got the same error message on the Shopping Carts View? This is indeed exceeding strange... there's nothing special about that.

After I deleted a shopping card order, yes. Doesn't happen again, now. If it will, I'll open an issue or update this here. I patched Commerce Price (because of other error messages), if it matters.

cancel.allow’s picture

I got same error after adding item to shopping cart. Can't access to pages with shopping cart block and to shopping cart page at all. After removing shopping cart block pages become accessible except shopping cart page.

Very strange error because i've already tested order with flat rate shipping and everything worked just fine. After this testing was installed filefield path module, but didn't configured it. Uninstalling module didnt solve an error.

System Commerce Kickstart 1.3 core (Modules: Views, Commerce, Commerce Multicurrency, Commerce AutoSKU, Shipping + Flat Rate, Physical Fields (dev), Imagecache Actions, i18n, EVA, Views Slideshow).

Tapendra Singh’s picture

Issue tags: +bug, +add to cart, +Commerce (duplicate)
FileSize
65.15 KB

I am also facing same error while developing the site. I have tried by enabling and disabling the commerce module. Cleared so many times cache of my drupal site. I have also upgraded all the modules of commerce and tried to resolve this error but I did not get success. I have also removed the products existing one and created new one's but I faced same error on site.I have attached the jpeg of error which i am facing right now. Is there anyone having solution to resolve this ?.

Murz’s picture

The problem is that line_item created on "add to cart" process added without data object.
Seems that this issue is related to Filefield Paths module, because if I disable it on my site, the problem is disappear.
For disappearing the problem you must disable Filefield Paths module, clear cookies (for remove link to current cart content), after that error message must be go away. And if you try to add product to cart again, all goes to work normally.
Other followers, please check if you have Filefield Paths module enabled, try described method and report here.

j_ten_man’s picture

Also using Filefield paths. Don't have time to test right now. Will try to do so later.

ging74ru’s picture

#37 works!

rszrama’s picture

(See also the related issue linked in comment 32 above.)

j_ten_man’s picture

#1253114: Notice: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes does in fact fix the issue for me. I didn't clear my cache after applying the patch previously.

To fix the issue:
- Apply http://drupal.org/node/1253114#comment-5497816
- Flush caches

rszrama’s picture

Ok, great. I'm reworking that patch and want to get an update function in and will post it asap - hopefully this evening. If we can get another confirmation, let's close this one out as a duplicate.

no2e’s picture

If we can get another confirmation, let's close this one out as a duplicate.

I use Filefield Paths and have applied this patch → no problem for me.

rszrama’s picture

Status: Active » Closed (duplicate)

Wonderful, let's go ahead and mark this a duplicate then. The rework of the patch will keep the same logic but just use two separate API functions instead of a single generic "prepare" function. It should include an upgrade path, too, that simply clears out illegitimate data columns.

Murz’s picture