magento2: Array to String conversion error on checkout page when changin country - how to debug
Preconditions
- Magento 2.2.1
- php and mysql updated from ubuntu 16.04 repositories
Steps to reproduce
- I guess it is difficult to reproduce and configuration dependent. I’d be happy for hints how to debug this. The payment methods are set available for all allowed countries. There are shipping tablerates for the respictive countries too.
- Add one or more product(s) to cart
- Go to (onepage) checkout page
- Change the country
Expected result
- Shipping method and tax values and payment providers should change according to country selection.
Actual result
- Sometimes client sees a short red error message above the checkout page about Array to string conversion. In that case following is seen in
var/log/exception.log:[2017-12-08 03:48:23] main.CRITICAL: Report ID: webapi-5a2a0b8746dca; Message: Notice: Array to string conversion in /var/www/XXX/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 2999 {"exception":"[object] (Exception(code: 0): Report ID: webapi-5a2a0b8746dca; Message: Notice: Array to string conversion in /var/www/XXX/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 2999 at /var/www/XXX/vendor/magento/framework/Webapi/ErrorProcessor.php:205, Exception(code: 0): Notice: Array to string conversion in /var/www/XXX/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 2999 at /var/www/XXX/vendor/magento/framework/App/ErrorHandler.php:61)"} []The corresponding (shipping, tax, payment) values do not always change. Sometimes the error is not shown in frontend, then the log message differs slightly. In between configuration changes or separete tests I flush caches and clear the browser session (FF, Ctrl+F5).
[2017-12-07 23:57:04] main.CRITICAL: Notice: Array to string conversion in /var/www/XXX/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 2999 {"exception":"[object] (Exception(code: 0): Notice: Array to string conversion in /var/www/XXX/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 2999 at /var/www/XXX/vendor/magento/framework/App/ErrorHandler.php:61)"} []
I am sorry not to be able to be more precise here but any help on getting a more detailed stacktrace or more information on where the error actually comes from would be greatly appreciated.
I hacked the corresponding Mysql.php file and printed the “array” contents into a file. It showed up an empty list (“()” afair).
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 21 (11 by maintainers)
Commits related to this issue
- Fixed Array to String conversion error on checkout page when changing country #12612 — committed to bluvertigo/magento2 by bluvertigo 6 years ago
- Change variable name #12612 — committed to bluvertigo/magento2 by bluvertigo 6 years ago
Here are the exact steps to reproduce, I tested it multiple times to make sure I didn’t make any mistakes
Preconditions
2.1-developbranch, current commit: c1b771005bdSteps to reproduce
Expected result
Actual result
Fix which hasn’t been tested very well
I wrote a small module with a preference for the
Magento\Quote\Observer\Frontend\Quote\Address\VatValidatorand copied thevalidatemethod and added some extra lines of code:This is most likely not the correct solution, but it seems to work…
@magento-engcom-team: can you double check and verify and then add the
G3 Passedlabel once verified? Thanks!I also ran into this issue. From what I am seeing this happens only to users who get their customer group emulated (and vat number validated) during checkout. (customers with a valid tax id shipping to another country within the EU that is)
When Magento fetches an address object from db it seems to turn the region data into an array (
Magento\Customer\Model\Address\AbstractAddress::getDataModel, Line 533).If later on vat validation is performed (
Magento\Quote\Observer\Frontend\Quote\Address\VatValidator, Line 43) there is a (\Magento\Quote\Model\Quote\Address) Model being saved that still has the region split as array.As the data is getting persisted into
quote_addresswhereregionis a varchar obviously Magento is trying to convert the array into a string which produces the error.This does not look like an error caused by extensions or migrated data.
@hostep , sorry for mistake, we rechecked this issue and added all correct labeles
@hostep Since the region data was of no importance in our case, we fixed this by simply unsetting the region data before vat validation was performed in a Plugin.
(We also targeted the
Magento\Quote\Observer\Frontend\Quote\Address\VatValidator::validateMethod)I’m also unsure if this method is the correct place to add the region splitting, this is something @magento-engcom-team needs to decide. Hopefully they now acknowledge the existence of this issue.