Skip to content
Eduardo Lira

PRESTASHOP · BANCO-DE-DADOS

Prestashop: "OrderHistory -> id_order_state is empty" and the 2013 SQL I wouldn't paste again

The error shows up when the setting that tells which status an order gets is missing. In 2013 I published an INSERT to recreate those keys; today I would query first, because the IDs vary from store to store.

In July 2013 I posted the fix for this error here. It showed up when completing a purchase or changing an order’s status in Prestashop:

Fatal error (OrderHistory -> id_order_state is empty)

The diagnosis is still right. The SQL I suggested is what deserved more care.

What the error means

Every order has a status history: awaiting payment, payment accepted, shipped and so on. When a payment module creates the order, it doesn’t store the status by name: it reads the ID from a configuration key, such as PS_OS_PAYMENT or PS_OS_BANKWIRE, in the ps_configuration table. If that key doesn’t exist or is empty, the history entry is created with no status, and Prestashop stops with this error. The order may even have been saved, but without the payment status.

In 2013 the problem showed up a lot in versions 1.4.4.0 and 1.4.4.1, in stores where those keys hadn’t been created.

The first attempt: reinstall the module

That was what I suggested first, and it is still the cleanest path: payment modules usually create, on installation, the keys and statuses they need. But reinstalling wipes the module’s configuration, which is why the post offered the database alternative.

The 2013 SQL

INSERT IGNORE INTO `PREFIXO_configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES
('PS_OS_CHEQUE', '1', NOW(), NOW()),
('PS_OS_PAYMENT', '2', NOW(), NOW()),
('PS_OS_PREPARATION', '3', NOW(), NOW()),
-- ... up to PS_OS_WS_PAYMENT, '12'

Three things I wouldn’t repeat:

  • The numbers are those of a fresh installation. 2 is only “payment accepted” if the store never created or deleted a status. Storing the wrong number makes the order enter with the wrong status, which is worse than the error, because it goes unnoticed.
  • INSERT IGNORE doesn’t fix an empty key. It only skips the row when the key already exists. If the key exists with an empty value, which was exactly the case I described, nothing changes. And in Prestashop versions without a unique index on the name, the result is a duplicate row.
  • The original list had five keys unrelated to the error, for image quality and cookie lifetime. They shouldn’t have been there.

How I would do it today

First, see what exists. The store’s status IDs and names:

SELECT s.id_order_state, l.name
FROM ps_order_state s
JOIN ps_order_state_lang l ON l.id_order_state = s.id_order_state
WHERE l.id_lang = 1
ORDER BY s.id_order_state;

And the status keys in the configuration:

SELECT id_configuration, name, value
FROM ps_configuration
WHERE name LIKE 'PS\_OS\_%';

id_lang = 1 and the ps_ prefix are the defaults; check your store’s. With both lists in hand, you can see which key is missing or empty and which ID it should have. The fix is an UPDATE on the empty row or an INSERT of just the missing key, with the right ID, and always with a database backup made beforehand.

References

Who writes this

Eduardo Lira

Software developer in Rio de Janeiro. I started this blog in 2012, in technical support at a hosting company, writing down the fixes for the problems that came up every day. Today I work at Sofis Tecnologia, on critical healthcare systems and SQL Server database migrations.

Found a mistake in this post?

A command that no longer works, a broken link, wrong information: tell me what you saw. The message goes only to the author and is not shown on the site.