OrderNumberGenerator
in package
Generates the order number: the year plus a sequence number taken under a lock.
Format: YYYYNNNNN (year and a zero-padded 5-digit sequence, e.g. 202600001; past 99999
the number simply grows longer). The variable symbol is the digits of the number and is set
only when it was not entered manually.
IMPORTANT: the critical section is SELECT ... FOR UPDATE on the year row of
cms_mod_eshop_order_number_series. It is held until the save transaction commits, because
the generator runs from OrderManager::beforeSave(), inside the already open transaction.
The year row is created by an idempotent insert before the lock. UNIQUE(order_number) is
only a backstop: a duplicate key would abort the transaction, the lock prevents it.
IMPORTANT: uses raw DBAL on purpose. Any find()/findAll() in a save hook would detach
the freshly hydrated order graph before the flush.
Tags
Table of Contents
Constants
- NUMBER_LENGTH : int = 5
- ORDER_TABLE : string = 'cms_mod_eshop_orders'
- SERIES_TABLE : string = 'cms_mod_eshop_order_number_series'
Properties
- $em : EntityManagerInterface
Methods
- __construct() : mixed
- generate() : bool
- Generates and sets `orderNumber`, and `variableSymbol` when it was not entered.
- numberExists() : bool
- Checks whether the number exists; raw DBAL for the same reason as {@see generate()}.
- buildNumber() : string
Constants
NUMBER_LENGTH
private
int
NUMBER_LENGTH
= 5
ORDER_TABLE
private
string
ORDER_TABLE
= 'cms_mod_eshop_orders'
SERIES_TABLE
private
string
SERIES_TABLE
= 'cms_mod_eshop_order_number_series'
Properties
$em read-only
private
EntityManagerInterface
$em
Methods
__construct()
public
__construct(EntityManagerInterface $em) : mixed
Parameters
- $em : EntityManagerInterface
generate()
Generates and sets `orderNumber`, and `variableSymbol` when it was not entered.
public
generate(TOrderGraph $order) : bool
The year comes from the order insertDatetime (now when missing). Returns false when the
year row cannot be locked.
Parameters
- $order : TOrderGraph
Return values
boolnumberExists()
Checks whether the number exists; raw DBAL for the same reason as {@see generate()}.
public
numberExists(string $number) : bool
Parameters
- $number : string
Return values
boolbuildNumber()
private
buildNumber(int $year, int $order) : string
Parameters
- $year : int
- $order : int