Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Price
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
18 Aug 2011 at 13:27 UTC
Updated:
19 Jul 2019 at 11:32 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
rszrama commentedI'll need more information to debug this. Is there anything I should know about the way you're using price fields? I've never had a problem clearing the cache before...
Comment #2
kratkar commentedI have 2 field price. Maybe because of this?
Comment #3
rszrama commentedHow is the second one setup?
Comment #4
BenK commentedSubscribing
Comment #5
BenK commentedI'm experiencing this issue and I don't have two price fields... just a single one.
@kratkar: Do you happen to be using the Display Suite module and its custom view modes? I am and I'm wondering if this could be related.
--Ben
Comment #6
kratkar commented@BenK Do not install this module.
I cleared all the data modules (admin/modules/uninstall) problem has been resolved. Modules uninstall: Product Attributes, Commerce Delivery, Features, Payment, Payment UI.
Now added another field to the node, where installed product reference. I entered value and clear cache - this message appears.
add dvm:
Result http://ubuntuone.com/p/1Bhw/
I do not know it would help.
Comment #7
rszrama commentedHmm, I see in your debug message where unserialization is partially happening... I haven't had problems with multiple fields before.
@kratkar, I couldn't tell from your reply to BenK, are you saying you're not using Display Suite?
Comment #8
kratkar commented@rszrama I not using Display Suite
Now install drupal separately and will be installing modules and check.
Comment #9
kratkar commentedNot yet installed the modules.
But here's what did:
Output:
First "Array"!
Check this:
Notice did not appear.
Comment #10
bendiy commentedI'm getting this same error. We have an import modules setup that pull products from another database and creates them in Drupal Commerce. It then creates product nodes. I have three price fields. I get this error at Store > Products > List after an import. Making the change in #9 appears to have fixed it.
Comment #11
rszrama commentedHmm, the problem, though, is that it should never have attempted to write the "Array" to that column without first serializing it. The change in #9 just hides the issue... the real issue is we need to ensure every price field data array is properly serialized on save. We'll need to find the common denominator in your three scenarios.
Are you all using some sort of import routine or creating your products / nodes and price data through the UI?
Are you all getting this problem with price fields on nodes?
Comment #12
bendiy commentedUsing Eclipse and xDebug, this is what my $item variable looks like for one item:
There are a few hundred items it loops through that all look like that.
Comment #13
bendiy commentedI also get the error if I have an item in the cart and the cart block on every page. If I Flush All Caches, when the page loads, I get the error. Here's the $item array for the cart:
Comment #14
sreynen commentedI saw this error with products I created in code where I didn't set the price field at all.
Comment #15
bendiy commentedMy price field is set for my products. I'm using the default price field and 3 additional ones that were added. Not all of the additional price fields have a value in them. Maybe that's the issue?
I upgraded my site yesterday to the new Drupal Commerce 1.0, all suggested versions of the required modules for Drupal Commernce (Ctools, Rules, etc) and moved to Drupal 7.8. I'm not getting the error any more.
Can anyone else confirm upgrading fixes their errors?
Comment #16
thesurfinganalyst commentedNot sure if this is related, but I'm using devel-generate to create content product nodes that have a price field. Note: I'm not generating products, but nodes that have product references.
Using devel-generate to receive the following notice:
When I view the generated nodes I receive the 'Notice: unserialize'.
Comment #17
carn1x commentedI am getting this error after running import from CSV through Commerce Feeds, seemingly 1 instance of the error for each imported product.
If I remove all the imported products, and keep only manually entered products, all the errors go away.
Wasn't getting the issue at all before hand.
I am storing 5 different price fields if that makes any difference?
Comment #18
wojtha commentedI'm just debugging that... found this
INSERT INTO field_revision_field_course_fee_concession (entity_type, entity_id, revision_id, bundle, delta, language, field_course_fee_concession_amount, field_course_fee_concession_currency_code, field_course_fee_concession_data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8_components)Notice the :db_insert_placeholder_8_components key, it contains empty array - "Array[0]".
I suspect the filefield_paths module since I had bit similar kind of problems (messed up node object) in Drupal 6 half year ago and filefield_paths was the principal offender. It is because filefield_paths module needs tokens for paths replacement so during node save it loads node object again and node object is being modified by this process because it is passed by reference. The second thing is that this module itself invokes node update hook so the data flows in a bit different way and some parts of the usual node/field update process is bypassed.
Stack when saving the invalid data just before DB exception is going to be thrown:
Comment #19
wojtha commentedSo I disabled the suspect - filefield_paths but still experiencing this bug.
I found that the data are saved twice during the node_save(). Here is node update lifecycle with important stages in bold:
So in short:
Comment #20
wojtha commentedAnd the winner is ... Drupal Commerce! :-)
These two functions unserialize the price during node insert/update lifecycle.
Comment #21
wojtha commentedThinking about workaround... but it is not easy. Node object is shared across all node and field hooks so if we made change such as the serialization, the change is global.
The conflicting modules are e.g. Filefield Paths
or Workbench Moderation
The given chunks of code could be IMHO fixed by calling node_presave() or field_attach_presave() before calling field_attach_update().
Question is if it is the right approach and if is Commerce issue or Drupal core issue or the conflicting modules issue...
Comment #22
5n00py commentedAny working solutions?
Comment #23
adroid commentedSubscribing
Comment #24
sixelats commentedI've altered the if statement in line 84 of commerce_price.module with the code from #9
if (!empty($items[$id][$delta]['data']) && $items[$id][$delta]['data']!='Array') {and haven't seen the error since. Also, everything about prices seems to work fine but it's not on a live site.
Comment #25
mr.baileysIt might be a long shot, but since the errors seem similar, try and see if the patch from #1403140: Rule to copy price from one product to another causes PHP notices fixes the issue (also deals with price field (un-)serialization issues.
Comment #26
amateescu commentedThis was quite hard to crack, took me a few hours :) Anyway, the answer is... *drumroll*:
hook_field_storage_pre_insert()andhook_field_storage_pre_update().This patch also fixes #1403140: Rule to copy price from one product to another causes PHP notices so I'm going to close that as a duplicate.
I'm not very happy with this piece of code, but I hope Ryan will have some ideas on how to clean it.
Comment #27
sixelats commentedApplied patch #26 with commerce 7.x-1.2 but I still get the notice: unserialize data error.
Comment #28
amateescu commented@sixelats: the patch from #26 doesn't include an update function to clean existing 'bad' data, I don't know if that's even possible. It just prevents the error to appear in the future by moving data serialization to a later stage in the process :)
Comment #29
lukusThanks for the patch - I was experiencing the error after a cache refresh. The patch solved the problem for me.
Comment #30
msmithcti commented@amateescu If I'm understanding comment #28 correctly: I'm getting this error on a site I'm developing at the moment with some dummy products. If I delete the dummy products and apply this patch before adding the products for real will that sort the error?
Comment #31
wojtha commented@splatio yes, the problem is that the price data was wrong serialized during node insert/update. Theoretically you can just update the nodes (after applying the patch) which forces the price field to resave and hopefully save the correct price data this time.
Comment #32
Ahyari commented@No need to deleted the old products, After applying the patch I disabled then enabled all products. The error disappeared.
Comment #33
msmithcti commented@Ahyari, @wojtha - thanks for the clarification!
Comment #34
chrisjlee commented@amateescu Patch seems to work for me and solved my problem thus far!
I just had some issues patching it because my git root dir was different. For others trying this out you may need to just use unix's native patch system:
patch < 1253114-26.patchComment #35
batigol commentedI can confirm that patch from #26 is working for me - at last I can include proper tax in my product.
Before I did got this error:
Comment #36
aidanlis commentedI'm getting this problem too. My products are created through the GUI, but the rest of the data in commerce (orders, line items, etc) are created using the Migrate module. The patch in #26 solves my problem.
Comment #37
wojtha commentedIt will be nice to provide some update function for this issue. I don't think we need to load each product as full object and re-save it. The price data columns is broken anyway so some kind of addittional data is lost anyway so I propose just filling the DB columns with the right data "empty" data.
Pseudocode:
Or is there any way how to update the price field via API without need to load the whole product node object?
Comment #38
rszrama commentedAhh, you know what, that's a perfectly reasonable update solution. I was wondering how we'd end up doing that, and since "Array" obviously isn't useful at all, nuking the column entirely is fair game. I've been struggling in my review of this patch lately, and I think the reason is because it unnecessarily combines two separate functions into one. I'm going to revert the combination of serialization / unserialization code into the single "prepare" function so that we have two separate functions for it, but I'll stick with the field storage hooks approach.
Comment #39
no2e commentedHad the same problem as described in #1446132: Notice: Array to string conversion in DatabaseStatementBase->execute().
The attached patch from #26 helped: the warnings don't appear anymore.
I'm not sure what I should do with the posted php code (in #26, too)? Do I need it in addition to the patch?
And: can't this #26 patch be committed now?
As far as I understand, it is only missing a way to update existing products, correct? But couldn't this be another issue? For ppl who freshly start, the fix would save trouble, wouldn't it?
Comment #40
ryumkin commentedsubscribe
Comment #41
murzConfirm that patch from #26 solves the problem for me, also fix issue #1446000: Unsupported operand types in commerce/modules/cart/commerce_cart.module on line 830 - after adding to cart.
Comment #42
jbova commentedThe patch in #26 solved some problems. I had to delete any open shopping carts or orders containing the products, then delete the products in order for the error to disappear.
Comment #43
mrpeanut commentedThe patch from #26 also worked for me. Like jbova in #42, I also had to delete any open shopping carts and orders. I also cleared the cache and disabled then enabled my dummy product.
Comment #44
rszrama commentedJust to reiterate, my recommendation in #38 needs to happen before a fix is committed. I've been meaning to do it myself but just didn't have the time with everything happening at DrupalCon.
Comment #45
giorgoskany progress ?
I have changed status of all products using latest VBO http://drupal.org/project/views_bulk_operations
status disabled then again enabled and the error message are gone ... (also using patch #26)
Comment #46
dimitriseng commentedI can also confirm that patch #26 removes the error messages. Will be waiting for the updated patch as per #38... Thanks.
Comment #47
wedge commented#26 fixed this for me too. Thanks.
Comment #48
rszrama commentedTagging this for 1.3. Even though people keep +1'ing the patch in #26, we won't commit anything until it's been reworked according to #38. I started this work but then got sidetracked, so I don't have any patch to share on this atm.
Comment #49
amateescu commentedHere's an updated patch that provides separate serialize/unserialize code and an update function.
Comment #51
amateescu commentedSloppy copy-paste :)
Comment #52
Anonymous (not verified) commentedI was getting the error message from #35 when trying to create a product, which brought me to this issue. I applied the patch from #51 to the latest dev version of Commerce and now the error's gone and products are being created successfully.
I'll let others test and mark as RTBC, but it's working for me!
Comment #53
helior commentedEverything works smoothly with applying the patch from #51. Great work!
Comment #54
Marcus VBP commentedHi, after the last -dev release, I get this error again, and the patch not worked.
thanks.
Comment #55
rszrama commented@Marcus VBP, did you actually apply the patch? It hasn't been committed to any -dev yet.
Comment #56
Marcus VBP commented@rszrama yes, I applied the patch after upgrading to the latest version -dev and not worked
Comment #57
k4v commented@Marcus VBP: Did you update the database (drush updatedb, update.php?). After applying the patch I still saw the error before updating. The patch works for me =).
Comment #58
rszrama commentedAlrighty, got a quickie review in before committing and realized we needed to add a confirmation message in the update function. Additionally, instead of the update function initializing components arrays in all the data columns, I just reset the values to NULL. We're initializing components arrays on load, so there's no reason to take up disk space with all those initialized strings. : )
Thanks so much to amateescu for sticking with this and for everyone who brought new insight to the table. This was particularly nasty to track down, and I'm sorry it took so long to finally commit a solution.
Commit: http://drupalcode.org/project/commerce.git/commitdiff/3d45979
Comment #59.0
(not verified) commentedEnglish version & delete home dir
Comment #60
ollaankoodeis commentedI get this same error when updating product images filenames with Filefield paths.
Notice: unserialize(): Error at offset 0 of 5 bytes funktiossa commerce_price_table_field_load() (line 180 in file /[path_to_drupal]/sites/all/modules/contrib/commerce_price_table/commerce_price_table.module).
I'm using latest stable releases of Drupal and modules so fixes to this issue should be committed?
Comment #61
wittehond commentedrerolled the patch against 7.x-1.x dev from git. the checks for empty are still needed with commerce_price_table