By default the invoice number is generated by the page number.
$orderPage->invoiceNumber()
You can override this method to use a custom field.
To update the field a custom hook can be used.
By default the invoice number is generated by the page number.
$orderPage->invoiceNumber()
You can override this method to use a custom field.
To update the field a custom hook can be used.
You can override the default invoiceNumber()
method to return for example a content field. In this example the content of invoiceNumber field is returned.
<?php
class OrderPage extends OrderPageAbstract
{
public function invoiceNumber(): string
{
return $this->content()->invoiceNumber()->toString();
}
}
Be careful, the invoiceNumber()
method has to return a string
.
To update the invoiceNumber
content field you can use the completePayment:after
hook.
<?php
return [
'hooks' => [
'ww.merx.completePayment:after' => function ($orderPage) {
$invoiceNumber = 0;
if ($prevOrder = $orderPage->prevListed()) {
$invoiceNumber = (int)$prevOrder->invoiceNumber();
}
$invoiceNumber = $invoiceNumber + 1;
$orderPage->update([
'invoiceNumber' => $invoiceNumber,
]);
},
],
];
To return the invoice number you should use the custom $orderPage->invoiceNumber()
method.
<?php
echo 'Invoice Number: ';
echo $page->invoiceNumber();