Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

refactor product variant configuration #34

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 0 additions & 87 deletions src/Infrastructure/Mapper/Product/ProductVariantChildMapper.php

This file was deleted.

27 changes: 15 additions & 12 deletions src/Infrastructure/Mapper/Product/ProductVariantMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Ergonode\ExporterShopware6\Infrastructure\Mapper\Product;

use Ergonode\Attribute\Domain\Query\OptionQueryInterface;
use Ergonode\Attribute\Domain\Repository\AttributeRepositoryInterface;
use Ergonode\Attribute\Domain\Repository\OptionRepositoryInterface;
use Ergonode\Channel\Domain\Entity\Export;
Expand All @@ -21,27 +20,28 @@
use Ergonode\ExporterShopware6\Infrastructure\Model\Shopware6Product;
use Ergonode\Product\Domain\Entity\AbstractProduct;
use Ergonode\Product\Domain\Entity\VariableProduct;
use Ergonode\Product\Domain\Repository\ProductRepositoryInterface;
use Ergonode\Product\Infrastructure\Calculator\TranslationInheritanceCalculator;
use Ergonode\SharedKernel\Domain\Aggregate\AttributeId;
use Ergonode\SharedKernel\Domain\AggregateId;
use Webmozart\Assert\Assert;

class ProductVariantMapper extends AbstractVariantOptionMapper
{
private PropertyGroupRepositoryInterface $propertyGroupRepository;
private OptionQueryInterface $optionQuery;
protected ProductRepositoryInterface $productRepository;

public function __construct(
PropertyGroupRepositoryInterface $propertyGroupRepository,
OptionQueryInterface $optionQuery,
AttributeRepositoryInterface $attributeRepository,
OptionRepositoryInterface $optionRepository,
TranslationInheritanceCalculator $calculator,
PropertyGroupOptionsRepositoryInterface $propertyGroupOptionsRepository
PropertyGroupOptionsRepositoryInterface $propertyGroupOptionsRepository,
ProductRepositoryInterface $productRepository
) {
parent::__construct($attributeRepository, $optionRepository, $calculator, $propertyGroupOptionsRepository);

$this->propertyGroupRepository = $propertyGroupRepository;
$this->optionQuery = $optionQuery;
$this->productRepository = $productRepository;
}

public function map(
Expand All @@ -65,22 +65,25 @@ private function variantMapper(
): Shopware6Product {
foreach ($product->getBindings() as $bindingId) {
if ($this->propertyGroupRepository->exists($channel->getId(), $bindingId)) {
$this->mapOptions($channel, $shopware6Product, $bindingId);
$this->mapOptions($channel, $shopware6Product, $bindingId, $product->getChildren());
}
}

return $shopware6Product;
}


private function mapOptions(
Shopware6Channel $channel,
Shopware6Product $shopware6Product,
AttributeId $bindingId
AttributeId $bindingId,
array $childrenId
): Shopware6Product {
$options = $this->optionQuery->getOptions($bindingId);
foreach ($options as $option) {
$optionId = new AggregateId($option);
$shopwareId = $this->optionMap($channel, $bindingId, $optionId);
foreach ($childrenId as $childId) {
$child = $this->productRepository->load($childId);
Assert::isInstanceOf($child, AbstractProduct::class);

$shopwareId = $this->optionMapper($bindingId, $child, $channel);
if ($shopwareId) {
$shopware6Product->addConfiguratorSettings(
new Shopware6ProductConfiguratorSettings(null, $shopwareId),
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ services:
- '@Ergonode\ExporterShopware6\Infrastructure\Mapper\Product\CustomField\ProductCustomFieldSetMultimediaMapper'
- '@Ergonode\ExporterShopware6\Infrastructure\Mapper\Product\CustomField\ProductCustomFieldSetUnitMapper'
- '@Ergonode\ExporterShopware6\Infrastructure\Mapper\Product\ProductVariantMapper'
- '@Ergonode\ExporterShopware6\Infrastructure\Mapper\Product\ProductVariantChildMapper'
- '@Ergonode\ExporterShopware6\Infrastructure\Mapper\Product\ProductCoverMapper'
- '@Ergonode\ExporterShopware6\Infrastructure\Mapper\Product\ProductSEOMetaTitleMapper'
- '@Ergonode\ExporterShopware6\Infrastructure\Mapper\Product\ProductSEOMetaDescriptionMapper'
Expand Down