CoolCMS API

StockItemFormTrait

Add/edit form of a stock item: multilingual texts (name/description, like {@see WarehouseFormTrait}), main fields (code/ean/unit/minQuantity) and the default supplier (Picker, single-field FK association, object graph).

IMPORTANT: it does not contain levels, batches or movements; they live in separate read-only tabs (see StockItemPresenter) and the item maps only translations. Mapping them would make an object-graph save silently delete stock levels.

Table of Contents

Methods

createComponentEditForm()  : Form
addStockItemMainFields()  : void
Code (SKU), EAN, unit, minimum stock, activation.
addStockItemTranslationFields()  : void
Multilingual texts (name/description), active by checkbox.
applyUnit()  : void
Writes the code list choice and the abbreviation to print.
buildStockItemEntity()  : StockItem
getDefaultUnitId()  : int|null
Default for a new item: the first unit of the code list by order.
getUnitOptions()  : array<int, NotTranslate>
Unit code list for the select: `unit_id => "code (name)"`. Only active items: a deactivated unit is not offered, but nothing is taken from items that already have it.
saveStockItemForm()  : bool
setStockItemFormDefaults()  : void
unitName()  : string
Unit name in the current language; when missing, the first non-empty translation.

Methods

addStockItemMainFields()

Code (SKU), EAN, unit, minimum stock, activation.

private addStockItemMainFields(Form $form) : void
Parameters
$form : Form

addStockItemTranslationFields()

Multilingual texts (name/description), active by checkbox.

private addStockItemTranslationFields(Form $form) : void
Parameters
$form : Form

applyUnit()

Writes the code list choice and the abbreviation to print.

private applyUnit(StockItem $stockItem, mixed $unitId) : void

unit (text) is printed by the item overview and the stocktake sheet; it is kept denormalized so that deleting a unit from the code list does not leave a stocktake without its unit. Without a valid choice the text is not overwritten: an existing item keeps it, a new one gets ks.

Parameters
$stockItem : StockItem
$unitId : mixed

buildStockItemEntity()

private buildStockItemEntity(ArrayHash<string|int, mixed> $values) : StockItem
Parameters
$values : ArrayHash<string|int, mixed>
Return values
StockItem

getDefaultUnitId()

Default for a new item: the first unit of the code list by order.

private getDefaultUnitId() : int|null
Return values
int|null

getUnitOptions()

Unit code list for the select: `unit_id => "code (name)"`. Only active items: a deactivated unit is not offered, but nothing is taken from items that already have it.

private getUnitOptions() : array<int, NotTranslate>

The text is built from DB data (unit code + name), not a key: NotTranslate, otherwise the form domain translator looks it up as a key and Tracy reports a missing translation.

Return values
array<int, NotTranslate>

saveStockItemForm()

private saveStockItemForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
$values : ArrayHash<string|int, mixed>
Return values
bool

unitName()

Unit name in the current language; when missing, the first non-empty translation.

private unitName(Unit $unit) : string
Parameters
$unit : Unit
Return values
string
On this page

Search results