Skip to content

Commit

Permalink
WIP: Add import all action on admin section (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Feb 13, 2024
1 parent af70038 commit 9a3c445
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
17 changes: 17 additions & 0 deletions config/admin_routing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return function (RoutingConfigurator $routes): void {
$routes->add('webgriffe_sylius_akeneo_product_import', '/product/{productId}/import')
->controller(['webgriffe_sylius_akeneo.controller.product_import_controller', 'importAction'])
;

$routes->import(
'@WebgriffeSyliusAkeneoPlugin/Resources/config/admin_routing.yml',
'sylius_admin'
);
$routes->import('.', 'sylius.resource');
};
4 changes: 4 additions & 0 deletions config/admin_routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ webgriffe_sylius_akeneo_item_import_result:
index:
icon: 'cloud download'
type: sylius.resource

webgriffe_sylius_akeneo_products_import:
controller: webgriffe_sylius_akeneo.controller.product_import_controller::importAllAction
path: products/import
13 changes: 12 additions & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,18 @@ sylius_grid:
label: webgriffe_sylius_akeneo.ui.successful
message:
type: string
label: webgriffe_sylius_akeneo.ui.message
label: webgriffe_sylius_akeneo.ui.message
actions:
main:
import_product_variants:
type: importProduct
label: webgriffe_sylius_akeneo.ui.schedule_import
options:
link:
route: webgriffe_sylius_akeneo_products_import
parameters: []
icon: cloud download
color: violet

framework:
messenger:
Expand Down
42 changes: 42 additions & 0 deletions src/Controller/ProductImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Webgriffe\SyliusAkeneoPlugin\Controller;

use Akeneo\Pim\ApiClient\AkeneoPimClient;
use DateTime;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Repository\ProductRepositoryInterface;
Expand All @@ -13,6 +15,7 @@
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webgriffe\SyliusAkeneoPlugin\Message\ItemImport;
use Webgriffe\SyliusAkeneoPlugin\Product\Importer;
use Webgriffe\SyliusAkeneoPlugin\Product\Importer as ProductImporter;
use Webgriffe\SyliusAkeneoPlugin\ProductAssociations\Importer as ProductAssociationsImporter;
use Webgriffe\SyliusAkeneoPlugin\ProductModel\Importer as ProductModelImporter;
Expand All @@ -24,7 +27,27 @@ public function __construct(
private ProductRepositoryInterface $productRepository,
private MessageBusInterface $messageBus,
private TranslatorInterface $translator,
private ?Importer $productImporter = null,
) {
if ($this->akeneoPimClient === null) {

Check failure on line 32 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.3, MySQL 8.0

Access to an undefined property Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController::$akeneoPimClient.

Check failure on line 32 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4, MySQL 8.0

Access to an undefined property Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController::$akeneoPimClient.

Check failure on line 32 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.3, MySQL 8.0

Access to an undefined property Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController::$akeneoPimClient.

Check failure on line 32 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

Access to an undefined property Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController::$akeneoPimClient.

Check failure on line 32 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.3, MySQL 8.0

Access to an undefined property Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController::$akeneoPimClient.

Check failure on line 32 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4, MySQL 8.0

Access to an undefined property Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController::$akeneoPimClient.

Check failure on line 32 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

Access to an undefined property Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController::$akeneoPimClient.

Check failure on line 32 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4, MySQL 8.0

Access to an undefined property Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController::$akeneoPimClient.

Check failure on line 32 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4, MySQL 8.0

Access to an undefined property Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController::$akeneoPimClient.

Check failure on line 32 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.3, MySQL 8.0

Access to an undefined property Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController::$akeneoPimClient.
trigger_deprecation(
'webgriffe/sylius-akeneo-plugin',
'1.5.0',
'Not passing an instance of %s to %s constructor is deprecated. It will be mandatory in version 2.0.0.',
AkeneoPimClient::class,
self::class,
);
}

if ($this->productImporter === null) {
trigger_deprecation(
'webgriffe/sylius-akeneo-plugin',
'1.5.0',
'Not passing an instance of %s to %s constructor is deprecated. It will be mandatory in version 2.0.0.',
AkeneoPimClient::class,
self::class,
);
}
}

public function importAction(int $productId): Response
Expand Down Expand Up @@ -65,4 +88,23 @@ public function importAction(int $productId): Response

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

public function importAllAction(): Response
{
$identifiers = $this->productImporter->getIdentifiersModifiedSince((new DateTime())->setTimestamp(0));

Check failure on line 94 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.3, MySQL 8.0

Cannot call method getIdentifiersModifiedSince() on Webgriffe\SyliusAkeneoPlugin\Product\Importer|null.

Check failure on line 94 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4, MySQL 8.0

Cannot call method getIdentifiersModifiedSince() on Webgriffe\SyliusAkeneoPlugin\Product\Importer|null.

Check failure on line 94 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.3, MySQL 8.0

Cannot call method getIdentifiersModifiedSince() on Webgriffe\SyliusAkeneoPlugin\Product\Importer|null.

Check failure on line 94 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

Cannot call method getIdentifiersModifiedSince() on Webgriffe\SyliusAkeneoPlugin\Product\Importer|null.

Check failure on line 94 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^6.3, MySQL 8.0

Cannot call method getIdentifiersModifiedSince() on Webgriffe\SyliusAkeneoPlugin\Product\Importer|null.

Check failure on line 94 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4, MySQL 8.0

Cannot call method getIdentifiersModifiedSince() on Webgriffe\SyliusAkeneoPlugin\Product\Importer|null.

Check failure on line 94 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.0, Symfony ^5.4, MySQL 8.0

Cannot call method getIdentifiersModifiedSince() on Webgriffe\SyliusAkeneoPlugin\Product\Importer|null.

Check failure on line 94 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.1, Symfony ^5.4, MySQL 8.0

Cannot call method getIdentifiersModifiedSince() on Webgriffe\SyliusAkeneoPlugin\Product\Importer|null.

Check failure on line 94 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^5.4, MySQL 8.0

Cannot call method getIdentifiersModifiedSince() on Webgriffe\SyliusAkeneoPlugin\Product\Importer|null.

Check failure on line 94 in src/Controller/ProductImportController.php

View workflow job for this annotation

GitHub Actions / Sylius ^1.12, PHP 8.2, Symfony ^6.3, MySQL 8.0

Cannot call method getIdentifiersModifiedSince() on Webgriffe\SyliusAkeneoPlugin\Product\Importer|null.

foreach ($identifiers as $identifier) {
$itemImport = new ItemImport(
Importer::AKENEO_ENTITY,
$identifier,
);
$this->messageBus->dispatch($itemImport);
}
$this->addFlash(
'success',
$this->translator->trans('webgriffe_sylius_akeneo.ui.products_enqueued_successfully'),
);

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

0 comments on commit 9a3c445

Please sign in to comment.