CoolCMS API

Voucher extends BaseEntity
in package
implements IdentifiableInterface uses IdentifiableTrait

AbstractYes

Discount coupon. `code` is unique. Either percentage (`hasPercents` + `percents`) or a fixed amount per currency ({@see VoucherPrice::$price}). Vouchers on an order add up (sum of percents capped at 100 + sum of fixed amounts; see `OrderCalculator`).

currentNumber is the count of active redemptions: increment on order save and decrement on cancellation are done only by VoucherManager (atomic sql update); #[ExternalReadonly], so the external API must not overwrite it.

Tags
template
Attributes
#[MappedSuperclass]
#[TableAlias]
$alias: 'voucher'

Table of Contents

Interfaces

IdentifiableInterface
Entity with a simple integer primary key. Most entities have one (often via {@see \App\Core\Traits\Shared\Models\Entities\IdentifiableTrait}); texts and links with a composite key do not, which is why `getId()` is not on {@see \App\Core\Base\BaseEntity}. Code that needs the id of a generic entity asks for this interface (parameter type, template bound, `instanceof`).

Properties

$available  : bool
$code  : string
$currentNumber  : int
$endDatetime  : DateTime|null
$hasPercents  : bool
$id  : int|null
$maxNumber  : int
$percents  : int
$prices  : Collection<int, TPrice>
$startDatetime  : DateTime|null

Methods

__construct()  : mixed
addPrice()  : $this
callInitMethods()  : void
Calls `init{TraitName}()` for every used trait that defines such a method.
getAllTraits()  : array<string, string>
Returns all traits the class uses, including those used by parent classes and nested traits.
getAvailable()  : bool
getCode()  : string
getCurrentNumber()  : int
getEndDatetime()  : DateTime|null
getHasPercents()  : bool
getId()  : int|null
getMaxNumber()  : int
getPercents()  : int
getPriceForCurrency()  : TPrice|null
Price row of the voucher for a currency (min/max cart + fixed discount); null means no row, so the voucher is not valid in that currency.
getPrices()  : Collection<int, TPrice>
getStartDatetime()  : DateTime|null
isAvailable()  : bool
isPersisted()  : bool
setAvailable()  : $this
setCode()  : $this
setCurrentNumber()  : $this
setEndDatetime()  : $this
setHasPercents()  : $this
setId()  : $this
setMaxNumber()  : $this
setPercents()  : $this
setPrices()  : $this
setStartDatetime()  : $this
getTraitsRecursive()  : array<string, string>
Walks the trait list recursively and collects nested traits too.

Properties

$available

protected bool $available = true
Attributes
#[Column]
$name: 'available'
$type: 'boolean'

$code

protected string $code = ''
Attributes
#[Column]
$name: 'code'
$type: 'string'
$length: 80

$currentNumber

protected int $currentNumber = 0
Attributes
#[Column]
$name: 'current_number'
$type: 'integer'
$options: ['unsigned' => true]
#[ExternalReadonly]

$endDatetime

protected DateTime|null $endDatetime = null
Attributes
#[Column]
$name: 'end_datetime'
$type: 'datetime'

$hasPercents

protected bool $hasPercents = false
Attributes
#[Column]
$name: 'has_percents'
$type: 'boolean'

$id

protected int|null $id = null
Attributes
#[Column]
$name: 'voucher_id'
$type: 'integer'
$options: ['unsigned' => true]
#[GeneratedValue]
#[Id]

$maxNumber

protected int $maxNumber = 0
Attributes
#[Column]
$name: 'max_number'
$type: 'integer'
$options: ['unsigned' => true]

$percents

protected int $percents = 0
Attributes
#[Column]
$name: 'percents'
$type: 'integer'
$options: ['unsigned' => true]

$prices

protected Collection<int, TPrice> $prices = new ArrayCollection()

$startDatetime

protected DateTime|null $startDatetime = null
Attributes
#[Column]
$name: 'start_datetime'
$type: 'datetime'

Methods

__construct()

public __construct([int|null $id = null ][, string $code = '' ][, bool $hasPercents = false ][, int $percents = 0 ][, DateTime|null $startDatetime = null ][, DateTime|null $endDatetime = null ][, int $maxNumber = 0 ][, int $currentNumber = 0 ][, bool $available = true ][, Collection $prices = new ArrayCollection() ]) : mixed
Parameters
$id : int|null = null
$code : string = ''
$hasPercents : bool = false
$percents : int = 0
$startDatetime : DateTime|null = null
$endDatetime : DateTime|null = null
$maxNumber : int = 0
$currentNumber : int = 0
$available : bool = true
$prices : Collection = new ArrayCollection()

addPrice()

public addPrice(TPrice $price) : $this
Parameters
$price : TPrice
Return values
$this

callInitMethods()

Calls `init{TraitName}()` for every used trait that defines such a method.

public callInitMethods() : void

getAllTraits()

Returns all traits the class uses, including those used by parent classes and nested traits.

public getAllTraits() : array<string, string>
Return values
array<string, string>

getAvailable()

public getAvailable() : bool
Return values
bool

getCode()

public getCode() : string
Return values
string

getCurrentNumber()

public getCurrentNumber() : int
Return values
int

getEndDatetime()

public getEndDatetime() : DateTime|null
Return values
DateTime|null

getHasPercents()

public getHasPercents() : bool
Return values
bool

getMaxNumber()

public getMaxNumber() : int
Return values
int

getPercents()

public getPercents() : int
Return values
int

getPriceForCurrency()

Price row of the voucher for a currency (min/max cart + fixed discount); null means no row, so the voucher is not valid in that currency.

public getPriceForCurrency(int $currencyId) : TPrice|null
Parameters
$currencyId : int
Return values
TPrice|null

getPrices()

public getPrices() : Collection<int, TPrice>
Return values
Collection<int, TPrice>

getStartDatetime()

public getStartDatetime() : DateTime|null
Return values
DateTime|null

isAvailable()

public isAvailable() : bool
Return values
bool

setAvailable()

public setAvailable(bool $available) : $this
Parameters
$available : bool
Return values
$this

setCode()

public setCode(string $code) : $this
Parameters
$code : string
Return values
$this

setCurrentNumber()

public setCurrentNumber(int $currentNumber) : $this
Parameters
$currentNumber : int
Return values
$this

setEndDatetime()

public setEndDatetime(DateTime|null $endDatetime) : $this
Parameters
$endDatetime : DateTime|null
Return values
$this

setHasPercents()

public setHasPercents(bool $hasPercents) : $this
Parameters
$hasPercents : bool
Return values
$this

setId()

public setId(int|null $id) : $this
Parameters
$id : int|null
Return values
$this

setMaxNumber()

public setMaxNumber(int $maxNumber) : $this
Parameters
$maxNumber : int
Return values
$this

setPercents()

public setPercents(int $percents) : $this
Parameters
$percents : int
Return values
$this

setPrices()

public setPrices(Collection<int, TPrice>|array<int, TPrice> $prices) : $this
Parameters
$prices : Collection<int, TPrice>|array<int, TPrice>
Return values
$this

setStartDatetime()

public setStartDatetime(DateTime|null $startDatetime) : $this
Parameters
$startDatetime : DateTime|null
Return values
$this

getTraitsRecursive()

Walks the trait list recursively and collects nested traits too.

private static getTraitsRecursive(array<string, string> $traits) : array<string, string>
Parameters
$traits : array<string, string>
Return values
array<string, string>
On this page

Search results