Sylius Practical Mastery Course
Chapter 25.2 - How to create a Plugin
This plugin is the product of Sylius training. It allows you to add a custom “Brand” resource, with those features :
- Back Office Grid: creation, edition, deletion,
- Assignment to a category "automotive" or "electronics",
- Workflow for brand validation by API / State Machine,
- Association brands-products, and listing of branded products.
Notes:
- 1st tested on a Sylius v1.13 Docker Project
- Then tested on a Sylius v1.14 Docker Project
- Finally tested on a Sylius v2.0 Docker Project
Make sure you're running a correctly installed version of the Sylius Docker project, and that you've performed all the necessary migrations beforehand.
-
Get the plugin from Composer
docker compose exec php composer require majerome/sylius-workshop-plugin --no-scripts
-
Apply the git patch to set up the plugin:
git apply vendor/majerome/sylius-workshop-plugin/src/Installer/majerome-workshop-plugin-sylius-2.0.patch
Notes:
- You can revert that patch using majerome-workshop-plugin-sylius-2.0-reverse.patch file instead
- If you are using a Sylius v1.13 project, replace the patch file with
majerome-workshop-plugin-sylius-1.13.patch.
(reverse patch is majerome-workshop-plugin-sylius-1.13-reverse.patch) - If you are using a Sylius v1.14 project, replace the patch file with
majerome-workshop-plugin-sylius-1.14.patch.
(reverse patch is majerome-workshop-plugin-sylius-1.14-reverse.patch)
-
Get into the php container and flush the cache:
make php-shell
Then run:
bin/console cache:clear
-
Check if a migration is available:
bin/console doctrine:migrations:list
Note: Available migrations have the status "not migrated".
If not, create a new migration file:
bin/console doctrine:migrations:diff
Note: Choose namespace
[0] App\Migrations
. -
Run the migration
bin/console doctrine:migrations:migrate
-
Load the fixtures:
bin/console sylius:fixtures:load -n
-
Clear the cache again, to handle translations:
bin/console cache:clear
-
Play with your brand new "Brand" resource!
- v1.0.9 - Valid version for Sylius v1.13
- v1.1.4 - Valid version for Sylius v1.14
- v1.2.4 - Valid version for Sylius v2.0
- Sylius v1
- Sylius v2