CategoryPriceSyncTrait
Propagates the category price list (matrix of {@see CategoryPriceInterface}) and the free flag (`forFree`) to the whole subtree; opt-in via `meta['setPricesToChildren']` from the admin form.
Prices of the edited category are saved through the object graph (owned collection prices);
this trait handles only the optional propagation: each descendant gets the same forFree and
a copy of the prices (delete-all + insert via updateColumn). Parallel to parameter targeting,
see CategoryParameterRelSyncTrait::propagateParameterRelsToDescendants().
IMPORTANT: the module CategoryPrice has its FK in the composite PK through the category association
(#[ORM\Id]); the mapper's raw insert
(SaveTrait::insertRelations()) writes the FK column
from getCategoryId(), so a copy must call setCategoryId(descendant), otherwise the FK is null.
Tags
Table of Contents
Methods
- newCategoryPrice() : CategoryPriceInterface
- A new, empty price entity of the module (Api layer), filled as a copy for a descendant.
- buildCategoryPriceCopies() : array<int, CategoryPriceInterface>
- extractCategoryPriceData() : array<int, array{regionId: int, gateId: int, currencyId: int, price: string, priceForUnlogged: ?string, active: bool}>
- Extracts flat data (region/gate/currency/price/active) from the owned price collection for copying.
- findCategoryDescendantIds() : array<int, int>
- Returns ids of all descendants of a category (nested-set subtree, without the root), using fresh lft/rgt from the DB (an in-memory entity may have zero indexes after insert).
- propagateCategoryPrices() : void
Methods
newCategoryPrice()
A new, empty price entity of the module (Api layer), filled as a copy for a descendant.
protected
abstract newCategoryPrice() : CategoryPriceInterface
Return values
CategoryPriceInterfacebuildCategoryPriceCopies()
private
buildCategoryPriceCopies(int $categoryId, array<int, array{regionId: int, gateId: int, currencyId: int, price: string, priceForUnlogged: ?string, active: bool}> $priceData) : array<int, CategoryPriceInterface>
Parameters
- $categoryId : int
- $priceData : array<int, array{regionId: int, gateId: int, currencyId: int, price: string, priceForUnlogged: ?string, active: bool}>
Return values
array<int, CategoryPriceInterface>extractCategoryPriceData()
Extracts flat data (region/gate/currency/price/active) from the owned price collection for copying.
private
extractCategoryPriceData(iterable<string|int, object> $prices) : array<int, array{regionId: int, gateId: int, currencyId: int, price: string, priceForUnlogged: ?string, active: bool}>
Parameters
- $prices : iterable<string|int, object>
Return values
array<int, array{regionId: int, gateId: int, currencyId: int, price: string, priceForUnlogged: ?string, active: bool}>findCategoryDescendantIds()
Returns ids of all descendants of a category (nested-set subtree, without the root), using fresh lft/rgt from the DB (an in-memory entity may have zero indexes after insert).
private
findCategoryDescendantIds(int $categoryId) : array<int, int>
Parameters
- $categoryId : int
Return values
array<int, int>propagateCategoryPrices()
private
propagateCategoryPrices(PricedCategoryInterface $category, array<string, mixed> $meta) : void
Parameters
- $category : PricedCategoryInterface
- $meta : array<string, mixed>