Skip to content

Commit

Permalink
Import product from controller (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Dec 13, 2023
1 parent 703d0a8 commit 47565ce
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions src/Controller/ProductImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webgriffe\SyliusAkeneoPlugin\Message\ItemImport;
use Webgriffe\SyliusAkeneoPlugin\ProductModel\Importer;
use Webmozart\Assert\Assert;

final class ProductImportController extends AbstractController
Expand All @@ -30,28 +31,18 @@ public function importAction(int $productId): Response
if ($product === null) {
throw new NotFoundHttpException('Product not found');
}

$enqueued = [];
foreach ($product->getVariants() as $productVariant) {
$productVariantCode = $productVariant->getCode();
Assert::notNull($productVariantCode);

$queueItem = new ItemImport(
'Product',
$productVariantCode,
);
$this->messageBus->dispatch($queueItem);

$enqueued[] = $productVariantCode;
}

foreach ($enqueued as $code) {
$this->addFlash(
'success',
$this->translator->trans('webgriffe_sylius_akeneo.ui.enqueued_success', ['{code}' => $code]),
);
}

return $this->redirectToRoute('sylius_admin_product_index');
$productCode = $product->getCode();
Assert::string($productCode);
$this->messageBus->dispatch(new ItemImport(
Importer::AKENEO_ENTITY,
$productCode,
));

$this->addFlash(
'success',
$this->translator->trans('webgriffe_sylius_akeneo.ui.enqueued_success', ['{code}' => $productCode]),
);

return $this->redirectToRoute('webgriffe_sylius_akeneo_admin_item_import_result_index');
}
}

0 comments on commit 47565ce

Please sign in to comment.