Skip to content

Internal Notes

Flow ID: AD-40 | Module(s): eshop | Complexity: Low Last Updated: 2026-04-04

Business Context

Internal notes provide a simple annotation system that allows admin users to attach free-text notes to various entities (orders, customers, products). Notes are used for internal communication between team members and are never visible to storefront customers.

Each note records the admin user who created it, the entity type and ID it relates to, and a timestamp. Notes are displayed chronologically (newest first) within the context of their parent entity's admin page.


API Reference

REST Endpoints

No REST API. Internal notes are managed exclusively through legacy AJAX endpoints.

Legacy Admin Routes

RouteControllerMethodHTTPDescription
notes/addNewNoteAdv_eshop_notesaddNewNotePOSTCreate a new note (AJAX, returns JSON)
notes/deleteNote/{id}Adv_eshop_notesdeleteNoteGETDelete a note by ID (returns bool)
notes/deleteSingleNote/{id}Adv_eshop_notesdeleteSingleNoteGETDelete and redirect back with flash message
notes/editNotesAdv_eshop_noteseditNotesPOSTUpdate a note's text (AJAX, returns JSON)

Code Flow

Adding a Note

  1. Admin is on an entity detail page (order, customer, or product).
  2. The entity page includes a notes panel with an AJAX form.
  3. POST to notes/addNewNote with { entity_type, entity_id, note }.
  4. Adv_eshop_notes::addNewNote() validates the note is not empty.
  5. Builds the record: entity_type, entity_id, user_id (from session $_SESSION['uid']), note_text, entry_date.
  6. Calls eshop_notes_model::addNewNote() which inserts into shop_notes.
  7. Returns JSON with the new note data including formatted entry_date.

Editing a Note

  1. POST to notes/editNotes with { entity_id (note ID), note }.
  2. editNotes() calls eshop_notes_model::updateNote() which updates note_text and entry_date to current timestamp.
  3. Returns the updated note object as JSON.

Deleting a Note

  1. deleteNote($id): Direct delete, returns boolean result (used by AJAX callers).
  2. deleteSingleNote($id): Deletes and sets a flash message, then redirects back to the referrer page. Used by non-AJAX delete buttons.

Retrieving Notes (Model Methods)

The model provides entity-specific retrieval methods called by entity admin controllers:

  • getCustomerNotes($entityId, $limit) -- filtered by entity_type = 'customer'
  • getProductNotes($id, $limit) -- filtered by entity_type = 'product'
  • getOrderNotes($id, $limit) -- filtered by entity_type = 'order'
  • getNotes($userId, $conditions, $limit, $offset) -- general query with search/filter support

Domain Layer

No modern domain layer. Notes are managed entirely through the legacy model.


Architecture

ComponentPathPurpose
Adv_eshop_notesecommercen/eshop/controllers/Adv_eshop_notes.phpAdmin controller (81 lines)
Adv_eshop_notes_modelecommercen/eshop/models/Adv_eshop_notes_model.phpModel with CRUD + entity-scoped queries (113 lines)
Eshop_notes_modelapplication/modules/eshop/models/Eshop_notes_model.phpApp-level wrapper
Routesapplication/config/routes.php:603-604notes/(.+) -> eshop/eshop_notes/$1

Data Model

shop_notes

ColumnTypeDescription
idint (PK)Auto-increment primary key
entity_typevarcharEntity type: customer, product, order
entity_idintID of the related entity
user_idintAdmin user ID who created the note
note_texttextFree-text note content
entry_datedatetimeCreation/last-edit timestamp

Configuration

No registry keys or config files. Access is controlled by role-based authorization.

Required roles: AUTH_ROLE_ADVISABLE, AUTH_ROLE_ADMIN, AUTH_ROLE_ORDERS, AUTH_ROLE_CMS.


Client Extension Points

  • Override model: Extend Eshop_notes_model in application/modules/eshop/models/ to add custom note types or retrieval logic.
  • Override controller: Extend Eshop_notes in application/modules/eshop/controllers/ to add custom validation or permissions.

Business Rules

  1. Empty note prevention: addNewNote() only inserts if the note POST field is non-empty.
  2. Entity polymorphism: Notes are polymorphic via entity_type + entity_id -- no FK constraints.
  3. Timestamp on edit: Editing a note updates its entry_date to the current time, so it appears as the most recent action.
  4. Session-based user tracking: The user_id is read directly from $_SESSION['uid'] (not from CI session).
  5. No cascading deletes: Deleting a parent entity (order, customer, product) does not automatically remove its notes.