From 91cfc6083284e1c15553459be71eff3019e3c5b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Wed, 11 Dec 2024 13:18:59 +0100 Subject: [PATCH] Add the grid in the extension instead of a custom config.yaml file --- README.md | 125 +++++++++++------- .../SetonoSyliusCatalogPromotionExtension.php | 67 +++++++++- src/Resources/config/app/config.yaml | 2 - src/Resources/config/grids/promotion.yaml | 45 ------- .../setono_sylius_catalog_promotion.yaml | 1 - 5 files changed, 142 insertions(+), 98 deletions(-) delete mode 100644 src/Resources/config/app/config.yaml delete mode 100644 src/Resources/config/grids/promotion.yaml diff --git a/README.md b/README.md index f852119..f174c04 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,80 @@ -# Setono Sylius Plugin Skeleton +# Sylius Catalog Promotion Plugin [![Latest Version][ico-version]][link-packagist] +[![Latest Unstable Version][ico-unstable-version]][link-packagist] [![Software License][ico-license]](LICENSE) [![Build Status][ico-github-actions]][link-github-actions] -[![Code Coverage][ico-code-coverage]][link-code-coverage] -[![Mutation testing][ico-infection]][link-infection] - -[Setono](https://setono.com) have made a bunch of [plugins for Sylius](https://github.com/Setono?q=plugin&sort=stargazers), and we have some guidelines -which we try to follow when developing plugins. These guidelines are used in this repository, and it gives you a very -solid base when developing plugins. - -Enjoy! - -## Quickstart - -1. Run - ```shell - composer create-project --prefer-source --no-install --remove-vcs setono/sylius-plugin-skeleton:1.12.x-dev ProjectName - ``` - or just click the `Use this template` button at the right corner of this repository. -2. Run - ```shell - cd ProjectName && composer install - ``` -3. From the plugin skeleton root directory, run the following commands: - - ```bash - php init - (cd tests/Application && yarn install) - (cd tests/Application && yarn build) - (cd tests/Application && bin/console assets:install) - - (cd tests/Application && bin/console doctrine:database:create) - (cd tests/Application && bin/console doctrine:schema:create) - - (cd tests/Application && bin/console sylius:fixtures:load -n) - ``` - -4. Start your local PHP server: `symfony serve` (see https://symfony.com/doc/current/setup/symfony_server.html for docs) - -To be able to set up a plugin's database, remember to configure you database credentials in `tests/Application/.env` and `tests/Application/.env.test`. - -[ico-version]: https://poser.pugx.org/setono/sylius-plugin-skeleton/v/stable -[ico-license]: https://poser.pugx.org/setono/sylius-plugin-skeleton/license -[ico-github-actions]: https://github.com/Setono/SyliusPluginSkeleton/workflows/build/badge.svg -[ico-code-coverage]: https://codecov.io/gh/Setono/SyliusPluginSkeleton/branch/1.12.x/graph/badge.svg -[ico-infection]: https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2FSetono%2FSyliusPluginSkeleton%2F1.12.x - -[link-packagist]: https://packagist.org/packages/setono/sylius-plugin-skeleton -[link-github-actions]: https://github.com/Setono/SyliusPluginSkeleton/actions -[link-code-coverage]: https://codecov.io/gh/Setono/SyliusPluginSkeleton -[link-infection]: https://dashboard.stryker-mutator.io/reports/github.com/Setono/SyliusPluginSkeleton/1.12.x + +Plugin for Sylius to define permanent or time-limited promotions for products and automatically update prices. + +![Screenshot showing catalog promotions admin page](docs/admin-create.png) + +## Install + +### Add plugin to composer.json + +```bash +composer require setono/sylius-catalog-promotion-plugin +``` + +### Register plugin + +```php + ['all' => true], + Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], + // ... +]; + +``` + +**Note**, that we MUST define `SetonoSyliusCatalogPromotionPlugin` BEFORE `SyliusGridBundle`. +Otherwise, you'll see exception like this: + +```bash +You have requested a non-existent parameter "setono_sylius_catalog_promotion.model.promotion.class". +``` + +### Add routing + +```yaml +# config/routes/setono_sylius_catalog_promotion.yaml +setono_sylius_catalog_promotion_admin: + resource: "@SetonoSyliusCatalogPromotionPlugin/Resources/config/admin_routing.yaml" + prefix: /admin +``` + +### Extend core classes + +TODO: Extend `Product` class + +### Create migration + +```bash +php bin/console doctrine:migrations:diff +php bin/console doctrine:migrations:migrate +``` + +### Install assets + +```bash +bin/console sylius:install:assets +``` + +### Configure cron (optional) + +```bash +php bin/console setono:sylius-catalog-promotion:process +``` + +[ico-version]: https://poser.pugx.org/setono/sylius-catalog-promotion-plugin/v/stable +[ico-unstable-version]: https://poser.pugx.org/setono/sylius-catalog-promotion-plugin/v/unstable +[ico-license]: https://poser.pugx.org/setono/sylius-catalog-promotion-plugin/license +[ico-github-actions]: https://github.com/Setono/SyliusCatalogPromotionPlugin/workflows/build/badge.svg + +[link-packagist]: https://packagist.org/packages/setono/sylius-catalog-promotion-plugin +[link-github-actions]: https://github.com/Setono/SyliusCatalogPromotionPlugin/actions diff --git a/src/DependencyInjection/SetonoSyliusCatalogPromotionExtension.php b/src/DependencyInjection/SetonoSyliusCatalogPromotionExtension.php index 40f3bd3..d18f2bf 100644 --- a/src/DependencyInjection/SetonoSyliusCatalogPromotionExtension.php +++ b/src/DependencyInjection/SetonoSyliusCatalogPromotionExtension.php @@ -10,9 +10,10 @@ use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -final class SetonoSyliusCatalogPromotionExtension extends AbstractResourceExtension +final class SetonoSyliusCatalogPromotionExtension extends AbstractResourceExtension implements PrependExtensionInterface { public function load(array $configs, ContainerBuilder $container): void { @@ -31,4 +32,68 @@ public function load(array $configs, ContainerBuilder $container): void $this->registerResources('setono_sylius_catalog_promotion', SyliusResourceBundle::DRIVER_DOCTRINE_ORM, $config['resources'], $container); } + + public function prepend(ContainerBuilder $container): void + { + $container->prependExtensionConfig('sylius_grid', [ + 'grids' => [ + 'setono_sylius_catalog_promotion_admin_promotion' => [ + 'driver' => [ + 'name' => 'doctrine/orm', + 'options' => [ + 'class' => '%setono_sylius_catalog_promotion.model.promotion.class%', + ], + ], + 'sorting' => [ + 'priority' => 'desc', + ], + 'limits' => [100, 200, 500], + 'fields' => [ + 'priority' => [ + 'type' => 'twig', + 'label' => 'sylius.ui.priority', + 'sortable' => null, + 'options' => [ + 'template' => '@SyliusUi/Grid/Field/position.html.twig', + ], + ], + 'code' => [ + 'type' => 'string', + 'label' => 'sylius.ui.code', + 'sortable' => null, + ], + 'name' => [ + 'type' => 'twig', + 'label' => 'sylius.ui.name', + 'path' => '.', + 'sortable' => null, + 'options' => [ + 'template' => '@SyliusUi/Grid/Field/nameAndDescription.html.twig', + ], + ], + ], + 'actions' => [ + 'main' => [ + 'create' => [ + 'type' => 'create', + ], + ], + 'item' => [ + 'delete' => [ + 'type' => 'delete', + ], + 'update' => [ + 'type' => 'update', + ], + ], + 'bulk' => [ + 'delete' => [ + 'type' => 'delete', + ], + ], + ], + ], + ], + ]); + } } diff --git a/src/Resources/config/app/config.yaml b/src/Resources/config/app/config.yaml deleted file mode 100644 index ee91938..0000000 --- a/src/Resources/config/app/config.yaml +++ /dev/null @@ -1,2 +0,0 @@ -imports: - - { resource: "@SetonoSyliusCatalogPromotionPlugin/Resources/config/grids/promotion.yaml" } diff --git a/src/Resources/config/grids/promotion.yaml b/src/Resources/config/grids/promotion.yaml deleted file mode 100644 index 43c2f71..0000000 --- a/src/Resources/config/grids/promotion.yaml +++ /dev/null @@ -1,45 +0,0 @@ -sylius_grid: - grids: - setono_sylius_catalog_promotion_admin_promotion: - driver: - name: doctrine/orm - options: - class: "%setono_sylius_catalog_promotion.model.promotion.class%" - sorting: - priority: desc - fields: - priority: - type: twig - label: sylius.ui.priority - sortable: ~ - options: - template: "@SyliusUi/Grid/Field/position.html.twig" - code: - type: string - label: sylius.ui.code - sortable: ~ - name: - type: twig - label: sylius.ui.name - path: . - sortable: ~ - options: - template: "@SyliusUi/Grid/Field/nameAndDescription.html.twig" - filters: - search: - type: string - label: sylius.ui.search - options: - fields: [code, name] - actions: - main: - create: - type: create - item: - update: - type: update - delete: - type: delete - bulk: - delete: - type: delete diff --git a/tests/Application/config/packages/setono_sylius_catalog_promotion.yaml b/tests/Application/config/packages/setono_sylius_catalog_promotion.yaml index 4f3fc8a..3128d8a 100644 --- a/tests/Application/config/packages/setono_sylius_catalog_promotion.yaml +++ b/tests/Application/config/packages/setono_sylius_catalog_promotion.yaml @@ -1,3 +1,2 @@ imports: - - { resource: "@SetonoSyliusCatalogPromotionPlugin/Resources/config/app/config.yaml" } - { resource: "@SetonoSyliusCatalogPromotionPlugin/Resources/config/app/fixtures.yaml" }