Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product Group processing deported to product models import #172

Merged
merged 1 commit into from
Nov 10, 2023
Merged
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
1 change: 0 additions & 1 deletion docs/LAUNCH.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ and add one of

akeneo:import:categories Import Categories from Akeneo PIM.
akeneo:import:attributes Import Attributes and Options from Akeneo PIM.
akeneo:import:families Import product's families from Akeneo PIM.
akeneo:import:association-type Import Associations type from Akeneo PIM.
akeneo:import:product-models Import Product Models from Akeneo PIM.
akeneo:import:products Import Products from Akeneo PIM.
Expand Down
48 changes: 0 additions & 48 deletions src/Command/BatchImportFamiliesCommand.php

This file was deleted.

54 changes: 0 additions & 54 deletions src/Command/ImportFamiliesCommand.php

This file was deleted.

18 changes: 18 additions & 0 deletions src/Component/Cache/CacheKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Synolia\SyliusAkeneoPlugin\Component\Cache;

class CacheKey
{
public const FAMILIES = 'akeneo_families';

public const FAMILY = 'akeneo_family_%s';

public const FAMILY_BY_VARIANT_CODE = 'akeneo_family_by_variant_code_%s';

public const FAMILY_VARIANTS = 'akeneo_family_variants_%s';

public const ATTRIBUTES = 'akeneo_attributes';
}
26 changes: 0 additions & 26 deletions src/Factory/FamilyPipelineFactory.php

This file was deleted.

70 changes: 0 additions & 70 deletions src/Fixture/FamiliesFixture.php

This file was deleted.

39 changes: 0 additions & 39 deletions src/Payload/Family/FamilyPayload.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,47 @@

declare(strict_types=1);

namespace Synolia\SyliusAkeneoPlugin\Task\Family;
namespace Synolia\SyliusAkeneoPlugin\Processor\ProductGroup;

use Doctrine\DBAL\Result;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Synolia\SyliusAkeneoPlugin\Entity\ProductGroup;
use Synolia\SyliusAkeneoPlugin\Entity\ProductGroupInterface;
use Synolia\SyliusAkeneoPlugin\Payload\Family\FamilyPayload;
use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface;
use Synolia\SyliusAkeneoPlugin\Processor\ProductGroup\FamilyVariationAxeProcessor;
use Synolia\SyliusAkeneoPlugin\Task\AbstractBatchTask;

final class BatchFamilyTask extends AbstractBatchTask
class ProductGroupProcessor
{
private int $groupAlreadyExistCount = 0;

private int $groupCreateCount = 0;

private array $productGroupsMapping;

public function __construct(
EntityManagerInterface $entityManager,
private EntityRepository $productGroupRepository,
private EntityManagerInterface $entityManager,
private LoggerInterface $logger,
private FamilyVariationAxeProcessor $familyVariationAxeProcessor,
private EntityRepository $productGroupRepository,
private FactoryInterface $productGroupFactory,
) {
parent::__construct($entityManager);
}

/**
* @param FamilyPayload $payload
*/
public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInterface
public function process(array $resource): void
{
$this->logger->debug(self::class);
$this->productGroupsMapping = [];
$resources = [];

$query = $this->getSelectStatement($payload);
/** @var Result $queryResult */
$queryResult = $query->executeQuery();

while ($results = $queryResult->fetchAll()) {
foreach ($results as $result) {
try {
$resource = json_decode($result['values'], true, 512, \JSON_THROW_ON_ERROR);
$resources[] = $resource;

$this->createProductGroups($resource);
$this->removeEntry($payload, (int) $result['id']);
} catch (\Throwable $throwable) {
$this->logger->warning($throwable->getMessage());
$this->removeEntry($payload, (int) $result['id']);
}
}
}
$this->entityManager->flush();

foreach ($resources as $resource) {
$this->familyVariationAxeProcessor->process($resource);
}
$this->entityManager->flush();

return $payload;
$this->createProductGroups($resource);
$this->familyVariationAxeProcessor->process($resource);
}

private function createGroupForCodeAndFamily(
string $code,
string $family,
string $familyVariant,
?string $parent = null,
): ProductGroupInterface {
): void {
if (isset($this->productGroupsMapping[$code])) {
return $this->productGroupsMapping[$code];
return;
}

$productGroup = $this->productGroupRepository->findOneBy(['model' => $code]);
if ($productGroup instanceof ProductGroup) {

if ($productGroup instanceof ProductGroupInterface) {
$this->productGroupsMapping[$code] = $productGroup;
++$this->groupAlreadyExistCount;

$this->logger->info(sprintf(
'Skipping ProductGroup "%s" for family "%s" as it already exists.',
Expand All @@ -96,8 +54,9 @@ private function createGroupForCodeAndFamily(
$productGroup->setModel($code);
$productGroup->setFamily($family);
$productGroup->setFamilyVariant($familyVariant);
$this->entityManager->persist($productGroup);

return $productGroup;
return;
}

$this->logger->info(sprintf(
Expand All @@ -114,10 +73,6 @@ private function createGroupForCodeAndFamily(
$productGroup->setFamilyVariant($familyVariant);
$this->entityManager->persist($productGroup);
$this->productGroupsMapping[$code] = $productGroup;

++$this->groupCreateCount;

return $productGroup;
}

private function createProductGroups(array $resource): void
Expand Down
Loading