PriceFormatContext
in package
Overrides the amount format used when rendering an invoice (document).
A document must not be formatted by the current request: an admin with a switched
localization would regenerate an old invoice and its numbers would differ from the original
PDF. The document stores its localization at creation and the generator sets it here for the
duration of the render. PriceLatteExtension reads this override first and only then the
ambient LocalizationContext, so templates stay unchanged (invoice PDF templates live
in the database).
Usage (always with try/finally):
$this->priceFormatContext->override($invoice->getLocalization());
try { $abs = $this->pdfGenerator->generate(...); } finally { $this->priceFormatContext->reset(); }
IMPORTANT: without finally the localization leaks into the next render in the same request,
and bulk document generation would format every document by the first one.
The service is per DI container (one per web request); long-running processes (cron, CLI) must call reset().
Table of Contents
Properties
- $documentMode : bool
- $languageId : int|null
- Language of the unit label after the amount (currency `unit_label`, e.g. "credits").
- $localization : object|null
Methods
- getLanguageId() : int|null
- getLocalization() : object|null
- hasOverride() : bool
- isDocument() : bool
- override() : self
- Sets the override; a null localization is valid (a document without a stored localization falls back to the currency).
- overrideForDocument() : self
- Enables accounting document mode: on top of the localization it forces fixed decimal places and suppresses the `,-` suffix on every amount.
- reset() : self
- runWith() : T
- Runs `$render` with the customer's format (order localization + language), then restores the previous state instead of calling `reset()`, because an e-mail may be rendered inside another override that must survive. For e-mails; documents use {@see overrideForDocument()}.
Properties
$documentMode
private
bool
$documentMode
= false
$languageId
Language of the unit label after the amount (currency `unit_label`, e.g. "credits").
private
int|null
$languageId
= null
Null means the current request language. E-mails and order documents render in the customer's language even when an admin triggered the state change.
$localization
private
object|null
$localization
= null
Methods
getLanguageId()
public
getLanguageId() : int|null
Return values
int|nullgetLocalization()
public
getLocalization() : object|null
Return values
object|nullhasOverride()
public
hasOverride() : bool
Return values
boolisDocument()
public
isDocument() : bool
Return values
booloverride()
Sets the override; a null localization is valid (a document without a stored localization falls back to the currency).
public
override(object|null $localization[, int|null $languageId = null ]) : self
Parameters
- $localization : object|null
- $languageId : int|null = null
Return values
selfoverrideForDocument()
Enables accounting document mode: on top of the localization it forces fixed decimal places and suppresses the `,-` suffix on every amount.
public
overrideForDocument(object|null $localization[, int|null $languageId = null ]) : self
The ,- suffix is a price list notation and would mix up columns on a document (1.000,-
above 210,00). Applies to all document types (order, invoice, proforma, cancellation,
credit note); the front end and the shop keep ,-.
Parameters
- $localization : object|null
- $languageId : int|null = null
Return values
selfreset()
public
reset() : self
Return values
selfrunWith()
Runs `$render` with the customer's format (order localization + language), then restores the previous state instead of calling `reset()`, because an e-mail may be rendered inside another override that must survive. For e-mails; documents use {@see overrideForDocument()}.
public
runWith(object|null $localization, int|null $languageId, callable(): T $render) : T
Parameters
- $localization : object|null
- $languageId : int|null
- $render : callable(): T