diff --git a/docs/LAUNCH.md b/docs/LAUNCH.md index c8cfb0d8..4b8e3bac 100644 --- a/docs/LAUNCH.md +++ b/docs/LAUNCH.md @@ -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. diff --git a/src/Command/BatchImportFamiliesCommand.php b/src/Command/BatchImportFamiliesCommand.php deleted file mode 100644 index 67f55e8f..00000000 --- a/src/Command/BatchImportFamiliesCommand.php +++ /dev/null @@ -1,48 +0,0 @@ -getArgument('ids')); - - $this->logger->notice('Processing batch', ['from_id' => $ids[0], 'to_id' => $ids[\count($ids) - 1]]); - $this->logger->debug(self::$defaultName, ['batched_ids' => $ids]); - - $batchPayload = new FamilyPayload($this->clientFactory->createFromApiCredentials()); - $batchPayload->setIds($ids); - - $this->batchFamilyTask->__invoke($batchPayload); - - return 0; - } -} diff --git a/src/Command/ImportFamiliesCommand.php b/src/Command/ImportFamiliesCommand.php deleted file mode 100755 index 77913787..00000000 --- a/src/Command/ImportFamiliesCommand.php +++ /dev/null @@ -1,54 +0,0 @@ -preExecute(); - - $payload = $this->payloadFactory->createFromCommand(FamilyPayload::class, $input, $output); - $this->pipeline->process($payload); - - $this->postExecute(); - } catch (CommandLockedException $commandLockedException) { - $this->logger->warning($commandLockedException->getMessage()); - - return 1; - } - - return 0; - } -} diff --git a/src/Component/Cache/CacheKey.php b/src/Component/Cache/CacheKey.php new file mode 100644 index 00000000..bec3f893 --- /dev/null +++ b/src/Component/Cache/CacheKey.php @@ -0,0 +1,18 @@ +dispatcher)); - - return $pipeline - ->pipe($this->taskProvider->get(SetupTask::class)) - ->pipe($this->taskProvider->get(ProcessFamilyTask::class)) - ->pipe($this->taskProvider->get(TearDownTask::class)) - ; - } -} diff --git a/src/Fixture/FamiliesFixture.php b/src/Fixture/FamiliesFixture.php deleted file mode 100644 index 7f118903..00000000 --- a/src/Fixture/FamiliesFixture.php +++ /dev/null @@ -1,70 +0,0 @@ - - * } $options - */ - public function load(array $options): void - { - $pipeline = $this->familyPipelineFactory->create(); - $payload = $this->payloadFactory->create( - FamilyPayload::class, - ); - - $payload->setBatchSize($options['batch_size']); - $payload->setAllowParallel($options['allow_parallel']); - $payload->setMaxRunningProcessQueueSize($options['max_concurrency']); - - $payload->setCustomFilters($options['custom']); - - $pipeline->process($payload); - } - - public function getName(): string - { - return 'akeneo_families'; - } - - protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void - { - $optionsNode - ->children() - ->integerNode('batch_size')->defaultValue(100)->end() - ->booleanNode('allow_parallel')->defaultTrue()->end() - ->integerNode('max_concurrency')->defaultValue(4)->end() - ->arrayNode('custom') - ->variablePrototype()->end() - ->end() - ->end() - ; - } -} diff --git a/src/Payload/Family/FamilyPayload.php b/src/Payload/Family/FamilyPayload.php deleted file mode 100644 index e1716de3..00000000 --- a/src/Payload/Family/FamilyPayload.php +++ /dev/null @@ -1,39 +0,0 @@ -setTmpTableName(self::TEMP_AKENEO_TABLE_NAME); - $this->setCommandName(self::BATCH_COMMAND_NAME); - } - - public function getResources(): ResourceCursorInterface - { - return $this->resources; - } - - public function setResources(ResourceCursorInterface $resources): void - { - $this->resources = $resources; - } -} diff --git a/src/Task/Family/BatchFamilyTask.php b/src/Processor/ProductGroup/ProductGroupProcessor.php similarity index 53% rename from src/Task/Family/BatchFamilyTask.php rename to src/Processor/ProductGroup/ProductGroupProcessor.php index 160bf3a9..a5f55ca0 100644 --- a/src/Task/Family/BatchFamilyTask.php +++ b/src/Processor/ProductGroup/ProductGroupProcessor.php @@ -2,73 +2,31 @@ 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( @@ -76,15 +34,15 @@ private function createGroupForCodeAndFamily( 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.', @@ -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( @@ -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 diff --git a/src/Retriever/FamilyRetriever.php b/src/Retriever/FamilyRetriever.php index bd82ab2c..61607d55 100644 --- a/src/Retriever/FamilyRetriever.php +++ b/src/Retriever/FamilyRetriever.php @@ -6,77 +6,88 @@ use Akeneo\Pim\ApiClient\AkeneoPimClientInterface; use Psr\Log\LoggerInterface; +use Symfony\Contracts\Cache\CacheInterface; +use Synolia\SyliusAkeneoPlugin\Component\Cache\CacheKey; use Synolia\SyliusAkeneoPlugin\Provider\Configuration\Api\ApiConnectionProviderInterface; final class FamilyRetriever implements FamilyRetrieverInterface { - /** @var array */ - private array $familiesByVariant = []; - private array $families = []; + private array $familiesByCode = []; + + private array $familiesByVariantCode = []; + public function __construct( private AkeneoPimClientInterface $akeneoPimClient, private LoggerInterface $logger, private ApiConnectionProviderInterface $apiConnectionProvider, + private CacheInterface $akeneoFamilies, + private CacheInterface $akeneoFamily, + private FamilyVariantRetriever $familyVariantRetriever, ) { } - public function getFamily(string $familyCode): array + public function getFamilies(): array { - if (\array_key_exists($familyCode, $this->families)) { - return $this->families[$familyCode]; + if ($this->families !== []) { + return $this->families; } - $paginationSize = $this->apiConnectionProvider->get()->getPaginationSize(); + /** @phpstan-ignore-next-line */ + return $this->families = $this->akeneoFamilies->get(CacheKey::FAMILIES, function (): array { + $families = []; - $families = $this->akeneoPimClient->getFamilyApi()->all($paginationSize); + $paginationSize = $this->apiConnectionProvider->get()->getPaginationSize(); - /** @var array{code: string} $family */ - foreach ($families as $family) { - $this->families[$family['code']] = $family; - } + $results = $this->akeneoPimClient->getFamilyApi()->all($paginationSize); - return $this->families[$familyCode]; + /** @var array{code: string} $result */ + foreach ($results as $result) { + $families[$result['code']] = $result; + } + + return $families; + }); } - public function getFamilyCodeByVariantCode(string $familyVariantCode): string + public function getFamily(string $familyCode): array { - if (\array_key_exists($familyVariantCode, $this->familiesByVariant)) { - return $this->familiesByVariant[$familyVariantCode]; + if (array_key_exists($familyCode, $this->familiesByCode)) { + return $this->familiesByCode[$familyCode]; } - $paginationSize = $this->apiConnectionProvider->get()->getPaginationSize(); - - try { - $families = $this->akeneoPimClient->getFamilyApi()->all($paginationSize); - - /** @var array{code: string} $family */ - foreach ($families as $family) { - if (!\array_key_exists($family['code'], $this->families)) { - $this->families[$family['code']] = $family; - } - - $familyVariants = $this->akeneoPimClient->getFamilyVariantApi()->all($family['code'], $paginationSize); - if (!$familyVariants->valid()) { - continue; - } + /** @phpstan-ignore-next-line */ + return $this->familiesByCode[$familyCode] = $this->akeneoFamily->get(\sprintf(CacheKey::FAMILY, $familyCode), function () use ($familyCode): array { + return $this->getFamilies()[$familyCode]; + }); + } - /** @var array{code: string} $familyVariant */ - foreach ($familyVariants as $familyVariant) { - $this->familiesByVariant[$familyVariant['code']] = $family['code']; - } + public function getFamilyCodeByVariantCode(string $familyVariantCode): string + { + if (array_key_exists($familyVariantCode, $this->familiesByVariantCode)) { + return $this->familiesByVariantCode[$familyVariantCode]; + } - if (isset($this->familiesByVariant[$familyVariantCode])) { - return $family['code']; + /** @phpstan-ignore-next-line */ + return $this->familiesByVariantCode[$familyVariantCode] = $this->akeneoFamily->get(\sprintf(CacheKey::FAMILY_BY_VARIANT_CODE, $familyVariantCode), function () use ($familyVariantCode): string { + try { + /** @var array{code: string} $family */ + foreach ($this->getFamilies() as $family) { + /** @var array{code: string} $familyVariant */ + foreach ($this->familyVariantRetriever->getVariants($family['code']) as $familyVariant) { + if ($familyVariant['code'] === $familyVariantCode) { + return $family['code']; + } + } } + } catch (\Throwable $exception) { + $this->logger->warning($exception->getMessage(), [ + 'exception' => $exception, + ]); } - } catch (\Throwable $exception) { - $this->logger->warning($exception->getMessage(), [ - 'exception' => $exception, - ]); - } - throw new \LogicException(sprintf('Unable to find family for variant "%s"', $familyVariantCode)); + throw new \LogicException(sprintf('Unable to find family for variant "%s"', $familyVariantCode)); + }); } } diff --git a/src/Retriever/FamilyRetrieverInterface.php b/src/Retriever/FamilyRetrieverInterface.php index 61649b88..44fe15a8 100644 --- a/src/Retriever/FamilyRetrieverInterface.php +++ b/src/Retriever/FamilyRetrieverInterface.php @@ -6,6 +6,8 @@ interface FamilyRetrieverInterface { + public function getFamilies(): array; + public function getFamilyCodeByVariantCode(string $familyVariantCode): string; public function getFamily(string $familyCode): array; diff --git a/src/Retriever/FamilyVariantRetriever.php b/src/Retriever/FamilyVariantRetriever.php index 176d91ff..867e54d5 100644 --- a/src/Retriever/FamilyVariantRetriever.php +++ b/src/Retriever/FamilyVariantRetriever.php @@ -6,39 +6,42 @@ use Akeneo\Pim\ApiClient\AkeneoPimClientInterface; use Psr\Log\LoggerInterface; +use Symfony\Contracts\Cache\CacheInterface; +use Synolia\SyliusAkeneoPlugin\Component\Cache\CacheKey; use Synolia\SyliusAkeneoPlugin\Provider\Configuration\Api\ApiConnectionProviderInterface; -final class FamilyVariantRetriever +final class FamilyVariantRetriever implements FamilyVariantRetrieverInterface { - private array $familyVariants = []; + private array $variantsByFamily = []; public function __construct( private AkeneoPimClientInterface $akeneoPimClient, private LoggerInterface $logger, private ApiConnectionProviderInterface $apiConnectionProvider, + private CacheInterface $akeneoFamilyVariants, ) { } public function getVariants(string $familyCode): array { - if (\array_key_exists($familyCode, $this->familyVariants)) { - return $this->familyVariants[$familyCode]; + if ($this->variantsByFamily !== []) { + return $this->variantsByFamily[$familyCode] ?? []; } - $paginationSize = $this->apiConnectionProvider->get()->getPaginationSize(); + /** @phpstan-ignore-next-line */ + return $this->variantsByFamily[$familyCode] = $this->akeneoFamilyVariants->get(\sprintf(CacheKey::FAMILY_VARIANTS, $familyCode), function () use ($familyCode): array { + $paginationSize = $this->apiConnectionProvider->get()->getPaginationSize(); - try { - $familyVariants = $this->akeneoPimClient->getFamilyVariantApi()->all($familyCode, $paginationSize); + try { + $results = $this->akeneoPimClient->getFamilyVariantApi()->all($familyCode, $paginationSize); + $familyVariants = iterator_to_array($results); + } catch (\Throwable $exception) { + $this->logger->warning($exception->getMessage()); - $this->familyVariants[$familyCode] = iterator_to_array($familyVariants); - - if (isset($this->familyVariants[$familyCode])) { - return $this->familyVariants[$familyCode]; + return []; } - } catch (\Throwable $exception) { - $this->logger->warning($exception->getMessage()); - } - throw new \LogicException(sprintf('Unable to find variants for family "%s"', $familyCode)); + return $familyVariants; + }); } } diff --git a/src/Retriever/FamilyVariantRetrieverInterface.php b/src/Retriever/FamilyVariantRetrieverInterface.php new file mode 100644 index 00000000..ee416db2 --- /dev/null +++ b/src/Retriever/FamilyVariantRetrieverInterface.php @@ -0,0 +1,10 @@ +getAkeneoPimClient(); - $pagination = $this->apiConnectionProvider->get()->getPaginationSize(); - - $families = $client->getFamilyApi()->all($pagination); + $families = $this->familyRetriever->getFamilies(); foreach ($families as $family) { - $familyVariants = $client->getFamilyVariantApi()->all( - $family['code'], - $pagination, - ); + $familyVariants = $this->familyVariantRetriever->getVariants($family['code']); $variationAxes = array_merge($variationAxes, $this->getVariationAxesForFamilies($familyVariants)); } @@ -148,7 +143,7 @@ private function getVariationAxes(PipelinePayloadInterface $payload): array return $variationAxes; } - private function getVariationAxesForFamilies(ResourceCursorInterface $familyVariants): array + private function getVariationAxesForFamilies(array $familyVariants): array { $variationAxes = []; diff --git a/src/Task/Family/ProcessFamilyTask.php b/src/Task/Family/ProcessFamilyTask.php deleted file mode 100644 index 64ec3f27..00000000 --- a/src/Task/Family/ProcessFamilyTask.php +++ /dev/null @@ -1,77 +0,0 @@ -logger->debug(self::class); - - if ($payload->isContinue()) { - $this->process($payload); - - return $payload; - } - - $this->logger->notice(Messages::retrieveFromAPI($payload->getType())); - - try { - $event = new FilterEvent($payload->getCommandContext()); - $this->eventDispatcher->dispatch($event); - - $queryParameters['search'] = $event->getFilters(); - } catch (CommandContextIsNullException) { - $queryParameters = []; - } - - $queryParameters = \array_merge_recursive($queryParameters, $payload->getCustomFilters()); - - $resources = $payload->getAkeneoPimClient()->getProductModelApi()->all( - $this->apiConnectionProvider->get()->getPaginationSize(), - $queryParameters, - ); - - $this->handle($payload, $resources); - $this->processManager->waitForAllProcesses(); - - return $payload; - } - - protected function createBatchPayload(PipelinePayloadInterface $payload): PipelinePayloadInterface - { - $commandContext = ($payload->hasCommandContext()) ? $payload->getCommandContext() : null; - - return new FamilyPayload($payload->getAkeneoPimClient(), $commandContext); - } -} diff --git a/src/Task/ProductGroup/ProcessProductGroupModelTask.php b/src/Task/ProductGroup/ProcessProductGroupModelTask.php index 8aeb70f9..acf9e38a 100644 --- a/src/Task/ProductGroup/ProcessProductGroupModelTask.php +++ b/src/Task/ProductGroup/ProcessProductGroupModelTask.php @@ -10,6 +10,7 @@ use Sylius\Component\Core\Repository\ProductRepositoryInterface; use Synolia\SyliusAkeneoPlugin\Entity\ProductGroupInterface; use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface; +use Synolia\SyliusAkeneoPlugin\Processor\ProductGroup\ProductGroupProcessor; use Synolia\SyliusAkeneoPlugin\Provider\Configuration\Api\ApiConnectionProviderInterface; use Synolia\SyliusAkeneoPlugin\Repository\ProductGroupRepository; use Synolia\SyliusAkeneoPlugin\Task\AkeneoTaskInterface; @@ -24,6 +25,7 @@ public function __construct( private ProductRepositoryInterface $productRepository, private LoggerInterface $logger, private EntityManagerInterface $entityManager, + private ProductGroupProcessor $productGroupProcessor, ) { $this->productGroups = []; } @@ -41,6 +43,8 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte * } $resource */ foreach ($resourceCursor as $resource) { + $this->productGroupProcessor->process($resource); + if (null === $resource['parent']) { continue; } diff --git a/src/Task/ProductModel/BatchProductModelTask.php b/src/Task/ProductModel/BatchProductModelTask.php index 4c58742a..49f8ca32 100644 --- a/src/Task/ProductModel/BatchProductModelTask.php +++ b/src/Task/ProductModel/BatchProductModelTask.php @@ -4,8 +4,11 @@ namespace Synolia\SyliusAkeneoPlugin\Task\ProductModel; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Result; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\ORMInvalidArgumentException; +use Doctrine\Persistence\ManagerRegistry; use Psr\Log\LoggerInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Repository\ProductRepositoryInterface; @@ -18,6 +21,7 @@ use Synolia\SyliusAkeneoPlugin\Payload\PipelinePayloadInterface; use Synolia\SyliusAkeneoPlugin\Payload\ProductModel\ProductModelPayload; use Synolia\SyliusAkeneoPlugin\Processor\Product\ProductProcessorChainInterface; +use Synolia\SyliusAkeneoPlugin\Processor\ProductGroup\ProductGroupProcessor; use Synolia\SyliusAkeneoPlugin\Task\AbstractBatchTask; final class BatchProductModelTask extends AbstractBatchTask @@ -35,12 +39,16 @@ public function __construct( private EventDispatcherInterface $dispatcher, private ProductProcessorChainInterface $productProcessorChain, private IsProductProcessableCheckerInterface $isProductProcessableChecker, + private ProductGroupProcessor $productGroupProcessor, + private ManagerRegistry $managerRegistry, ) { parent::__construct($entityManager); } /** * @param ProductModelPayload $payload + * + * @throws Exception */ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInterface { @@ -54,7 +62,10 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte while ($results = $queryResult->fetchAll()) { foreach ($results as $result) { - $resource = json_decode($result['values'], true, 512, \JSON_THROW_ON_ERROR); + /** @var array $resource */ + $resource = json_decode($result['values'], true); + + $this->handleProductGroup($resource); try { $this->dispatcher->dispatch(new BeforeProcessingProductEvent($resource)); @@ -68,7 +79,6 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte $this->entityManager->flush(); $this->entityManager->commit(); - $this->entityManager->clear(); unset($resource, $product); $this->removeEntry($payload, (int) $result['id']); @@ -83,6 +93,26 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte return $payload; } + private function handleProductGroup(array $resource): void + { + try { + $this->entityManager->beginTransaction(); + + $this->productGroupProcessor->process($resource); + + $this->entityManager->flush(); + $this->entityManager->commit(); + } catch (ORMInvalidArgumentException) { + if ($this->entityManager->getConnection()->isTransactionActive()) { + $this->entityManager->rollback(); + } + + if (!$this->entityManager->isOpen()) { + $this->entityManager = $this->getNewEntityManager(); + } + } + } + private function process(array &$resource): ProductInterface { $product = $this->productRepository->findOneByCode($resource['code']); @@ -105,4 +135,15 @@ private function process(array &$resource): ProductInterface return $product; } + + private function getNewEntityManager(): EntityManagerInterface + { + $objectManager = $this->managerRegistry->resetManager(); + + if (!$objectManager instanceof EntityManagerInterface) { + throw new \LogicException('Wrong ObjectManager'); + } + + return $objectManager; + } } diff --git a/tests/PHPUnit/Task/Association/AssociateProductsTaskTest.php b/tests/PHPUnit/Task/Association/AssociateProductsTaskTest.php index fad3fd49..0776961d 100644 --- a/tests/PHPUnit/Task/Association/AssociateProductsTaskTest.php +++ b/tests/PHPUnit/Task/Association/AssociateProductsTaskTest.php @@ -18,13 +18,11 @@ use Synolia\SyliusAkeneoPlugin\Entity\ProductGroup; use Synolia\SyliusAkeneoPlugin\Factory\AssociationTypePipelineFactory; use Synolia\SyliusAkeneoPlugin\Factory\CategoryPipelineFactory; -use Synolia\SyliusAkeneoPlugin\Factory\FamilyPipelineFactory; use Synolia\SyliusAkeneoPlugin\Factory\ProductModelPipelineFactory; use Synolia\SyliusAkeneoPlugin\Filter\ProductFilter; use Synolia\SyliusAkeneoPlugin\Payload\Association\AssociationPayload; use Synolia\SyliusAkeneoPlugin\Payload\Association\AssociationTypePayload; use Synolia\SyliusAkeneoPlugin\Payload\Category\CategoryPayload; -use Synolia\SyliusAkeneoPlugin\Payload\Family\FamilyPayload; use Synolia\SyliusAkeneoPlugin\Payload\ProductModel\ProductModelPayload; use Synolia\SyliusAkeneoPlugin\Provider\AkeneoAttributePropertiesProvider; use Synolia\SyliusAkeneoPlugin\Provider\TaskProvider; @@ -71,7 +69,6 @@ public function testCreateUpdateTask(): void $this->importCategories(); $this->importAttributes(); $this->importAssociationTypes(); - $this->importFamilies(); $this->importProductModels(); $productModelPayload = new ProductModelPayload($this->createClient()); @@ -150,16 +147,6 @@ private function importAssociationTypes(): void $associationTypePipeline->process($associationTypePayload); } - private function importFamilies(): void - { - /** @var Pipeline $familyPipeline */ - $familyPipeline = $this->getContainer()->get(FamilyPipelineFactory::class)->create(); - - $familyPayload = new FamilyPayload($this->client); - $familyPayload->setProcessAsSoonAsPossible(false); - $familyPipeline->process($familyPayload); - } - private function createProductFiltersConfiguration(): void { $this->productFilter = $this->getContainer()->get(ProductFilter::class); diff --git a/tests/PHPUnit/Task/Product/CreateConfigurableProductEntitiesTaskTest.php b/tests/PHPUnit/Task/Product/CreateConfigurableProductEntitiesTaskTest.php index 4776e1ae..656551c0 100644 --- a/tests/PHPUnit/Task/Product/CreateConfigurableProductEntitiesTaskTest.php +++ b/tests/PHPUnit/Task/Product/CreateConfigurableProductEntitiesTaskTest.php @@ -10,15 +10,12 @@ use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApi; use Akeneo\Pim\ApiClient\Search\Operator; use donatj\MockWebServer\Response; -use League\Pipeline\Pipeline; use Symfony\Component\HttpFoundation\Response as HttpResponse; use Synolia\SyliusAkeneoPlugin\Entity\ProductFiltersRules; use Synolia\SyliusAkeneoPlugin\Factory\CategoryPipelineFactory; -use Synolia\SyliusAkeneoPlugin\Factory\FamilyPipelineFactory; use Synolia\SyliusAkeneoPlugin\Factory\ProductModelPipelineFactory; use Synolia\SyliusAkeneoPlugin\Filter\ProductFilter; use Synolia\SyliusAkeneoPlugin\Payload\Category\CategoryPayload; -use Synolia\SyliusAkeneoPlugin\Payload\Family\FamilyPayload; use Synolia\SyliusAkeneoPlugin\Payload\Product\ProductPayload; use Synolia\SyliusAkeneoPlugin\Payload\ProductModel\ProductModelPayload; use Synolia\SyliusAkeneoPlugin\Provider\AkeneoAttributePropertiesProvider; @@ -60,7 +57,6 @@ public function testCreateConfigurableProductsTask(): void $this->importCategories(); $this->importAttributes(); $this->importReferenceEntities(); - $this->importFamilies(); $this->importProductModels(); $this->manager->flush(); @@ -178,16 +174,6 @@ private function importProductModels(): void $productModelPipeline->process($productModelPayload); } - private function importFamilies(): void - { - /** @var Pipeline $familyPipeline */ - $familyPipeline = $this->getContainer()->get(FamilyPipelineFactory::class)->create(); - - $familyPayload = new FamilyPayload($this->client); - $familyPayload->setProcessAsSoonAsPossible(false); - $familyPipeline->process($familyPayload); - } - private function createProductFiltersConfiguration(): void { $this->productFilter = $this->getContainer()->get(ProductFilter::class); diff --git a/tests/PHPUnit/Task/ProductGroup/ProcessProductGroupModelTaskTest.php b/tests/PHPUnit/Task/ProductGroup/ProcessProductGroupModelTaskTest.php index 447bda76..26afeb6b 100644 --- a/tests/PHPUnit/Task/ProductGroup/ProcessProductGroupModelTaskTest.php +++ b/tests/PHPUnit/Task/ProductGroup/ProcessProductGroupModelTaskTest.php @@ -4,10 +4,13 @@ namespace Tests\Synolia\SyliusAkeneoPlugin\PHPUnit\Task\ProductGroup; +use Akeneo\Pim\ApiClient\Api\FamilyVariantApi; +use donatj\MockWebServer\Response; use PHPUnit\Framework\Assert; use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; use Sylius\Component\Core\Model\Product; use Sylius\Component\Core\Repository\ProductRepositoryInterface; +use Symfony\Component\HttpFoundation\Response as HttpResponse; use Synolia\SyliusAkeneoPlugin\Entity\ProductConfiguration; use Synolia\SyliusAkeneoPlugin\Entity\ProductGroup; use Synolia\SyliusAkeneoPlugin\Payload\ProductModel\ProductModelPayload; @@ -41,6 +44,11 @@ protected function setUp(): void $this->productGroupRepository = $this->getContainer()->get('akeneo.repository.product_group'); $this->processProductGroupModelTask = $this->getContainer()->get(ProcessProductGroupModelTask::class); self::assertInstanceOf(TaskProvider::class, $this->taskProvider); + + $this->server->setResponseOfPath( + '/' . sprintf(FamilyVariantApi::FAMILY_VARIANT_URI, 'clothing', 'clothing_color_size'), + new Response($this->getFileContent('family_variant_clothing_color_size.json'), [], HttpResponse::HTTP_OK), + ); } public function testCreateProductGroupAssociations(): void diff --git a/tests/PHPUnit/Task/ProductModel/AddOrUpdateProductModelTaskTest.php b/tests/PHPUnit/Task/ProductModel/AddOrUpdateProductModelTaskTest.php index 9e5b6dbc..2740adf5 100644 --- a/tests/PHPUnit/Task/ProductModel/AddOrUpdateProductModelTaskTest.php +++ b/tests/PHPUnit/Task/ProductModel/AddOrUpdateProductModelTaskTest.php @@ -4,9 +4,12 @@ namespace Tests\Synolia\SyliusAkeneoPlugin\PHPUnit\Task\ProductModel; +use Akeneo\Pim\ApiClient\Api\FamilyVariantApi; +use donatj\MockWebServer\Response; use PHPUnit\Framework\Assert; use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository; use Sylius\Component\Core\Model\Product; +use Symfony\Component\HttpFoundation\Response as HttpResponse; use Synolia\SyliusAkeneoPlugin\Entity\ProductConfiguration; use Synolia\SyliusAkeneoPlugin\Entity\ProductConfigurationAkeneoImageAttribute; use Synolia\SyliusAkeneoPlugin\Entity\ProductConfigurationImageMapping; @@ -43,6 +46,11 @@ protected function setUp(): void $this->productRepository = $this->getContainer()->get('sylius.repository.product'); $this->productGroupRepository = $this->getContainer()->get('akeneo.repository.product_group'); self::assertInstanceOf(TaskProvider::class, $this->taskProvider); + + $this->server->setResponseOfPath( + '/' . sprintf(FamilyVariantApi::FAMILY_VARIANT_URI, 'clothing', 'clothing_color_size'), + new Response($this->getFileContent('family_variant_clothing_color_size.json'), [], HttpResponse::HTTP_OK), + ); } public function testCreateUpdateTask(): void diff --git a/tests/PHPUnit/Task/ProductModel/EnableDisableProductModelTaskTest.php b/tests/PHPUnit/Task/ProductModel/EnableDisableProductModelTaskTest.php index de9b30bc..2e267f73 100644 --- a/tests/PHPUnit/Task/ProductModel/EnableDisableProductModelTaskTest.php +++ b/tests/PHPUnit/Task/ProductModel/EnableDisableProductModelTaskTest.php @@ -4,7 +4,10 @@ namespace Tests\Synolia\SyliusAkeneoPlugin\PHPUnit\Task\ProductModel; +use Akeneo\Pim\ApiClient\Api\FamilyVariantApi; +use donatj\MockWebServer\Response; use Sylius\Component\Core\Model\Product; +use Symfony\Component\HttpFoundation\Response as HttpResponse; use Synolia\SyliusAkeneoPlugin\Payload\ProductModel\ProductModelPayload; use Synolia\SyliusAkeneoPlugin\Provider\AkeneoAttributePropertiesProvider; use Synolia\SyliusAkeneoPlugin\Provider\TaskProvider; @@ -31,6 +34,11 @@ protected function setUp(): void $akeneoPropertiesProvider->setLoadsAllAttributesAtOnce(true); $this->taskProvider = $this->getContainer()->get(TaskProvider::class); self::assertInstanceOf(TaskProvider::class, $this->taskProvider); + + $this->server->setResponseOfPath( + '/' . sprintf(FamilyVariantApi::FAMILY_VARIANT_URI, 'clothing', 'clothing_color_size'), + new Response($this->getFileContent('family_variant_clothing_color_size.json'), [], HttpResponse::HTTP_OK), + ); } public function testEnableDisableProductModelTask(): void diff --git a/tests/PHPUnit/datas/sample/family_variant_clothing_color_size.json b/tests/PHPUnit/datas/sample/family_variant_clothing_color_size.json index d428a9cc..bdd745af 100644 --- a/tests/PHPUnit/datas/sample/family_variant_clothing_color_size.json +++ b/tests/PHPUnit/datas/sample/family_variant_clothing_color_size.json @@ -32,4 +32,4 @@ ] } ] -} \ No newline at end of file +}