Prestashop: Error on display details of order OrderCustomerForViewing (... must be of the type string null given ...) GetOrderForViewingHandler

Created on 3 Dec 2020  ·  34Comments  ·  Source: PrestaShop/PrestaShop

Describe the bug

Hello
today I updated my Prestashop from 1.7.6.4 to 1.7.7.0 after I update my cms some pages didn't work correctly.
now I cant see details of the order and I will get the below error :

Argument 4 passed to PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderCustomerForViewing::__construct() must be of the type string, null given, called in /home/....../....../src/Adapter/Order/QueryHandler/GetOrderForViewingHandler.php on line 236

I am using Prestashop with Persian Language and also multistore option too.

  • PrestaShop version: 1.7.7.0 (with Persian lang)
  • PHP version: 7.2
1.7.7.0 Autoupgrade BO Bug Can't Reproduce Customer Order

Most helpful comment

Hi everyone, after looking at the code mentioned in the error, this kind of erro happens when someone attempts to display an Order with invalid data in it.

I have seen multiple examples of invalid data such as customized products with an empty name data.

Basically, "previous" Order Page was able to display this data because it was tolerant. New Order page rejects rather invalid data. This looks like something we should improve on the new Order Page:

  • when order data is not valid, add a warning message to merchant*
  • display the order nonetheless

*It is important to flag the data has some validity issues. Sometimes you don't care (like invalid address) but sometimes the data might be important for billing/shipping.

All 34 comments

Hello @IranDec

Did you had errors while upgrading? like database errors?
And could you please provide some screenshot.

Please next time respect and follow our template to submit a complete bug report.
Read more about how we expect the issues to be handled here.

Thanks!

@hibatallahAouadni
Hello
today I got it there is no problem with new orders that did after upgraded but I can't access into non of my previous orders

https://ibb.co/DVrQddg

Did you had errors while upgrading? like database errors?

No, all thing updated fine without any errors

Same issue here. I had no errors during upgrade.
It happens also on new orders with old addresses, with no "company" in the address, for example. Very annoying. Can't open the order and can't open the address either.

Same here, i cant reach the old orders / 1.7.7.0

https://pasteboard.co/JEDRlfH.jpg
https://pasteboard.co/JEDRsrR.jpg

I had same problem also 5 minutes ago, after reading your comments here, I went straight to the addresses and noticed that the orders being made by new customers, the new customers during the purchase process must have made some simulation to get delivery price but did not finish adding address, but on a second try, they finalised purchase with complete address.

So I noticed this, each of these customers had 2 addresses, 1 incomplete and the other complete, since I use onepagecheckout, I used the option in the module to clear empty/incomplete addresses and the erro was gone.

Might not be the complete cause or solution, but for now this was my experience. Will update tread if I get further findings.

Also, something else I noticed, the status being assigned is different from the payment method, so I changed the payment status from Amazon marketplace order (which are orders imported form amazon marketplace) to PayPal payment accepted which is the payment method used and the error appeared again.

I used the one page checkout module in deleting empty addresses and I can now access again the order page.

Regards.

Update: the error is still there on view customer, but I can see order.

Hoping for a definite fix soon.

Hi everyone, after looking at the code mentioned in the error, this kind of erro happens when someone attempts to display an Order with invalid data in it.

I have seen multiple examples of invalid data such as customized products with an empty name data.

Basically, "previous" Order Page was able to display this data because it was tolerant. New Order page rejects rather invalid data. This looks like something we should improve on the new Order Page:

  • when order data is not valid, add a warning message to merchant*
  • display the order nonetheless

*It is important to flag the data has some validity issues. Sometimes you don't care (like invalid address) but sometimes the data might be important for billing/shipping.

Well, an address without company shouldn't even be considered "invalid data" unless the company field is configured required. Heck, I couldn't even open orders with a null address 2 field. Many of those fields should be nullable as on the previous version. Also, if the new version stores empty strings instead of null values in the database, it wouldn't have hurt to write a migration script for the current null values. That's what I had to do manually and everything works fine now as far as opening and editing orders and addresses.

Hello @IranDec

Sorry for the late response. But, I didn't manage to reproduce your issue, see the attached screen record below:

https://drive.google.com/file/d/1S4zwWmOt7FK14KMNHQlCMzkJc8oAC5Am/view

I installed a new shpp 1.7.6.4 with persian lang, then I upgraded to 1.7.7.0. The only bug encountred is #22250

Please check and feedback.
Thanks!

I had a similar issue when manually transferring a database from a localhost server to a web server. It resulted in precisely the same error in the OP. I needed to change database collation type (another error entirely).
As a result, I ended up with 'NULL' values populating empty values on numerous tables.

A simple SQL query aimed at ps_addresses, ps_orders, ps_order_detail and ps_customer to replace 'NULL' values with no text (in SQL column='') seemed to do the trick. Clearly a quick and dirty fix though, and doesn't solve the initial problem caused.

Hi andrewcroberts, yes you are right!
I have this issue too, on customers, orders etc..
I would not explain my issue as I use a module to migrate the datas from an old oscommerce to prestashop.
It worked nice on 1.7.6.3, and no more on 1.7.7, I spent days to find the issue, searching for the data missing.
But in fact you are right, no datas are missing, NULL has been changed to "nothing".
On an old order I have many "NULL", and I made a new test order, and yes there is not the null anymore.

So I have a question, do you think this is the right solution to replace all the null by "nothing", I can make a sql request in all my tables, or should I do that only where I have the errors ?

For one order I had 6 or 7 errors like that:

  • phone mobile null: ps_adress
  • ref product: ps_order_detail
  • ps_order_payment: all null

Hi andrewcroberts, yes you are right!
I have this issue too, on customers, orders etc..
I would not explain my issue as I use a module to migrate the datas from an old oscommerce to prestashop.
It worked nice on 1.7.6.3, and no more on 1.7.7, I spent days to find the issue, searching for the data missing.
But in fact you are right, no datas are missing, NULL has been changed to "nothing".
On an old order I have many "NULL", and I made a new test order, and yes there is not the null anymore.

So I have a question, do you think this is the right solution to replace all the null by "nothing", I can make a sql request in all my tables, or should I do that only where I have the errors ?

For one order I had 6 or 7 errors like that:

  • phone mobile null: ps_adress
  • ref product: ps_order_detail
  • ps_order_payment: all null

In my case I only did it for the tables I said, and that’s fixed my issues. However, make yourself a backup and apply it to all the tables, and let us know if it fixes the issue and doesn’t have any additional side effects elsewhere.
If applying that to all tables works, then it’s a quick and simple query to issue for people having this issue.
It appears that Prestashop has stopped issuing ‘null’ values in a lot of places. So adjusting the entire database to reflect this may not be a bad thing 🤷‍♀️
Best of luck!

Hi, no it will not work, just for one "order_invoice" in phpmyadmin it wont make the change.
So I searched a little more.
In fact my old datas have some columns to "null", it was not an issue in prestashop 1.7.6.3.
2 ways: I search why no it doesn't accept anymore this null data.
or like you I update one by one to ''.
and in my case I will try to change the migration module, and set '' instead of null to be automatic to my next migrations.

new orders with 1.7.6.3 already had 'nothing' instead of null, so I think we will have to deal it by ourself.
but it's good, at least we know why and how to fix it.

I did not check all the tables, but I compared where the new system use null or not.
So this is not the full list, but you just have to copy/paste this to sql phpmyadmin, and then no more issue about null given:

UPDATE ps_address SET phone = '' WHERE phone IS NULL;
UPDATE ps_address SET phone_mobile = '' WHERE phone_mobile IS NULL;

UPDATE ps_order_detail SET id_order_invoice = '0' WHERE id_order_invoice IS NULL;
UPDATE ps_order_detail SET product_reference = '' WHERE product_reference IS NULL;
UPDATE ps_order_detail SET product_supplier_reference = '' WHERE product_supplier_reference IS NULL;
UPDATE ps_order_detail SET product_isbn = '' WHERE product_isbn IS NULL;
UPDATE ps_order_detail SET product_upc = '' WHERE product_upc IS NULL;
UPDATE ps_order_detail SET product_mpn = '' WHERE product_mpn IS NULL;
UPDATE ps_order_detail SET download_hash = '' WHERE download_hash IS NULL;
UPDATE ps_orders SET gift_message = '' WHERE gift_message IS NULL;

UPDATE ps_order_payment SET transaction_id = '' WHERE transaction_id IS NULL;
UPDATE ps_order_payment SET card_number = '' WHERE card_number IS NULL;
UPDATE ps_order_payment SET card_brand = '' WHERE card_brand IS NULL;
UPDATE ps_order_payment SET card_expiration = '' WHERE card_expiration IS NULL;
UPDATE ps_order_payment SET card_holder = '' WHERE card_holder IS NULL;

UPDATE ps_order_carrier SET tracking_number = '' WHERE tracking_number IS NULL;
UPDATE ps_order_carrier SET id_order_invoice = '0' WHERE id_order_invoice IS NULL;
UPDATE ps_order_carrier SET weight = '0' WHERE weight IS NULL;

UPDATE ps_product SET isbn = '' WHERE isbn IS NULL;
UPDATE ps_product SET upc = '' WHERE upc IS NULL;
UPDATE ps_product SET mpn = '' WHERE mpn IS NULL;
UPDATE ps_product SET unity = '' WHERE unity IS NULL;
UPDATE ps_product SET supplier_reference = '' WHERE supplier_reference IS NULL;
UPDATE ps_product SET location = '' WHERE location IS NULL;
UPDATE ps_product SET redirect_type = '301-category' WHERE redirect_type = '';
UPDATE ps_product SET available_date = '2020-12-01' WHERE available_date IS NULL;
UPDATE ps_product SET cache_default_attribute = '0' WHERE cache_default_attribute IS NULL;
UPDATE ps_product_shop SET unity = '' WHERE unity IS NULL;
UPDATE ps_product_shop SET redirect_type = '301-product' WHERE redirect_type = '';
UPDATE ps_product_shop SET available_date = '2020-12-01' WHERE available_date IS NULL;
UPDATE ps_product_shop SET cache_default_attribute = '0' WHERE cache_default_attribute IS NULL;

@DelosTR

adding below queries to the list

update ps_address set dni = '' where dni is null;
update ps_address set other = '' where other is null;
update ps_address set address2 = '' where address2 is null;
update ps_address set company = '' where company is null;
update ps_address set vat_number = '' where vat_number is null;

@abdullacm

Alright, thanks for the add ;)

Hello @abdullacm & @DelosTR

Could you please confirm that you both encounter the same problem as @IranDec

Thanks!

@hibatallahAouadni Hi, I can't confirm that because I don't know which pages didn't work for him.
BUT, the error is the same, "null given" when upgrading to 1.7.7

And we could solve that by give to it a "real" value instead of null.
I don't think we are alone with this issue, it's strange.

Hello @DelosTR

Thanks for your feedback!
Could you please open a new issue following the template to submit a complete bug report.
And please fill all the blocks cause we need every detail to reproduce the issue.

@IranDec
Since we had no news from you for more than 20 days, I'll close this ticket to avoid cluttering up the backlog.
Please note that you can always create a new one if further information pops up.

Thanks!

It's ridiculous that you close this ticket when so many people are having the same issue. Obviously there is an issue. Says a lot about the support from Prestashop.

Hello @fire2

Cause I can't reach @IranDec for more than 20 days that's why I close it.
And we need more details to reproduce the issue.
So, please open a new issue following the template to submit a complete bug report.
And please fill all the blocks cause we need every detail to reproduce the issue.

Thanks!

And you don't think creating a new issue for the same problem is cluttering more the backlog?? really...

Sir, I clearly said that we need more details to reproduce the issue.
If the contributor doesn't help us reproduce the issue, we close it.

Hi,
For me it was happening because the "id_lang" of a order no longer exists in my shop, so I had to change:

Line 299 of PrestaShop\PrestaShopAdapter\Order\QueryHandlerGetOrderForViewingHandler to
isset($country->name[$order->id_lang]) ? $country->name[$order->id] : $country->name[\Configuration::get('PS_LANG_DEFAULT')],

Line 266 of PrestaShop\PrestaShopAdapter\Order\QueryHandlerGetOrderForViewingHandler to
isset($country->name[$order->id_lang]) ? $country->name[$order->id] : $country->name[\Configuration::get('PS_LANG_DEFAULT')]

Line 220 of PrestaShop\PrestaShopAdapter\Order\QueryHandlerGetOrderForViewingHandler to:
$genderName = isset($gender->name[$order->id_lang]) ? $gender->name[$order->id_lang] : $gender->name[\Configuration::get('PS_LANG_DEFAULT')];

I could submit a PR with these fixes, but I am note sure if there is a better way to apply this fix with the new classes of PrestaShop.

The same error is happening when I click in this arrow and the fix is very similar. @hibatallahAouadni Do you want me to create another issue and submit a PR with these fixes?

image

Hello @amaurigabriel

Yes please and thanks in advance.

I got the problem that after upgrade from 1.7.6.3 to 1.7.7 (just a couple of days ago) and when click on backoffice orders I got this message (I read something about "$address->phone_mobile" but the customer has a mobile phone):
Type error: Argument 4 passed to PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderShippingAddressForViewing::__construct() must be of the type string, null given, called in /homepages/11/d812037717/htdocs/src/Adapter/Order/QueryHandler/GetOrderForViewingHandler.php on line 269
Captura de pantalla 2020-12-31 a las 18 57 44

If I switch Off the debug mode and I click again in an order I get this message

Captura de pantalla 2020-12-31 a las 19 11 38

You can use the sql lines of my post.
For your case:

Phpmyadmin, sql:

UPDATE ps_address SET phone = '' WHERE phone IS NULL;
UPDATE ps_address SET phone_mobile = '' WHERE phone_mobile IS NULL;

what about this?

image

Try:

UPDATE ps_connections_source SET keywords = '' WHERE keywords IS NULL;

See if that solves it. It might start complaining about other null values, in which case, replace the column names with the new offending columns.

omg thats it!! thanks so much

You can use the sql lines of my post.
For your case:

Phpmyadmin, sql:

UPDATE ps_address SET phone = '' WHERE phone IS NULL;
UPDATE ps_address SET phone_mobile = '' WHERE phone_mobile IS NULL;

How should I do this? I do not know much about SQL. I´m a plain user of Prestashop.

Happy New Year to all!

And a Happy New Year to you too!

Do you have access to phpMyAdmin?
If not, contact your web host for details to access it.

If so, log in to it, and select the database that prestashop is using. Click on the tab at the top, marked 'SQL'.

It should present you with a text box (titled "Run SQL query/queries on database ")
Copy at paste the commands into there, and press 'go'.

Also, I'd suggest you use the DB backup option in the prestashop back office first, just in case something goes wildly wrong.

Was this page helpful?
0 / 5 - 0 ratings