Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add import all action on admin section (#153) #198

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@

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');
}
}
Loading