The customer 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 customer account: name, email, phone, password, group, status, and flags such as newsletter subscription. Addresses are stored separately in address, group names in customer_group_description, and balance and reward points in the customer_transaction and customer_reward journals. About a dozen other service tables record logins, IP addresses, and activity. Between 3.0 and 4.1, password storage, default addresses, and tokens changed.
Examples are for OpenCart 4.1. In 4.0.x, model triggers and event handling differ. For the overall database map, see the article OpenCart database tables.
What is in the customer table?
| Columns | Purpose |
|---|---|
customer_id | primary key; 0 in an order means a guest |
customer_group_id, store_id, language_id | group, store, and language the customer registered with |
firstname, lastname, email, telephone | contact details |
password | password hash (format depends on version) |
newsletter | newsletter consent |
custom_field | values of custom account fields in JSON |
status, safe | whether the customer can log in; a "safe" customer is not checked by anti-fraud extensions |
ip, token, code, date_added | IP at registration, service tokens, date |
Differences between the branches in the table itself:
- OpenCart 3.0: has
saltfor the password,address_id(default address),fax, and the legacy columnscartandwishlist. The wishlist is actually stored in a separatecustomer_wishlisttable, and the cart incart. - OpenCart 4.1: the
salt,address_id,fax,cart, andwishlistcolumns are absent;commenterwas added (in the admin hint, a flag related to spam checking of comments by the anti-spam system) along with an index onemail.
How are passwords and emails stored?
Password
OpenCart 3.0 (both 3.0.4.1 and 3.0.5.1) writes a random string to salt during registration, and a triple SHA1 hash with this salt to password. At login, the core still accepts the old MD5 format.
OpenCart 4.1 uses password_hash() with PHP's default algorithm. During login, the core verifies the password via password_verify(). If the hash is in an old format (SHA1 with a salt, when the salt column remains after database migration, or MD5), it rehashes it after a successful login. This means customers migrated from 3.0 gradually receive new hashes as they log into their accounts.
There is no unique key on email in any branch: duplicates are prevented by the registration and admin code, which counts customers with the same email before saving. Search is case-insensitive: WHERE LOWER(email) = … in 3.0 and LCASE(`email`) in 4.1. This leads to two consequences:
- in 4.1, the email is stored in lowercase during registration; in 3.0, it is stored as the customer entered it;
- a function applied to the column prevents MySQL from using the index, so on a large database, login and email checks perform a full table scan even in 4.1, where the index exists.
Importing customers from another system with direct SQL easily creates duplicate emails with different letter case. Check them with a GROUP BY LOWER(email) HAVING COUNT(*) > 1 query before running the import.
How do customer groups work?
customer_group has only customer_group_id, approval, and sort_order; the name and description are in customer_group_description with the key (customer_group_id, language_id). Groups are managed in "Customers → Customer Groups" (Customers → Customer Groups).

A group affects many things at once:
- Prices. Discounts and specials in
product_discount(andproduct_specialin 3.0) are set for a specific group; points for purchases inproduct_rewardare as well. - Custom fieldsYour own fields in registration or address, for example a tax ID number or a post office branch. More in the glossary →.
custom_field_customer_groupdetermines which fields the group sees and fills in. - Registration approval. If
approvalis enabled for a group, a new customer is created withstatus = 0, and a request appears incustomer_approval; the administrator approves it in "Customers → Customer Approvals" (Customers → Customer Approvals). - Taxes and payment or shipping methods, if the corresponding modules take the group into account.
The default group for new customers and the list of groups that can be selected during registration are set in "System → Settings" on the "Option" tab (Customer GroupA segment of buyers (retail, wholesale) with different prices and terms. More in the glossary → and Customer Groups fields). For guests, the core uses the default group. If you delete a group that customers are still assigned to, their prices and fields become unpredictable, so first move the customers to another group.
How are addresses stored?
address has one row per address: customer_id, firstname, lastname, company, address_1, address_2, city, postcode, country_id, zone_id, and custom_field. An index on customer_id exists in both branches.
| What | OpenCart 3.0 | OpenCart 4.1 |
|---|---|---|
| Default address | customer.address_id | address.default column |
| Country address format | country.address_format column | separate address_format table; in the country, address_format_id |
| Country and region names | in the country and zone tables | in country_description and zone_description by language |
The address in an order is a copy, not a reference: at checkoutThe order placement page. The fewer fields, the higher the conversion. More in the glossary →, the address fields are written to the order table. Changing or deleting an address in the account does not affect old orders. For Ukraine, the city and address_1 fields are often filled with the city and the carrier's branch; shipping modules usually store the branch ID in custom fields or in their own tables. For the order table, see the article order table in OpenCart.
Where are the balance, reward points, and customer history?
In OpenCart, the balance and points are not stored as a single number. They are operation journals, and the current value is the sum of the rows:
customer_transactionis the monetary balance (store credit):customer_id,order_id,description,amount. Negative amounts are expenses.customer_rewardis reward points:customer_id,order_id,description,points.
Example
SELECT c.customer_id, c.email,
(SELECT COALESCE(SUM(ct.amount), 0) FROM oc_customer_transaction ct WHERE ct.customer_id = c.customer_id) AS balance,
(SELECT COALESCE(SUM(cr.points), 0) FROM oc_customer_reward cr WHERE cr.customer_id = c.customer_id) AS points
FROM oc_customer c
WHERE c.customer_id = 42;
This is exactly how the core models calculate them. A bonus or cashback module that wants to change the balance should add a row to the journal, not edit the amount. A ready-made version of such a mechanism is Advanced Bonuses and Cashback.
Other service tables for the customer:
customer_history: manager comments in the customer record;customer_ip: IP addresses of logins (in 4.1 alsostore_idandcountry);customer_login: failed login attempts by email and IP to protect against brute force;customer_online,customer_activity,customer_search: who is on the site, actions in the account, search queries;customer_affiliate: affiliate program data (in 4.1,balanceandpayment_methodwere added);customer_wishlist: wishlist items (in 4.1 the key includesstore_id).
In 4.1, customer_token (codes for password reset and confirmations) and customer_authorize (login authorization records with token, IP, browser, and expiry date) were added. These tables contain personal data, so access to them from modules should be limited to the minimum required. For admin protection, see the blog: OpenCart admin security.
How to work with customers safely from a module?
Customer data is personal, and mistakes here are more costly than in the catalog. A few rules that follow from the schema:
- Create and modify customers through the admin model
customer/customer: it correctly hashes the password for its version, in 4.1 it stores the email in lowercase, and it fills in all required columns. - Delete through the model as well. The
deleteCustomer()method of the admin model removes the account along with the related service data of the customer, while a directDELETEfromcustomerwill leave them in the database. Check the list of tables that the method cleans up inadmin/of your release.model/ customer/ customer.php - Do not copy personal data into your own tables unnecessarily. Store
customer_idand take the name or email fromcustomerat the moment of use. - Account for data deletion requests. In 4.1, there is the
gdprtable and the "Customers → GDPR" page (Customers → GDPR, routecustomer/gdpr) for requests to export and delete data. If a module stores customer data separately, plan for its deletion along with the customer, for example with an event using theadmin/trigger in 3.0 ormodel/ customer/ customer/ deleteCustomer/ after admin/in 4.1. A trigger with an incorrect separator will silently never fire.model/ customer/ customer.deleteCustomer/ after
How to intercept customer deletion or changes with an event is described in the article event model in OpenCart.
Summary
customeris the account; group names are incustomer_group_description, addresses are inaddress.- 3.0 stores the password as SHA1 with a salt; 4.1 uses
password_hash()and rehashes old formats at login. - Email has no unique key and is searched case-insensitively; check for duplicates after imports yourself.
- Default address:
customer.address_idin 3.0,address.defaultin 4.1. - Balance and points are sums of the
customer_transactionandcustomer_rewardjournals; change them by adding new rows.
Languages and stores in the database, and safe and slow queries, are covered in other articles in the Database section. For how to build your own module tables alongside the customer tables, see the article custom module tables in OpenCart.