The order table in OpenCartA free open-source CMS for online stores, written in PHP with a MySQL/MariaDB database. Everything that is not part of the core is added through extensions. More in the glossary → stores the order "header": the customer, addresses, payment and shipping methods, the total, the currency, and the current status. Products are in order_product and order_option, summary rows (subtotal, shipping, coupon, total) are in order_total, and the full history of status changes is in order_history. An order in OpenCart is a snapshot taken at checkoutThe order placement page. The fewer fields, the higher the conversion. More in the glossary →: names and prices are copied rather than referenced to the productA catalog item with a name, price, description, and photos. More in the glossary →, so changing the catalog does not change old orders.
Examples are for OpenCart 4.1; in 4.0.x, model triggers and event handling differ. For the general database schema, see the article OpenCart database tables.
What does the order table store?
The table name is a reserved SQL word, so in queries it is always wrapped in backticks: `oc_order`, and in code `" . DB_PREFIX . "order`. The columns are easier to read in groups:
| Group | Columns |
|---|---|
| Identification | order_id, invoice_no, invoice_prefix, store_id, store_name, store_url |
| Customer | customer_id (0 for a guest), customer_group_id, firstname, lastname, email, telephone, custom_field |
| Payment address | payment_firstname … payment_city, payment_country_id, payment_zone_id, payment_address_format, payment_custom_field |
| Shipping address | the same set with the prefix shipping_ |
| Methods | payment_method, shipping_method (format differs, see below) |
| Money | total, currency_id, currency_code, currency_value, commission |
| State | order_status_id, comment, date_added, date_modified |
| Marketing and technical | affiliate_id, marketing_id, tracking, language_id, ip, forwarded_ip, user_agent, accept_language |
Country and zone names, the address format, and the store name are stored as text alongside their IDs. This is deliberate: if a zone or store is renamed later, old orders will show what was current at the time of checkout.
Guests, customers, and custom fields
For guest checkoutPurchasing without registration. Enabled in the settings. More in the glossary →, customer_id equals 0, and an order can be linked to a person only by email or phone number. For a registered customer, customer_id points to the customer table, but the name, email, and phone are still copied into the order: if the customer later changes their email in the account area, old orders keep the previous one.
Custom field values are stored in the custom_field, payment_custom_field, and shipping_custom_field columns as JSON in both branches: the key is the field ID, and the value is what the buyer entered. Searching by them in SQL is inconvenient and slow, so if a module needs a field for filtering or reports (for example, a company tax ID for legal entities), it is better to also store it in your own table with order_id.
invoice_no defaults to 0: the invoice number is not assigned at checkout but when the administrator generates it in the order record. So the invoice number and the order number are different things, and invoice numbers can have gaps relative to orders.
How did the columns change in OpenCart 4.1?
| Item | OpenCart 3.0 | OpenCart 4.1 |
|---|---|---|
payment_method | varchar(128), method name as text | text, JSON with the name and code of the selected option (for example, code cod.cod) |
payment_code, shipping_code | separate columns with the method code | none, the code is inside the JSON |
shipping_method | varchar(128), text | text, JSON |
| Addresses | text fields only | additionally payment_address_id, shipping_address_id |
| New columns | — | subscription_id, transaction_id, language_code |
| Removed | fax | — |
| Indexes | primary key only | additionally email and order_status_id |
For integrations, this is the most important change. A report or CRM synchronization that filters by WHERE payment_code = 'cod' in 3.0 will not work in 4.1: the column does not exist, and the code has to be extracted from the JSON. It is more reliable to read orders through the model and decode the field in PHP using json_decode() than to parse JSON in SQL.
Example
// OpenCart 4.1, контролер адмінки модуля
$this->load->model('sale/order');
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info) {
$payment_code = $order_info['payment_method']['code'] ?? '';
}
The sale/order model in 4.1 decodes the JSON for payment and shipping methods automatically, so the getOrder() result is already arrays. If you read the table directly, decode it yourself.
How are order products stored?
order_product
One row per item: order_id, product_id, name, model, quantity, price, total, tax, reward. It is important to understand the meaning of the amounts:
priceis the unit price excluding tax, already including quantity discounts, promotions, and option surcharges;totalisprice × quantity, also excluding tax;taxis the tax per unit, not for the whole line item.
In 4.1, master_id was added for variant products. There is an index on order_id in both branches.
order_option
The selected options of an item: order_product_id, product_option_id, product_option_value_id, as well as name, value, and type as text. As with products, names are stored as copies so the order stays readable after the options catalog changes.
What is order_total and why is it needed?
order_total is the breakdown of the order total: one row for each totals module that ran during checkout. Fields: code (for example, sub_total, shipping, coupon, tax, total), title is the label as the buyer saw it, value and sort_order. In 4.1 there is also extension, the code of the extension that owns the totals module.
The row with the code total equals order.total. The remaining rows explain how the total is made up: coupon discounts are stored as negative values, and taxes are separate rows with code = 'tax'. These are the rows shown in the email to the buyer, in the order record, and on the invoice.
Practical implications:
- To find the shipping cost of an order, take the row with
code = 'shipping'rather than calculating the difference between totals. - If you change the order contents outside standard editing, you must recalculate both
order_totalandorder.total, otherwise the email, invoice, and reports will show different figures. - It is better to implement a discount from your own module as a separate totals module, so it will automatically appear in
order_total. For the extension types, see the article OpenCart module types.
How do status and order_history work?
The current status is in order.order_status_id, and order_history stores every change: order_status_id, notify (whether the buyer was notified), comment, and date_added. Both places are updated by one storefrontWhat the customer sees: the home page, categories, product page, and cart. More in the glossary → model method: addOrderHistory() in 3.0 and addHistory() in 4.1. It also deducts stock when moving into processing statuses, sends emails, and returns goods to stock on cancellation.
- Status 0 means checkout is not complete: the order is created before payment and receives a status only after confirmation. In the admin, such orders are visible only through the Missing Orders filter, and core reports do not count them.
- Status names are in the
order_statustable with the key(order_status_id, language_id), so queries against them need a language condition. - There is no index on
order_idinorder_historyin either 3.0 or 4.1. On a large database, fetching the history of several thousand orders in one query will be slow.
Do not change the status with a direct UPDATE: stock adjustments, emails, rewards, and module events waiting for a status change will then not fire. For how to intercept a status change with an event, see the article event model in OpenCart.
How to calculate totals and build reports correctly?
order.total and all amounts in order_product and order_total are stored in the store's default currency. The currency_code and currency_value columns record the currency in which the buyer saw prices and the exchange rate at the time of checkout. The amount in the buyer's currency is total × currency_value; this is how the admin and emails display it.
Example
-- виручка за місяць за статусами, в основній валюті
SELECT os.name AS status, COUNT(*) AS orders, SUM(o.total) AS revenue
FROM `oc_order` o
JOIN oc_order_status os ON (os.order_status_id = o.order_status_id AND os.language_id = 1)
WHERE o.order_status_id > 0
AND o.date_added >= '2026-10-01' AND o.date_added < '2026-11-01'
GROUP BY o.order_status_id, os.name;
A few rules for reports:
- Always exclude
order_status_id = 0, otherwise you will count unfinished checkouts. - Filter by
store_idif you have multiple stores. - For revenue, choose the statuses that mean an actual sale in your store; in settings they are defined as processing and completion statuses.
order.totalshows the order amount, not how much was actually paid: the core does not separately store partial payments or refunds.
It is better to delete orders through the admin: in both branches, the core first switches the order to status 0 to return the goods to stock, and then deletes the related rows: order_product, order_option, order_total, order_history, customer transactions, and other records linked to the order.
Summary
orderis the order header with a snapshot of the customer's data, addresses, methods, and amount; wrap the table name in backticks.order_productstores the price and the per-unit tax excluding tax,order_totalholds the breakdown of the total by totals modules.- Change the status only through
addOrderHistory()(3.0) oraddHistory()(4.1); status 0 means an unfinished checkout. - In 4.1, payment and shipping methods are JSON, and the
payment_codeandshipping_codecolumns no longer exist. - Amounts are in the default currency; the exchange rate and the buyer's currency code are recorded in the order itself.
The customer, language, and store tables and query performance are covered in other articles in the Database section. The product tables referenced by orders are described in the article the product table in OpenCart.