From 2ba753e044e2d86ced69bcf2a793b5dff8b21694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jib=C3=A9=20Barth?= Date: Thu, 19 Oct 2023 08:51:24 +0200 Subject: [PATCH 01/10] Feat: Allow to set custom filters on any payload --- src/Payload/AbstractPayload.php | 12 ++++++++++++ src/Payload/FilterAwareInterface.php | 12 ++++++++++++ src/Payload/PayloadInterface.php | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/Payload/FilterAwareInterface.php diff --git a/src/Payload/AbstractPayload.php b/src/Payload/AbstractPayload.php index 0511ffc7..185668a3 100644 --- a/src/Payload/AbstractPayload.php +++ b/src/Payload/AbstractPayload.php @@ -24,6 +24,8 @@ abstract class AbstractPayload implements PipelinePayloadInterface protected string $commandName; + protected array $customFilters = []; + public function __construct( protected AkeneoPimClientInterface $akeneoPimClient, protected ?\Synolia\SyliusAkeneoPlugin\Command\Context\CommandContextInterface $commandContext = null, @@ -116,4 +118,14 @@ public function setCommandName(string $command): BatchPayloadInterface return $this; } + + public function getCustomFilters(): array + { + return $this->customFilters; + } + + public function setCustomFilters(array $customFilters = []): void + { + $this->customFilters = $customFilters; + } } diff --git a/src/Payload/FilterAwareInterface.php b/src/Payload/FilterAwareInterface.php new file mode 100644 index 00000000..daa30ce6 --- /dev/null +++ b/src/Payload/FilterAwareInterface.php @@ -0,0 +1,12 @@ + Date: Thu, 19 Oct 2023 09:10:29 +0200 Subject: [PATCH 02/10] Feat: Add a new akeneo_categories fixture that allow to launch category import --- src/Fixture/CategoriesFixture.php | 59 ++++++++++++++++++++ src/Task/Category/RetrieveCategoriesTask.php | 2 + 2 files changed, 61 insertions(+) create mode 100644 src/Fixture/CategoriesFixture.php diff --git a/src/Fixture/CategoriesFixture.php b/src/Fixture/CategoriesFixture.php new file mode 100644 index 00000000..24657068 --- /dev/null +++ b/src/Fixture/CategoriesFixture.php @@ -0,0 +1,59 @@ +} $options + */ + public function load(array $options): void + { + $pipeline = $this->categoryPipelineFactory->create(); + $payload = $this->payloadFactory->create( + CategoryPayload::class, + ); + $payload->setCustomFilters($options['custom']); + + $pipeline->process($payload); + } + + public function getName(): string + { + return 'akeneo_categories'; + } + + protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void + { + $optionsNode + ->children() + ->arrayNode('custom') + ->variablePrototype()->end() + ->end() + ->end() + ; + } +} diff --git a/src/Task/Category/RetrieveCategoriesTask.php b/src/Task/Category/RetrieveCategoriesTask.php index 590d4d05..52746805 100644 --- a/src/Task/Category/RetrieveCategoriesTask.php +++ b/src/Task/Category/RetrieveCategoriesTask.php @@ -47,6 +47,8 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte } $queryParameters['with_enriched_attributes'] = true; + $queryParameters = \array_merge_recursive($queryParameters, $payload->getCustomFilters()); + $resources = $payload->getAkeneoPimClient()->getCategoryApi()->all( $this->apiConnectionProvider->get()->getPaginationSize(), $queryParameters, From d53f91d062228b803bea39dfa1c43e3d3f4ac246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jib=C3=A9=20Barth?= Date: Thu, 19 Oct 2023 09:12:05 +0200 Subject: [PATCH 03/10] Autoconfigure fixtures --- src/Resources/config/services.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 68c14490..4303cae5 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -8,7 +8,7 @@ services: Synolia\SyliusAkeneoPlugin\: resource: '../../*' - exclude: '../../{Controller,DependencyInjection,Fixture,Model,Migrations,Payload,Twig,SynoliaSyliusAkeneoPlugin.php}' + exclude: '../../{Controller,DependencyInjection,Model,Migrations,Payload,Twig,SynoliaSyliusAkeneoPlugin.php}' Synolia\SyliusAkeneoPlugin\Controller\: resource: '../../Controller' From 366948ad28c3de7fecc44a30d86fcb704f4009ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jib=C3=A9=20Barth?= Date: Thu, 19 Oct 2023 09:26:40 +0200 Subject: [PATCH 04/10] Initialize Fixture documentation --- README.md | 2 ++ docs/FIXTURE.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 docs/FIXTURE.md diff --git a/README.md b/README.md index 5ac079ff..b93255a1 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,8 @@ * See [How to contribute](CONTRIBUTING.md) * See [How to customize your import using processors](docs/customize/PROCESSORS.md) +* See [How to use fixtures](docs/FIXTURE.md) + ## Akeneo Enterprise Edition diff --git a/docs/FIXTURE.md b/docs/FIXTURE.md new file mode 100644 index 00000000..b0f87860 --- /dev/null +++ b/docs/FIXTURE.md @@ -0,0 +1,71 @@ +# Developers - Using fixtures + +This plugin provides multiples fixtures to help you start your shop from scratch. + +## Category Configurations - `akeneo_category_configuration` + +This fixture allow to define the root category you want to import from Akeneo, and also if you want to exclude somes. + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_category_configuration: + options: + root_categories_to_import: + - 'root_category' + - 'another_root_category' + categories_to_exclude: + - 'excluded_category' + - 'another_excluded_category' +``` +## Categories - `akeneo_categories` + +This fixture allow you to trigger the `akeneo:import:categories` command. + +> [!IMPORTANT] +> Remember that the `akeneo_category_configuration` fixture must be configured and loaded before this one. + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_category_configuration: + # ... + akeneo_categories: ~ +``` + +You can also provide a custom filter to reduce the number of categories you want to import. + +> [!IMPORTANT] +> If you want to get only some children categories, make sure that all parents are also included in your search. + +Inside `custom` node option, you can provide any query parameter supported by [Akneneo API](https://api.akeneo.com/documentation/filter.html#filter-categories). + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_category_configuration: + # ... + akeneo_categories: + options: + custom: + search: + code: + - + operator: 'IN' + value: + - 'root_category' + - 'child_category' + - 'another_child_category' +``` From b0dc7dffcf1cda364b94364bc58a5f8277598a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jib=C3=A9=20Barth?= Date: Thu, 19 Oct 2023 09:47:05 +0200 Subject: [PATCH 05/10] Feat: Add a new akeneo_attributes fixture that allow to launch attribute import --- docs/FIXTURE.md | 42 +++++++++++++ src/Fixture/AttributesFixture.php | 66 +++++++++++++++++++++ src/Task/Attribute/ProcessAttributeTask.php | 2 + 3 files changed, 110 insertions(+) create mode 100644 src/Fixture/AttributesFixture.php diff --git a/docs/FIXTURE.md b/docs/FIXTURE.md index b0f87860..1e0c37f3 100644 --- a/docs/FIXTURE.md +++ b/docs/FIXTURE.md @@ -69,3 +69,45 @@ sylius_fixtures: - 'child_category' - 'another_child_category' ``` + +## Attributes - `akeneo_attributes` + +This fixture allow you to trigger the `akeneo:import:attributes` command. + +You can specify the batch size, if you allow parallel import, and max concurrency. + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_attributes: + options: + batch_size: 100 + allow_parallel: true + max_concurrency: 4 +``` + +If you have too many attributes, you can also provide a custom filter to reduce the number of attributes you want to import. + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_attributes: + options: + custom: + search: + code: + - + operator: 'IN' + value: + - 'attribute_code' + - 'another_attribute_code' +``` +Inside `custom` node option, you can provide any query parameter supported by [Akneneo API](https://api.akeneo.com/documentation/filter.html#filter-attributes). diff --git a/src/Fixture/AttributesFixture.php b/src/Fixture/AttributesFixture.php new file mode 100644 index 00000000..7421cbd9 --- /dev/null +++ b/src/Fixture/AttributesFixture.php @@ -0,0 +1,66 @@ + + * } $options + */ + public function load(array $options): void + { + $pipeline = $this->attributePipelineFactory->create(); + $payload = $this->payloadFactory->create( + AttributePayload::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_attributes'; + } + + 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/Task/Attribute/ProcessAttributeTask.php b/src/Task/Attribute/ProcessAttributeTask.php index fac5a719..31fdbfbe 100644 --- a/src/Task/Attribute/ProcessAttributeTask.php +++ b/src/Task/Attribute/ProcessAttributeTask.php @@ -53,6 +53,8 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte $queryParameters = []; } + $queryParameters = \array_merge_recursive($queryParameters, $payload->getCustomFilters()); + $page = $payload->getAkeneoPimClient()->getAttributeApi()->listPerPage( $this->apiConnectionProvider->get()->getPaginationSize(), true, From d2cbbbf42d978bc554a012f0719921ce76954cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jib=C3=A9=20Barth?= Date: Thu, 19 Oct 2023 10:04:48 +0200 Subject: [PATCH 06/10] Feat: Add a new akeneo_association_types fixture that allow to launch association-type import --- docs/FIXTURE.md | 26 +++++++++++ src/Fixture/AssociationTypesFixture.php | 57 +++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/Fixture/AssociationTypesFixture.php diff --git a/docs/FIXTURE.md b/docs/FIXTURE.md index 1e0c37f3..6030d4e2 100644 --- a/docs/FIXTURE.md +++ b/docs/FIXTURE.md @@ -111,3 +111,29 @@ sylius_fixtures: - 'another_attribute_code' ``` Inside `custom` node option, you can provide any query parameter supported by [Akneneo API](https://api.akeneo.com/documentation/filter.html#filter-attributes). + +## Association Types - `akeneo_association_types` + +This fixture allow you to trigger the `akeneo:import:association-type` command. + +You can specify the batch size, if you allow parallel import, and max concurrency. + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_association_types: + options: + batch_size: 100 + allow_parallel: true + max_concurrency: 4 +``` + +> [!NOTE] +> Given [Akeneo API](https://api.akeneo.com/api-reference.html#Associationtype) don't provide any search filter for association types, +> it's not currently possible de reduce the number of association types to import. + + diff --git a/src/Fixture/AssociationTypesFixture.php b/src/Fixture/AssociationTypesFixture.php new file mode 100644 index 00000000..c1102170 --- /dev/null +++ b/src/Fixture/AssociationTypesFixture.php @@ -0,0 +1,57 @@ +associationTypePipelineFactory->create(); + $payload = $this->payloadFactory->create( + AssociationTypePayload::class, + ); + + $payload->setBatchSize($options['batch_size']); + $payload->setAllowParallel($options['allow_parallel']); + $payload->setMaxRunningProcessQueueSize($options['max_concurrency']); + + $pipeline->process($payload); + } + + public function getName(): string + { + return 'akeneo_association_types'; + } + + 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() + ->end() + ; + } +} From 2be095145c389b0a7b57813108aa7df1ae582de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jib=C3=A9=20Barth?= Date: Thu, 19 Oct 2023 11:41:51 +0200 Subject: [PATCH 07/10] Feat: Add a new akeneo_families fixture that allow to launch family import * We also update the ProductGroup entity with delete cascade on parent to allow purge database before launching fixtures. --- docs/FIXTURE.md | 44 +++++++++++++++ src/Entity/ProductGroup.php | 4 +- src/Fixture/FamiliesFixture.php | 70 ++++++++++++++++++++++++ src/Migrations/Version20231019090303.php | 30 ++++++++++ src/Task/Family/ProcessFamilyTask.php | 2 + 5 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 src/Fixture/FamiliesFixture.php create mode 100644 src/Migrations/Version20231019090303.php diff --git a/docs/FIXTURE.md b/docs/FIXTURE.md index 6030d4e2..7c57de7d 100644 --- a/docs/FIXTURE.md +++ b/docs/FIXTURE.md @@ -136,4 +136,48 @@ sylius_fixtures: > Given [Akeneo API](https://api.akeneo.com/api-reference.html#Associationtype) don't provide any search filter for association types, > it's not currently possible de reduce the number of association types to import. +## Families - `akeneo_families` + +This fixture allow you to trigger the `akeneo:import:families` command. + +You can specify the batch size, if you allow parallel import, and max concurrency. + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_families: + options: + batch_size: 100 + allow_parallel: true + max_concurrency: 4 +``` + +You can also provide a custom filter to reduce the number of families you want to import. + +Inside `custom` node option, you can provide any query parameter supported by [Akneneo API](https://api.akeneo.com/documentation/filter.html#filter-on-product-model-properties). + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_families: + options: + custom: + search: + categories: + - + operator: 'IN' + value: + - 'root_category' +``` + +> [!NOTE] +> The API call made is on ProductModel endpoint, so be careful to only use filters available for this endpoint. diff --git a/src/Entity/ProductGroup.php b/src/Entity/ProductGroup.php index 999e61e5..37c422a6 100644 --- a/src/Entity/ProductGroup.php +++ b/src/Entity/ProductGroup.php @@ -39,10 +39,10 @@ class ProductGroup implements ProductGroupInterface /** * @ORM\ManyToOne(targetEntity="Synolia\SyliusAkeneoPlugin\Entity\ProductGroupInterface") * - * @ORM\JoinColumn(referencedColumnName="id", nullable=true) + * @ORM\JoinColumn(referencedColumnName="id", nullable=true, onDelete="CASCADE") */ #[ORM\ManyToOne(targetEntity: ProductGroupInterface::class)] - #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true)] + #[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')] private ?ProductGroupInterface $parent = null; /** @ORM\Column(type="string", length=255, nullable=false, unique=true) */ diff --git a/src/Fixture/FamiliesFixture.php b/src/Fixture/FamiliesFixture.php new file mode 100644 index 00000000..7f118903 --- /dev/null +++ b/src/Fixture/FamiliesFixture.php @@ -0,0 +1,70 @@ + + * } $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/Migrations/Version20231019090303.php b/src/Migrations/Version20231019090303.php new file mode 100644 index 00000000..6429f99d --- /dev/null +++ b/src/Migrations/Version20231019090303.php @@ -0,0 +1,30 @@ +addSql('ALTER TABLE akeneo_product_group DROP FOREIGN KEY FK_52E48776727ACA70'); + $this->addSql('ALTER TABLE akeneo_product_group ADD CONSTRAINT FK_52E48776727ACA70 FOREIGN KEY (parent_id) REFERENCES akeneo_product_group (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE akeneo_product_group DROP FOREIGN KEY FK_52E48776727ACA70'); + $this->addSql('ALTER TABLE akeneo_product_group ADD CONSTRAINT FK_52E48776727ACA70 FOREIGN KEY (parent_id) REFERENCES akeneo_product_group (id) ON UPDATE NO ACTION ON DELETE NO ACTION'); + } +} diff --git a/src/Task/Family/ProcessFamilyTask.php b/src/Task/Family/ProcessFamilyTask.php index f3e42a08..64ec3f27 100644 --- a/src/Task/Family/ProcessFamilyTask.php +++ b/src/Task/Family/ProcessFamilyTask.php @@ -55,6 +55,8 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte $queryParameters = []; } + $queryParameters = \array_merge_recursive($queryParameters, $payload->getCustomFilters()); + $resources = $payload->getAkeneoPimClient()->getProductModelApi()->all( $this->apiConnectionProvider->get()->getPaginationSize(), $queryParameters, From 919f551a4f8908d5bb04f393f204f6ed0941f50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jib=C3=A9=20Barth?= Date: Thu, 19 Oct 2023 13:25:12 +0200 Subject: [PATCH 08/10] Feat: Add a new akeneo_product_models fixture that allow to launch product-models import --- docs/FIXTURE.md | 57 +++++++++++++++- src/Fixture/ProductModelsFixture.php | 66 +++++++++++++++++++ .../ProductModel/ProcessProductModelsTask.php | 2 + 3 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 src/Fixture/ProductModelsFixture.php diff --git a/docs/FIXTURE.md b/docs/FIXTURE.md index 7c57de7d..a1d512b3 100644 --- a/docs/FIXTURE.md +++ b/docs/FIXTURE.md @@ -46,7 +46,7 @@ You can also provide a custom filter to reduce the number of categories you want > [!IMPORTANT] > If you want to get only some children categories, make sure that all parents are also included in your search. -Inside `custom` node option, you can provide any query parameter supported by [Akneneo API](https://api.akeneo.com/documentation/filter.html#filter-categories). +Inside `custom` node option, you can provide any query parameter supported by [Akeneo API](https://api.akeneo.com/documentation/filter.html#filter-categories). ```yaml # config/packages/sylius_fixtures.yaml @@ -110,7 +110,7 @@ sylius_fixtures: - 'attribute_code' - 'another_attribute_code' ``` -Inside `custom` node option, you can provide any query parameter supported by [Akneneo API](https://api.akeneo.com/documentation/filter.html#filter-attributes). +Inside `custom` node option, you can provide any query parameter supported by [Akeneo API](https://api.akeneo.com/documentation/filter.html#filter-attributes). ## Association Types - `akeneo_association_types` @@ -158,7 +158,7 @@ sylius_fixtures: You can also provide a custom filter to reduce the number of families you want to import. -Inside `custom` node option, you can provide any query parameter supported by [Akneneo API](https://api.akeneo.com/documentation/filter.html#filter-on-product-model-properties). +Inside `custom` node option, you can provide any query parameter supported by [Akeneo API](https://api.akeneo.com/documentation/filter.html#filter-on-product-model-properties). ```yaml # config/packages/sylius_fixtures.yaml @@ -181,3 +181,54 @@ sylius_fixtures: > [!NOTE] > The API call made is on ProductModel endpoint, so be careful to only use filters available for this endpoint. +## Product Models - `akeneo_product_models` + +This fixture allow you to trigger the `akeneo:import:product-models` command. + +You can specify the batch size, if you allow parallel import, and max concurrency. + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_product_models: + options: + batch_size: 100 + allow_parallel: true + max_concurrency: 4 +``` + +> [!IMPORTANT] +> Before this fixture, you need to create a [Product Filter rule](https://github.com/synolia/SyliusAkeneoPlugin/blob/master/docs/CONFIGURE_DETAIL.md#product-filter-rules). + +You can also provide a custom filter to reduce the number of product-models you want to import. + +Inside `custom` node option, you can provide any query parameter supported by [Akeneo API](https://api.akeneo.com/documentation/filter.html#filter-on-product-model-properties). + +```yaml +sylius_fixtures: + suites: + app: + fixtures: + akeneo_product_models: + options: + custom: + search: + categories: + - + operator: 'IN' + value: + - 'root_category' + - 'another_category' + parent: + - + operator: 'NOT EMPTY' +``` + +> [!NOTE] +> Adding NOT EMPTY filter for parent will avoid warning while importing product models. +> We actually don't import productModel without parents. + diff --git a/src/Fixture/ProductModelsFixture.php b/src/Fixture/ProductModelsFixture.php new file mode 100644 index 00000000..8059ca4f --- /dev/null +++ b/src/Fixture/ProductModelsFixture.php @@ -0,0 +1,66 @@ + + * } $options + */ + public function load(array $options): void + { + $pipeline = $this->productModelPipelineFactory->create(); + $payload = $this->payloadFactory->create( + ProductModelPayload::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_product_models'; + } + + 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/Task/ProductModel/ProcessProductModelsTask.php b/src/Task/ProductModel/ProcessProductModelsTask.php index 054022fd..cb7e0a4f 100644 --- a/src/Task/ProductModel/ProcessProductModelsTask.php +++ b/src/Task/ProductModel/ProcessProductModelsTask.php @@ -58,6 +58,8 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte $queryParameters = []; } + $queryParameters = array_merge_recursive($queryParameters, $payload->getCustomFilters()); + $resources = $payload->getAkeneoPimClient()->getProductModelApi()->all( $this->apiConnectionProvider->get()->getPaginationSize(), $queryParameters, From d2842128897f25c5344e641b44ca0e6591771f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jib=C3=A9=20Barth?= Date: Fri, 20 Oct 2023 09:59:40 +0200 Subject: [PATCH 09/10] Feat: Add a new akeneo_products fixture that allow to launch products import --- docs/FIXTURE.md | 50 ++++++++++++++++++ src/Fixture/ProductsFixture.php | 66 ++++++++++++++++++++++++ src/Task/Product/ProcessProductsTask.php | 2 + 3 files changed, 118 insertions(+) create mode 100644 src/Fixture/ProductsFixture.php diff --git a/docs/FIXTURE.md b/docs/FIXTURE.md index a1d512b3..30cdc289 100644 --- a/docs/FIXTURE.md +++ b/docs/FIXTURE.md @@ -232,3 +232,53 @@ sylius_fixtures: > Adding NOT EMPTY filter for parent will avoid warning while importing product models. > We actually don't import productModel without parents. + +## Products - `akeneo_products` + +This fixture allow you to trigger the `akeneo:import:products` command. + +You can specify the batch size, if you allow parallel import, and max concurrency. + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_products: + options: + batch_size: 100 + allow_parallel: true + max_concurrency: 4 +``` + +Like others fixtures, you can reduce amount of product to import by adding filters. +Inside `custom` node option, you can provide any query parameter supported by [Akeneo API](https://api.akeneo.com/documentation/filter.html#filter-on-product-properties). + + +```yaml +# config/packages/sylius_fixtures.yaml + +sylius_fixtures: + suites: + app: + fixtures: + akeneo_products: + options: + custom: + search: + code: + - + operator: 'IN' + value: + - 'awesome_product' +``` + +> [!NOTE] +> While launching this fixture, the [Product Filter rule](https://github.com/synolia/SyliusAkeneoPlugin/blob/master/docs/CONFIGURE_DETAIL.md#product-filter-rules) will be applied too. +> Custom search can override those values. + + + + diff --git a/src/Fixture/ProductsFixture.php b/src/Fixture/ProductsFixture.php new file mode 100644 index 00000000..2cf95714 --- /dev/null +++ b/src/Fixture/ProductsFixture.php @@ -0,0 +1,66 @@ + + * } $options + */ + public function load(array $options): void + { + $pipeline = $this->productPipelineFactory->create(); + $payload = $this->payloadFactory->create( + ProductPayload::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_products'; + } + + 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/Task/Product/ProcessProductsTask.php b/src/Task/Product/ProcessProductsTask.php index 0c80fbfc..ed80822d 100644 --- a/src/Task/Product/ProcessProductsTask.php +++ b/src/Task/Product/ProcessProductsTask.php @@ -66,6 +66,8 @@ public function __invoke(PipelinePayloadInterface $payload): PipelinePayloadInte } catch (CommandContextIsNullException) { } + $queryParameters = array_merge_recursive($queryParameters, $payload->getCustomFilters()); + /** @var \Akeneo\Pim\ApiClient\Pagination\PageInterface|null $resources */ $resources = $payload->getAkeneoPimClient()->getProductApi()->listPerPage( $this->apiConnectionProvider->get()->getPaginationSize(), From 627e2bafc64f1d7a8dc826449cee0a7d0cf2680e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jib=C3=A9=20Barth?= Date: Fri, 20 Oct 2023 15:51:31 +0200 Subject: [PATCH 10/10] Akeneo client is now lazy --- install/Application/config/packages/test/akeneo.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install/Application/config/packages/test/akeneo.yaml b/install/Application/config/packages/test/akeneo.yaml index 395002f7..415951eb 100644 --- a/install/Application/config/packages/test/akeneo.yaml +++ b/install/Application/config/packages/test/akeneo.yaml @@ -16,7 +16,7 @@ services: Akeneo\Pim\ApiClient\AkeneoPimClientInterface: factory: ['@Tests\Synolia\SyliusAkeneoPlugin\PHPUnit\Client\ClientFactory', 'createFromApiCredentials'] - + lazy: true Synolia\SyliusAkeneoPlugin\Builder\Attribute\ProductAttributeValueValueBuilder: ~ Synolia\SyliusAkeneoPlugin\Factory\AttributePipelineFactory: ~ Synolia\SyliusAkeneoPlugin\Factory\CategoryPipelineFactory: ~ @@ -25,7 +25,6 @@ services: Synolia\SyliusAkeneoPlugin\Factory\AssociationTypePipelineFactory: ~ Synolia\SyliusAkeneoPlugin\Filter\ProductFilter: ~ Synolia\SyliusAkeneoPlugin\Provider\AkeneoAttributePropertiesProvider: ~ - Synolia\SyliusAkeneoPlugin\Provider\SyliusAkeneoLocaleCodeProvider: ~ Synolia\SyliusAkeneoPlugin\Provider\TaskProvider: ~ Synolia\SyliusAkeneoPlugin\Retriever\FamilyRetriever: ~ Synolia\SyliusAkeneoPlugin\Repository\ProductAttributeRepository: ~