Skip to content

Commit

Permalink
Import also product associations on webhook and on product model impo…
Browse files Browse the repository at this point in the history
…rt (#102)
  • Loading branch information
lruozzi9 committed Dec 13, 2023
1 parent e46a682 commit 2e87b29
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Controller/ProductImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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]),
Expand Down
5 changes: 5 additions & 0 deletions src/ProductModel/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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'],
));
}
}
}
5 changes: 3 additions & 2 deletions tests/Integration/Controller/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 2e87b29

Please sign in to comment.