# emizentech/magento2-customordernumber architecture

> Architecture diagram of the GitHub repository emizentech/magento2-customordernumber, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/emizentech/magento2-customordernumber
- Repository: https://github.com/emizentech/magento2-customordernumber

## Overview

This Magento 2 module customizes order and invoice increment IDs. Magento’s order and invoice lifecycle events invoke separate observers; each reads store settings, advances its own persisted counter, and saves a prefixed/suffixed ID to the sales entity. The schema defines the two counter tables. Event registration and admin configuration exist in the tree, but their contents were not sampled, so those wiring details are not asserted.

Main entry points: [`Observer/ChangeOrderId.php`](https://github.com/emizentech/magento2-customordernumber/blob/master/Observer/ChangeOrderId.php) (Order numbering), [`Observer/ChangeInvoiceId.php`](https://github.com/emizentech/magento2-customordernumber/blob/master/Observer/ChangeInvoiceId.php) (Invoice numbering), [`Model/Orderid.php`](https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Orderid.php) (Order counter model), [`Model/Invoiceid.php`](https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Invoiceid.php) (Invoice counter model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_numbering["Number generation"]
  node_orders["Order numbering<br/>[ChangeOrderId.php]"]
  node_invoices["Invoice numbering"]
end

subgraph group_persistence["Counter persistence"]
  node_order_model["Order counter model<br/>[Orderid.php]"]
  node_invoice_model["Invoice counter model<br/>[Invoiceid.php]"]
  node_order_resource["Order counter resource<br/>[Orderid.php]"]
  node_invoice_resource["Invoice counter resource<br/>[Invoiceid.php]"]
  node_order_collection["Order counter collection<br/>[Collection.php]"]
  node_invoice_collection["Invoice counter collection<br/>[Collection.php]"]
end

subgraph group_setup["Module setup"]
  node_schema["Counter schema<br/>[InstallSchema.php]"]
  node_event_config["Event configuration<br/>[events.xml]"]
  node_admin_config["Admin settings<br/>[system.xml]"]
  node_module_config["Default settings<br/>[config.xml]"]
end

node_sales["Magento Sales"]
node_storeconfig["Store settings"]
node_counter_db[("Counter tables")]

node_sales -.->|"invokes order observer"| node_orders
node_sales -.->|"invokes invoice observer"| node_invoices
node_orders -->|"reads settings"| node_storeconfig
node_invoices -->|"reads settings"| node_storeconfig
node_orders -->|"updates counter"| node_order_model
node_invoices -->|"updates counter"| node_invoice_model
node_orders -->|"saves order ID"| node_sales
node_invoices -->|"saves invoice ID"| node_sales
node_order_model -->|"uses resource"| node_order_resource
node_invoice_model -->|"uses resource"| node_invoice_resource
node_order_collection -->|"initializes collection"| node_order_model
node_order_collection -->|"initializes collection"| node_order_resource
node_invoice_collection -->|"initializes collection"| node_invoice_model
node_invoice_collection -->|"initializes collection"| node_invoice_resource
node_schema -->|"creates tables"| node_counter_db
node_order_resource -->|"accesses order table"| node_counter_db
node_invoice_resource -->|"accesses invoice table"| node_counter_db

click node_orders "https://github.com/emizentech/magento2-customordernumber/blob/master/Observer/ChangeOrderId.php"
click node_invoices "https://github.com/emizentech/magento2-customordernumber/blob/master/Observer/ChangeInvoiceId.php"
click node_order_model "https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Orderid.php"
click node_invoice_model "https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Invoiceid.php"
click node_order_resource "https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Resource/Orderid.php"
click node_invoice_resource "https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Resource/Invoiceid.php"
click node_order_collection "https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Resource/orderid/Collection.php"
click node_invoice_collection "https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Resource/invoiceid/Collection.php"
click node_schema "https://github.com/emizentech/magento2-customordernumber/blob/master/Setup/InstallSchema.php"
click node_event_config "https://github.com/emizentech/magento2-customordernumber/blob/master/etc/events.xml"
click node_admin_config "https://github.com/emizentech/magento2-customordernumber/blob/master/etc/adminhtml/system.xml"
click node_module_config "https://github.com/emizentech/magento2-customordernumber/blob/master/etc/config.xml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_orders,node_invoices toneBlue
class node_order_model,node_invoice_model,node_order_resource,node_invoice_resource,node_order_collection,node_invoice_collection,node_counter_db toneAmber
class node_schema,node_event_config,node_admin_config,node_module_config toneMint
class node_sales,node_storeconfig toneIndigo
```

## Components

### Number generation

- [Order numbering](https://github.com/emizentech/magento2-customordernumber/blob/master/Observer/ChangeOrderId.php): `Observer/ChangeOrderId.php`
- [Invoice numbering](https://github.com/emizentech/magento2-customordernumber/blob/master/Observer/ChangeInvoiceId.php): `Observer/ChangeInvoiceId.php`

### Counter persistence

- [Order counter model](https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Orderid.php): `Model/Orderid.php`
- [Invoice counter model](https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Invoiceid.php): `Model/Invoiceid.php`
- [Order counter resource](https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Resource/Orderid.php): `Model/Resource/Orderid.php`
- [Invoice counter resource](https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Resource/Invoiceid.php): `Model/Resource/Invoiceid.php`
- [Order counter collection](https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Resource/orderid/Collection.php): `Model/Resource/orderid/Collection.php`
- [Invoice counter collection](https://github.com/emizentech/magento2-customordernumber/blob/master/Model/Resource/invoiceid/Collection.php): `Model/Resource/invoiceid/Collection.php`

### Module setup

- [Counter schema](https://github.com/emizentech/magento2-customordernumber/blob/master/Setup/InstallSchema.php): `Setup/InstallSchema.php`
- [Event configuration](https://github.com/emizentech/magento2-customordernumber/blob/master/etc/events.xml): `etc/events.xml`
- [Admin settings](https://github.com/emizentech/magento2-customordernumber/blob/master/etc/adminhtml/system.xml): `etc/adminhtml/system.xml`
- [Default settings](https://github.com/emizentech/magento2-customordernumber/blob/master/etc/config.xml): `etc/config.xml`

### Other components

- **Magento Sales**
- **Store settings**
- **Counter tables**

## Connections

- Magento Sales → Order numbering: invokes order observer
- Magento Sales → Invoice numbering: invokes invoice observer
- Order numbering → Store settings: reads settings (evidence: `Observer/ChangeOrderId.php`)
- Invoice numbering → Store settings: reads settings (evidence: `Observer/ChangeInvoiceId.php`)
- Order numbering → Order counter model: updates counter (evidence: `Observer/ChangeOrderId.php`)
- Invoice numbering → Invoice counter model: updates counter (evidence: `Observer/ChangeInvoiceId.php`)
- Order numbering → Magento Sales: saves order ID (evidence: `Observer/ChangeOrderId.php`)
- Invoice numbering → Magento Sales: saves invoice ID (evidence: `Observer/ChangeInvoiceId.php`)
- Order counter model → Order counter resource: uses resource (evidence: `Model/Orderid.php`)
- Invoice counter model → Invoice counter resource: uses resource (evidence: `Model/Invoiceid.php`)
- Order counter collection → Order counter model: initializes collection (evidence: `Model/Resource/orderid/Collection.php`)
- Order counter collection → Order counter resource: initializes collection (evidence: `Model/Resource/orderid/Collection.php`)
- Invoice counter collection → Invoice counter model: initializes collection (evidence: `Model/Resource/invoiceid/Collection.php`)
- Invoice counter collection → Invoice counter resource: initializes collection (evidence: `Model/Resource/invoiceid/Collection.php`)
- Counter schema → Counter tables: creates tables (evidence: `Setup/InstallSchema.php`)
- Order counter resource → Counter tables: accesses order table (evidence: `Model/Resource/Orderid.php`)
- Invoice counter resource → Counter tables: accesses invoice table (evidence: `Model/Resource/Invoiceid.php`)
