PrestaShop Error after upgrading to PrestaShop 1.7.7.1

After upgrading a PrestaShop store from 1.7.6 to 1.7.7.1 we encountered an error when trying to open the details page to an order.

Enabling DEBUG mode

On first attempt to enter the order detail view we just got a totally meaningless error page stating that something went wrong.

To find out more details about the issue we enabled DEBUG mode by changing the following line of code in our config/defines.php and setting DEBUG to true.

/* Debug only */
if (!defined('_PS_MODE_DEV_')) {
define('_PS_MODE_DEV_', true);
}

Recreating the error

We then went back to the dashboard and our orders list and tried to open the details to any order. Now the error message was a little more informative, so to say.

PrestaShop Error

Type error: Argument 11 passed to PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderShippingAddressForViewing::__construct() must be of the type string, null given, called in C:\www\prestashop\src\Adapter\Order\QueryHandler\GetOrderForViewingHandler.php on line 270

After doing some research it turned out that PrestaShop 1.7.7.1 seems to be less forgiving about NULL values in our database tables, which obviously were no problem in older versions. Some users in the PrestaShop forums suggested this solution, and it thankfully got the store up and running again.

As per usual, before you alter your database, it is absolutely mandatory to make a backup.

Altering the database

Open your database with your favorite tool (phpMyAdmin works just fine) and paste the following code into your SQL command line.

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;
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;

After that please remember to go back into your config/defines.inc.php and set DEBUG mode to false again.

Update: products not found issue

After a few days we encountered another problem in the back office and at first, we could not even tie it to the database issue.

When creating a manual order in the back office, some products could not be found, even though they existed and were in stock. Again, enabling DEBUG mode helped us to trace down the issue.

As it turns out there is another NULL issue with product attribute combinations, so here is the quick SQL fix for it:

UPDATE ps_product_attribute SET location = '' WHERE location is NULL

And again, remember to turn off DEBUG mode afterwards.

We really hope this is finally it with this NULL issue, but somehow we have a strong gut feeling that we will see this bug happening again on some other part of the shop. At least we know where to search for it now.

If you found this helpful or have more questions, please leave a comment below!


Disclaimer: The Publisher and Editors cannot be held responsible for errors or any consequences arising from the use of the information contained in this blog post.

Consent management by Real Cookie Banner