Magento 2 Variables Guide for Custom Order Number Patterns

The Magento 2 Custom Order Number extension allows you to flexibly customize numbers for orders, sales notes, invoices, and more based on templates. This allows you to increase the visibility of documents, facilitates their administration and management, and ensures compliance with corporate standards or accounting requirements.

Below is a complete list of variables that can be used to build templates, their descriptions, and examples of how to use them.

Counter variable

The counter is used to gradually increase the numerical value with each new document in the system, which allows you to create consecutive numbers for convenient accounting.

The format of the {Ncounter} variable, where N determines the number of digits in the counter, sets a fixed length of the numeric value. For example, {6counter} will create a counter of 6 digits (e.g., 000001, 000002) and {4counter} will create a counter of 4 digits (e.g., 0001, 0002). This ensures that the number format is consistent, even with a large number of documents.

Examples

Template The result example
ORD-{6counter} ORD-000001, ORD-000002
INV-{4counter} INV-0001, INV-0002
SHP-{4counter} SHP-0001, SHP-0002

Date information variables

Date variables allow you to automatically include information in the document number based on the date the document was created. This allows you to create unique numbers that contain the date, making it easier to identify and track documents. Date variables can be used in a variety of formats to represent the day, month, or year – both numeric and text values.

List of supported variables:

Variable Description Example of values
{d} Day of the month without leading zeros 1 to 31
{dd} Day of the month, 2 digits with leading zeros 01 to 31
{m} Numeric representation of a month, without leading zeros 1 through 12
{mm} Numeric representation of a month, with leading zeros 01 through 12
{M} A short textual representation of a month, three letters JAN through DEC
{MM} A full textual representation of a month, such as January or August JANUARY through DECEMBER
{y} A two digit representation of a year 99, 05
{yyyy} A full numeric representation of a year, at least 4 digits 1999, 2005

Examples

Template The result example
ORD-{yyyy}-{m}-{dd}-{5counter} ORD-2024-11-05-00001
ORD-{yyyy}-{m}-{d}-{4counter} ORD-2024-11-5-0001
ORD-{yyyy}-{mm}-{dd}-{4counter} ORD-2024-11-05-0001
ORD-{yy}-{mm}-{dd}-{5counter} ORD-24-11-05-00001
ORD-{yy}-{M}-{d}-{6counter} ORD-24-Nov-5-000001
ORD-{yyyy}-{MM}-{dd}-{4counter} ORD-2024-Nov-05-0001

Store information variables

When building templates, it is also possible to use store information, which allows you to create more personalized numbers for different stores in the system. This is especially useful if you have multiple stores in the system and need to identify which store a particular document clearly belongs to.

List of supported variables:

Variable Description Example of values
{store_id} A unique numerical identifier of the store in the system 1, 2
{store_code} A unique store code used to identify a particular store in the system default, french

Examples

Template The result example
ORD-{store_code}-{yy}-{mm}-{dd}-{5counter} ORD-french-24-11-05-00001
ORD-{store_id}-{yyyy}-{MM}-{4counter} ORD-1-2024-Nov-0001

Was this article helpful?