From 2e87b292a8a79eb6ad0c8d029851537e2dfaa39a Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Wed, 13 Dec 2023 14:38:08 +0100 Subject: [PATCH] Import also product associations on webhook and on product model import (#102) --- src/Controller/ProductImportController.php | 5 +++++ src/ProductModel/Importer.php | 5 +++++ tests/Integration/Controller/WebhookControllerTest.php | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Controller/ProductImportController.php b/src/Controller/ProductImportController.php index 272e1f46..291ae686 100644 --- a/src/Controller/ProductImportController.php +++ b/src/Controller/ProductImportController.php @@ -14,6 +14,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; use Webgriffe\SyliusAkeneoPlugin\Message\ItemImport; use Webgriffe\SyliusAkeneoPlugin\Product\Importer as ProductImporter; +use Webgriffe\SyliusAkeneoPlugin\ProductAssociations\Importer as ProductAssociationsImporter; use Webgriffe\SyliusAkeneoPlugin\ProductModel\Importer as ProductModelImporter; use Webmozart\Assert\Assert; @@ -52,6 +53,10 @@ public function importAction(int $productId): Response ProductImporter::AKENEO_ENTITY, $productVariantCode, )); + $this->messageBus->dispatch(new ItemImport( + ProductAssociationsImporter::AKENEO_ENTITY, + $productVariantCode, + )); $this->addFlash( 'success', $this->translator->trans('webgriffe_sylius_akeneo.ui.enqueued_success', ['{code}' => $productVariantCode]), diff --git a/src/ProductModel/Importer.php b/src/ProductModel/Importer.php index 75105956..7f2c6205 100644 --- a/src/ProductModel/Importer.php +++ b/src/ProductModel/Importer.php @@ -14,6 +14,7 @@ use Webgriffe\SyliusAkeneoPlugin\ImporterInterface; use Webgriffe\SyliusAkeneoPlugin\Message\ItemImport; use Webgriffe\SyliusAkeneoPlugin\Product\Importer as ProductImporter; +use Webgriffe\SyliusAkeneoPlugin\ProductAssociations\Importer as ProductAssociationsImporter; use Webmozart\Assert\Assert; /** @@ -80,6 +81,10 @@ public function import(string $identifier): void ProductImporter::AKENEO_ENTITY, $product['identifier'], )); + $this->messageBus->dispatch(new ItemImport( + ProductAssociationsImporter::AKENEO_ENTITY, + $product['identifier'], + )); } } } diff --git a/tests/Integration/Controller/WebhookControllerTest.php b/tests/Integration/Controller/WebhookControllerTest.php index 00097d83..9846b0e7 100644 --- a/tests/Integration/Controller/WebhookControllerTest.php +++ b/tests/Integration/Controller/WebhookControllerTest.php @@ -91,9 +91,10 @@ public function it_imports_created_product_models_on_akeneo(): void $this->webhookController->postAction($request); $itemImportResults = $this->itemImportResultRepository->findAll(); - self::assertCount(2, $itemImportResults); + self::assertCount(3, $itemImportResults); self::assertEquals('Successfully imported item "Product" with identifier "PRODUCT" from Akeneo.', $itemImportResults[0]->getMessage()); - self::assertEquals('Successfully imported item "ProductModel" with identifier "PRODUCT_MODEL" from Akeneo.', $itemImportResults[1]->getMessage()); + self::assertEquals('Successfully imported item "ProductAssociations" with identifier "PRODUCT" from Akeneo.', $itemImportResults[1]->getMessage()); + self::assertEquals('Successfully imported item "ProductModel" with identifier "PRODUCT_MODEL" from Akeneo.', $itemImportResults[2]->getMessage()); } /** @test */