Skip to content

Commit

Permalink
Add the grid in the extension instead of a custom config.yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Dec 11, 2024
1 parent 6ca5c4f commit 91cfc60
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 98 deletions.
125 changes: 76 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
<?php
# config/bundles.php

return [
// ...
Setono\SyliusCatalogPromotionPlugin\SetonoSyliusCatalogPromotionPlugin::class => ['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
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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',
],
],
],
],
],
]);
}
}
2 changes: 0 additions & 2 deletions src/Resources/config/app/config.yaml

This file was deleted.

45 changes: 0 additions & 45 deletions src/Resources/config/grids/promotion.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
imports:
- { resource: "@SetonoSyliusCatalogPromotionPlugin/Resources/config/app/config.yaml" }
- { resource: "@SetonoSyliusCatalogPromotionPlugin/Resources/config/app/fixtures.yaml" }

0 comments on commit 91cfc60

Please sign in to comment.