ImportBundleWriter
in package
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
$em read-only
private
EntityManagerInterface
$em
$productSetManager read-only
private
ProductSetManager
$productSetManager
$productWriter read-only
private
ImportProductWriter
$productWriter
$unitOfWorkReset read-only
private
UnitOfWorkReset
$unitOfWorkReset
Methods
__construct()
public
__construct(ProductSetManager $productSetManager, ImportProductWriter $productWriter, EntityManagerInterface $em, UnitOfWorkReset $unitOfWorkReset) : mixed
Parameters
- $productSetManager : ProductSetManager
- $productWriter : ImportProductWriter
- $em : EntityManagerInterface
- $unitOfWorkReset : UnitOfWorkReset
write()
public
write(ImportBundleDto $bundle, ImportBundleVerdict $verdict, ImportExecutionContext $context) : void
Parameters
- $bundle : ImportBundleDto
- $verdict : ImportBundleVerdict
- $context : ImportExecutionContext
applyBundleFields()
Applies only `activated` and `vat`; a bundle has none of the other variant scalars (ean, isbn, unit, weight, ...).
private
applyBundleFields(ProductSet $set, ImportBundleDto $bundle, bool $isInsert, ImportExecutionContext $context) : bool
Parameters
- $set : ProductSet
- $bundle : ImportBundleDto
- $isInsert : bool
- $context : ImportExecutionContext
Return values
boolapplyItemRows()
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
applyVat()
private
applyVat(ProductSet $set, string $raw, ImportExecutionContext $context) : void
Parameters
- $set : ProductSet
- $raw : string
- $context : ImportExecutionContext
countFailure()
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.
private
countFailure(ImportExecutionContext $context) : void
Parameters
- $context : ImportExecutionContext
createBundle()
private
createBundle(ImportBundleDto $bundle, ImportBundleVerdict $verdict, array<int, int> $childRows, bool $itemsIncomplete, ImportExecutionContext $context) : void
Parameters
- $bundle : ImportBundleDto
- $verdict : ImportBundleVerdict
- $childRows : array<int, int>
-
childSetId → count
- $itemsIncomplete : bool
- $context : ImportExecutionContext
recoverEntityManager()
Closes the EM after a failed flush, as {@see ImportProductWriter} does; the next bundle would fail too otherwise.
private
recoverEntityManager() : void
resolveActivated()
private
resolveActivated(ImportValue|null $value) : bool
Parameters
- $value : ImportValue|null
Return values
boolresolveItemRows()
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[childSetId => count, whether some item could not be found]
resolveItemTarget()
private
resolveItemTarget(string $code, ImportExecutionContext $context) : int|null
Parameters
- $code : string
- $context : ImportExecutionContext
Return values
int|nullupdateBundle()
private
updateBundle(ImportBundleDto $bundle, ImportBundleVerdict $verdict, array<int, int> $childRows, bool $itemsIncomplete, ImportExecutionContext $context) : void
Parameters
- $bundle : ImportBundleDto
- $verdict : ImportBundleVerdict
- $childRows : array<int, int>
-
childSetId → count
- $itemsIncomplete : bool
- $context : ImportExecutionContext