Voucher
extends BaseEntity
in package
implements
IdentifiableInterface
uses
IdentifiableTrait
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
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]
$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
$thiscallInitMethods()
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
boolgetCode()
public
getCode() : string
Return values
stringgetCurrentNumber()
public
getCurrentNumber() : int
Return values
intgetEndDatetime()
public
getEndDatetime() : DateTime|null
Return values
DateTime|nullgetHasPercents()
public
getHasPercents() : bool
Return values
boolgetId()
public
getId() : int|null
Return values
int|nullgetMaxNumber()
public
getMaxNumber() : int
Return values
intgetPercents()
public
getPercents() : int
Return values
intgetPriceForCurrency()
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|nullgetPrices()
public
getPrices() : Collection<int, TPrice>
Return values
Collection<int, TPrice>getStartDatetime()
public
getStartDatetime() : DateTime|null
Return values
DateTime|nullisAvailable()
public
isAvailable() : bool
Return values
boolisPersisted()
public
isPersisted() : bool
Return values
boolsetAvailable()
public
setAvailable(bool $available) : $this
Parameters
- $available : bool
Return values
$thissetCode()
public
setCode(string $code) : $this
Parameters
- $code : string
Return values
$thissetCurrentNumber()
public
setCurrentNumber(int $currentNumber) : $this
Parameters
- $currentNumber : int
Return values
$thissetEndDatetime()
public
setEndDatetime(DateTime|null $endDatetime) : $this
Parameters
- $endDatetime : DateTime|null
Return values
$thissetHasPercents()
public
setHasPercents(bool $hasPercents) : $this
Parameters
- $hasPercents : bool
Return values
$thissetId()
public
setId(int|null $id) : $this
Parameters
- $id : int|null
Return values
$thissetMaxNumber()
public
setMaxNumber(int $maxNumber) : $this
Parameters
- $maxNumber : int
Return values
$thissetPercents()
public
setPercents(int $percents) : $this
Parameters
- $percents : int
Return values
$thissetPrices()
public
setPrices(Collection<int, TPrice>|array<int, TPrice> $prices) : $this
Parameters
- $prices : Collection<int, TPrice>|array<int, TPrice>
Return values
$thissetStartDatetime()
public
setStartDatetime(DateTime|null $startDatetime) : $this
Parameters
- $startDatetime : DateTime|null
Return values
$thisgetTraitsRecursive()
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>