Skip to content

Commit

Permalink
Fix import controller (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Dec 13, 2023
1 parent 9288eb7 commit 41c52af
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Controller/ProductImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Webgriffe\SyliusAkeneoPlugin\Controller;

use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Repository\ProductRepositoryInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -12,7 +13,8 @@
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webgriffe\SyliusAkeneoPlugin\Message\ItemImport;
use Webgriffe\SyliusAkeneoPlugin\ProductModel\Importer;
use Webgriffe\SyliusAkeneoPlugin\Product\Importer as ProductImporter;
use Webgriffe\SyliusAkeneoPlugin\ProductModel\Importer as ProductModelImporter;
use Webmozart\Assert\Assert;

final class ProductImportController extends AbstractController
Expand All @@ -34,14 +36,27 @@ public function importAction(int $productId): Response
$productCode = $product->getCode();
Assert::string($productCode);
$this->messageBus->dispatch(new ItemImport(
Importer::AKENEO_ENTITY,
ProductModelImporter::AKENEO_ENTITY,
$productCode,
));

$this->addFlash(
'success',
$this->translator->trans('webgriffe_sylius_akeneo.ui.enqueued_success', ['{code}' => $productCode]),
);
if ($product->isSimple()) {
$productVariant = $product->getVariants()->first();
Assert::isInstanceOf($productVariant, ProductVariantInterface::class);
$productVariantCode = $productVariant->getCode();
Assert::string($productVariantCode);
$this->messageBus->dispatch(new ItemImport(
ProductImporter::AKENEO_ENTITY,
$productVariantCode,
));
$this->addFlash(
'success',
$this->translator->trans('webgriffe_sylius_akeneo.ui.enqueued_success', ['{code}' => $productVariantCode]),
);
}

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

0 comments on commit 41c52af

Please sign in to comment.