CoolCMS API

ImportBundleWriter
in package

FinalYes

Writes one `<bundle>` (`ProductSet` of `type=2`, no card, variant or stock) exclusively through the existing Api managers.

Texts, tags, prices and images use the same channels as a variant, so this writer injects ImportProductWriter and calls its public applySetTexts(), applyTags(), applyPrices() and applyImages(). applyStock(), parameters and accessories are not called: a bundle has none.

Composition (<items>) is resolved immediately, not in a second pass: ProductSetManager::beforeSave() (validateComposition()) requires at least one item on every save of a type=2 set, so the set cannot be saved first and completed later. Item codes are therefore resolved before the first save(). The validator (ImportValidator::validateBundles()) guarantees every code is resolvable against seenCodes or the database. Product variants are always in codeToSetId (products are processed before bundles); another bundle only when it appears earlier in the file. A bundle referencing a later bundle is unsupported: the item is not attached and the set gets importIncomplete (soft error, no crash).

Table of Contents

Properties

$em  : EntityManagerInterface
$productSetManager  : ProductSetManager
$productWriter  : ImportProductWriter
$unitOfWorkReset  : UnitOfWorkReset

Methods

__construct()  : mixed
write()  : void
applyBundleFields()  : bool
Applies only `activated` and `vat`; a bundle has none of the other variant scalars (ean, isbn, unit, weight, ...).
applyItemRows()  : void
Mutates `$set->getSetItems()` in place to exactly `$childRows` (always a full replacement, also on create where the collection is empty). A row whose `childSetId` stays in the new composition is only overwritten (`setCount()`) on the existing entity: deleting and re-creating the same composite key (parent + child) collides in the identity map with the entity being removed (an update with the same composition failed with a duplicate ID hash error). See {@see ImportProductWriter::writeAccessoryCollection()}.
applyVat()  : void
countFailure()  : void
A failed bundle write is an item error. With `stopOnError` it sets `stopped` and the executor writes no further bundles. Already written items are not rolled back.
createBundle()  : void
recoverEntityManager()  : void
Closes the EM after a failed flush, as {@see ImportProductWriter} does; the next bundle would fail too otherwise.
resolveActivated()  : bool
resolveItemRows()  : array{0: array, 1: bool}
Resolves item codes to set ids: first sets touched by this run (product variants always, another bundle only if it appears earlier in the file), then the database. `<items>` has no `collectionMode`, so the returned rows are always the full composition to write.
resolveItemTarget()  : int|null
updateBundle()  : void

Properties

Methods

applyItemRows()

Mutates `$set->getSetItems()` in place to exactly `$childRows` (always a full replacement, also on create where the collection is empty). A row whose `childSetId` stays in the new composition is only overwritten (`setCount()`) on the existing entity: deleting and re-creating the same composite key (parent + child) collides in the identity map with the entity being removed (an update with the same composition failed with a duplicate ID hash error). See {@see ImportProductWriter::writeAccessoryCollection()}.

private applyItemRows(ProductSet $set, array<int, int> $childRows) : void
Parameters
$set : ProductSet
$childRows : array<int, int>

childSetId => count

recoverEntityManager()

Closes the EM after a failed flush, as {@see ImportProductWriter} does; the next bundle would fail too otherwise.

private recoverEntityManager() : void

resolveItemRows()

Resolves item codes to set ids: first sets touched by this run (product variants always, another bundle only if it appears earlier in the file), then the database. `<items>` has no `collectionMode`, so the returned rows are always the full composition to write.

private resolveItemRows(ImportBundleDto $bundle, ImportBundleVerdict $verdict, ImportExecutionContext $context) : array{0: array, 1: bool}
Parameters
$bundle : ImportBundleDto
$verdict : ImportBundleVerdict
$context : ImportExecutionContext
Return values
array{0: array, 1: bool} —

[childSetId => count, whether some item could not be found]

On this page

Search results