CoolCMS API

VoucherPickerTrait

Voucher picker for a row of the order `vouchers` multiplier, like {@see OrderGiftPickerTrait::orderGiftPicker()}.

IMPORTANT: the field of truth for the server stays code, not the numeric id. VoucherRedemptionService validates and snapshots exclusively by the code string (OrderFormTrait::orderPayloadVoucherCodes() must not change). So code is also the picker displayField, a real text control that survives the AJAX row re-render and stays manually editable; the hidden voucherId is only picker bookkeeping (where the picker JS writes the chosen id) and the server never reads it.

The suggest narrows to meaningful vouchers: available=1 and valid at query time (startDatetime/endDatetime, the same windows as VoucherRedemptionService::applyVouchers()), which the generic filters (EqualFilter, OrFilter, IsNullFilter) cover. An exhausted limit (currentNumber < maxNumber, maxNumber=0 means no limit) compares two columns of one entity, which the generic filters cannot do, so it is deliberately not filtered: the admin sees an exhausted voucher in the suggest, and VoucherRedemptionService rejects its redemption on save anyway. Requires $this->voucherManager.

Table of Contents

Methods

orderVoucherPicker()  : PickerConfig
resolveOrderVoucherLabel()  : string|null
suggestOrderVouchers()  : array<int, array{id: int, label: string}>

Methods

orderVoucherPicker()

protected orderVoucherPicker([string $container = 'vouchers' ][, string $targetField = 'voucherId' ][, string $displayField = 'code' ][, string $formName = 'editForm' ]) : PickerConfig
Parameters
$container : string = 'vouchers'
$targetField : string = 'voucherId'
$displayField : string = 'code'
$formName : string = 'editForm'
Return values
PickerConfig

resolveOrderVoucherLabel()

private resolveOrderVoucherLabel(int $id) : string|null
Parameters
$id : int
Return values
string|null

suggestOrderVouchers()

private suggestOrderVouchers(string $query) : array<int, array{id: int, label: string}>
Parameters
$query : string
Return values
array<int, array{id: int, label: string}>
On this page

Search results