Appearance
Customer Mail History
Flow ID: AD-41 | Module(s): eshop | Complexity: Low Last Updated: 2026-04-04
Business Context
The customer mail history system records every email sent to customers by the platform (order confirmations, shipping notifications, promotional emails, etc.). It provides a stored copy of each email's HTML body so administrators can view exactly what the customer received. A storefront-facing controller allows rendering a single email by ID, typically used for "view in browser" links embedded in outgoing emails.
The model is write-heavy: various parts of the system call addRecord() when sending emails, but there is no admin search/list interface in the core platform -- email history is viewed per-customer on their admin detail page.
API Reference
REST Endpoints
No REST API for mail history.
Legacy Storefront Routes
| Route | Controller | Method | HTTP | Description |
|---|---|---|---|---|
mail_history/view/{id} | Adv_customer_mail_history | view | GET | Render the stored email HTML body |
Note: This extends Front_c (storefront controller), not Admin_c. The email body is echoed directly as raw HTML without any template wrapping.
Code Flow
Recording an Email
- Any part of the system that sends customer email calls
customer_message_history_model::addRecord(). - Parameters:
customerId,purpose(type category),messageType(email/sms),subject,message(full HTML body). - Inserts a row into
shop_customer_message_historywith the current datetime.
Viewing an Email
- A "view in browser" link in an email points to
mail_history/view/{id}. Adv_customer_mail_history::view($id)callscustomer_message_history_model::getCustomerEmail($id).- The model selects only
email_body AS emailfrom the table. - The controller echoes the raw HTML content directly (no layout wrapping).
Viewing Customer History (Admin)
- On the customer admin detail page, the customer management controller calls
customer_message_history_model::getCustomerEmails($customerId). - Returns all emails for that customer, ordered by insert order.
- Displayed in a table showing date, type, subject, with a link to view the full body.
Cleanup Job
- The
ClearOldEmailsscheduled job callscustomer_message_history_model::deleteEmailBeforeDate($date). - This removes all records older than the specified date to prevent table bloat.
- Configured in
application/config/jobs.phpwith a default schedule of30 0 * * *(daily at 00:30).
Domain Layer
No modern domain layer. Mail history is managed entirely through the legacy model.
Architecture
| Component | Path | Purpose |
|---|---|---|
Adv_customer_mail_history | ecommercen/eshop/controllers/Adv_customer_mail_history.php | Storefront controller (23 lines) |
Customer_mail_history | application/modules/eshop/controllers/Customer_mail_history.php | App-level wrapper |
Adv_customer_message_history_model | ecommercen/eshop/models/Adv_customer_message_history_model.php | Model with record/retrieval/cleanup (42 lines) |
Customer_message_history_model | application/modules/eshop/models/Customer_message_history_model.php | App-level wrapper |
| Routes | application/config/routes.php:605 | mail_history/(.+) -> eshop/customer_mail_history/$1 |
Data Model
shop_customer_message_history
| Column | Type | Description |
|---|---|---|
id | int (PK) | Auto-increment primary key |
user_id | int (FK) | Customer ID |
datetime | datetime | When the email was sent |
type | varchar | Purpose/category of the email (e.g., order_confirmation, shipping_notification) |
message_type | varchar | Delivery channel: email or sms |
subject | varchar | Email subject line |
email_body | longtext | Full HTML body of the email |
Configuration
| Source | Key | Description |
|---|---|---|
| Job config | application/config/jobs.php ClearOldEmails | Schedule for purging old email records |
| Job options | Per-client options.days | Number of days to retain (client-configurable) |
Client Extension Points
- Override model: Extend
Customer_message_history_modelinapplication/modules/eshop/models/to add custom record fields or retrieval methods. - Override controller: Extend
Customer_mail_historyinapplication/modules/eshop/controllers/to add authentication or custom rendering. - Custom cleanup: Override the
ClearOldEmailsjob command or configureoptions.daysinapplication/config/jobs.php.
Business Rules
- No authentication on view: The
view()endpoint extendsFront_cand does not check if the requester is the email's recipient. Security relies on the URL being hard to guess (numeric ID). - Raw HTML output: The email body is echoed directly without sanitization -- it contains the exact HTML that was sent.
- Automatic cleanup: The
ClearOldEmailsjob removes old records to prevent table bloat. - Multi-channel: The
message_typefield supports bothemailandsms, though SMS messages typically have noemail_body.
Related Flows
- AD-04 Customer Management Admin -- Customer detail page displays email history
- SY-02 Order Status Emails -- Status change emails are recorded here
- SY-01 Cron Framework --
ClearOldEmailsjob runs on the cron schedule