CoolCMS API

PriceFormatContext
in package

FinalYes

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

$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.

Methods

getLocalization()

public getLocalization() : object|null
Return values
object|null

override()

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
self

overrideForDocument()

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
self

runWith()

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
Tags
template
Return values
T
On this page

Search results