I hate to be the bearer of bad news again. :(
I just upgraded to 7.x-1.15. Upon viewing any of my product displays, no matter which type, the following entry is shown in my DB log:
Warning: reset() expects parameter 1 to be array, null given in commerce_cart_add_to_cart_form() (line 2110 of ...sites/all/modules/commerce/modules/cart/commerce_cart.module).
The checkout workflows are unaffected and there doesn't seem to be any problems for end-user workflow.
I am using Drupal 7.67 with Drupal Commerce 7.x-1.15 and PHP 7.2.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 3057706-14.add_to_cart_field_values.patch | 3.1 KB | rszrama |
| #9 | interdiff_4-9.txt | 790 bytes | TynanFox |
| #9 | 3057706-9.patch | 875 bytes | TynanFox |
| #4 | warning_reset_expects_parameter_1_to_be_array-305-7706-4.patch | 859 bytes | TynanFox |
Comments
Comment #2
TynanFox commentedIt would appear this is occurring due to the changes made regarding generation of the add_to_cart form. Since that issue was worked on and patched for over 5 years, I don't even know where I would begin diving into the changes to determine the root cause. :( I am happy to provide any further information needed regarding my installation or product types or whatever!
Comment #3
gaijinu commentedI can confirm the issue
Comment #4
TynanFox commentedHere is a basic patch, the point of which is merely to suppress the PHP error warning/message. My entire DB log is FULL of this error message, so I am uploading this as a temporizing solution to stop this behavior, but it does NOT address the underlying problem causing this error, and a more formal solution is needed as well as input from the maintainers.
Side note: hooray for my first patch! :)
Comment #5
travis-bradbury commentedSetting this to Needs Work for a few issues but the general approach seems fine to me (though I don't really know why it's breaking for you but didn't cause problems for anyone involved with #2293537: Cart form attributes selects do not work with translated taxonomies/products).
field_get_items()is not guaranteed to return an array, so assuming it would return an array with an element0was incorrect.That was done in several places so I think it should get fixed in multiple places, not just
commerce_cart_add_to_cart_form().There's a few changes necessary to meet the Drupal coding standards: https://www.drupal.org/docs/develop/standards
Use spaces between parentheses/braces - so
if (!empty(...)){would beif (!empty(...)) {.put else on a new line, not in line with the closing brace of the if statement.
And to commit a patch it would be necessary to write a test that demonstrates the problem - which might require a sleuth to determine the root cause.
Comment #6
TynanFox commentedHappy to work on the issues with coding standards, etc.
However, I have only intermittently examined the code in-depth of just a few parts of the Commerce core code base, and admittedly, I haven't taken a deep dive into the Cart submodule. That said, I am quite familiar with my site's architecture, so I am happy to dig in and try to locate a root cause. But perhaps you could point me in the right direction? If you were investigating this, where would YOU start? Happy to give it a go from there.
Comment #7
travis-bradbury commentedI haven't tried replicating the issue yet but I'd venture a guess that you have at least one attribute field on your product variation that has no value. Is that true?
Comment #8
TynanFox commentedYes indeed. I use Commerce Sale Price, which includes attributes for "On Sale" "Start Date" "End Date" etc. On very many of my products, these fields are left blank/empty/null. Additionally I have some other attribute fields which may or may not have data depending on the product.
Comment #9
TynanFox commentedBasic update of the patch to reflect the coding standards you mentioned (and also to allow me to learn more about how Git works and how to create an Interdiff). Still looking into the root cause, etc.
Comment #10
TynanFox commentedWhoops, in all my newbie glory, I accidentally committed my patch in #9 directly to the 7.x-1.x branch. Sorry. If anyone out there sees/wants to revert that commit, I won't be offended. I only meant to do it to my working branch.
Comment #11
pvasilion commentedWe are experiencing this on a client site as well. We don't use the Commerce Sale Price module.
Going to apply the patch for now.
Comment #12
waverate commentedPatch at #9 works for me. Thank you @TynanFox.
Comment #13
wolfshine commentedI can confirm the issue when you have at least one attribute field on your product variation that has no value.
Comment #14
rszrama commentedThanks for the fix, @TynanFox! I was able to confirm it fixed the issue - we obviously didn't test the previous changes with optional attributes (and apparently never added full test coverage for them).
Also, re: @tbradbury's review, I did expand the patch to the 3 other places turning up reset() warnings for me in my test environment. Likely a factor of me having multiple types of attributes on the test product display turned up the other ones.
Comment #15
rszrama commentedI saw a few more places where field values are assumed to be an array, but in context, it isn't clear to me that setting a default value to NULL in the absence of a response would be the right behavior, so I'm leaving them alone until we see bug reports. Committed!
Comment #18
Infinitee commentedI was still getting this warning to the point that my host charged me a $900 penalty for CPU overages. I was forced to put my site in maintenance mode until fixed.
All modules and core are up to date and I am using Commerce Kickstart.
Fixed with patch #14. I posted a notification in Commerce Kickstart issues... https://www.drupal.org/project/commerce_kickstart/issues/3108817#comment...
Comment #19
waqarit commented#14 has worked for me.
Comment #20
rszrama commentedGood, because it's been committed for a while now. : D
Comment #21
hunlaprovo commentedWarning: reset() expects parameter 1 to be array, null given commerce_cart_add_to_cart_form()
/html/profiles/commerce_kickstart/modules/contrib/commerce/modules/cart/commerce_cart.module 2110
commerce_kickstart-7.x-2.66
Today I updated the
Comment #22
wqmeng commentedAlso get many warnings after upgrade Commerce from 7.x-1.13 to 7.x-1.15
Warning: reset() expects parameter 1 to be array, null given in reset() (line 2141 of /home/www/com/sites/all/modules/commerce/modules/cart/commerce_cart.module).
line 2141, Should be the same error as above line 2110, As I have patched many other patches before.
Comment #23
vensiresChanging version to make it more easily identifiable that it's commited in 7.x-1.x-dev. No stable release exists yet to fix this issue.