Variant Price Surcharge: Installation and Operation
Install Variant Price Surcharge for Sylius: Composer package, registering the bundle and admin routes, running the setup command, updating and uninstalling in the right order.
Variant Price Surcharge: Installation and Operation
Requirements
| Requirement | Version | Notes |
|---|---|---|
| Sylius | ^2.2 | Package sylius/sylius, tested with 2.2 and 2.3 |
| PHP | ^8.3 | |
| Database | MySQL or MariaDB | The bundled migrations are written in MySQL syntax |
The plugin does not require you to extend the Sylius ProductVariant class. It creates three tables of its own and works through decorators of the price calculators.
Installation
Private repository, distributed through Packeton (
https://packeton.markus-michalski.net). Access credentials are provided after license purchase/approval.
- Add Packeton as a Composer repository and install the package:
{ "repositories": [{ "type": "composer", "url": "https://packeton.markus-michalski.net" }] }
composer require mmd/sylius-variant-price-surcharge-plugin
- Register the bundle in
config/bundles.php:
Mmd\SyliusVariantPriceSurchargePlugin\MmdSyliusVariantPriceSurchargePlugin::class => ['all' => true],
- Import the admin routes, for example in
config/routes/mmd_sylius_variant_price_surcharge.yaml:
mmd_sylius_variant_price_surcharge_admin:
resource: "@MmdSyliusVariantPriceSurchargePlugin/config/routes/admin.yaml"
The routes are required: the admin menu entry points to the settings page. The file
config/routes/shop.yamlcontains no routes, so you do not need to import it.
- Run the setup command:
bin/console mmd:variant-price-surcharge:setup
- Clear the cache:
bin/console cache:clear
The plugin registers the Twig hooks for the variant form, the settings page and the overview grid automatically. You do not need to install or build any assets.
The setup command
mmd:variant-price-surcharge:setup runs only the open migrations of this plugin, nothing from the application or from other plugins. It works through these steps:
- It checks that the admin route
mmd_variant_price_surcharge_admin_settingsexists. If it is missing, it prints the snippet from step 3 and carries on. It never writes toconfig/. - It aborts if Doctrine does not know the plugin's migrations, for example because the bundle is not enabled.
- If the plugin has no open migration, it reports "Migrations are already up to date." and does nothing. That makes it safe to run after every
composer update. - If the plugin has open migrations but Sylius migrations are still open as well, it aborts and points you to
bin/console doctrine:migrations:migrate. Run that first, then run the setup command again. - Otherwise it runs the plugin's open migrations and reports how many it executed. Doctrine asks for confirmation in the process. In scripts, pass
--no-interaction.
The command has no options of its own. Running bin/console doctrine:migrations:migrate works as well, but it runs all open migrations of the whole application.
What the migrations create
| Table | Content |
|---|---|
mmd_product_variant_price_surcharge |
One row per configured variant: base variant yes/no, surcharge active yes/no, percentage, fixed surcharge. Foreign key to sylius_product_variant with ON DELETE CASCADE |
mmd_variant_price_surcharge_settings |
One row holding the global switch |
mmd_product_variant_price_surcharge_channel |
Per-channel overrides: one row per surcharge and channel code. Foreign key to mmd_product_variant_price_surcharge with ON DELETE CASCADE |
After installation
- Open a product in the admin and edit a variant. The new Price surcharge section appears there.
- Mark one variant as Base variant and enable Apply surcharge on another variant.
Details are on the Configuration page.
Update
composer update mmd/sylius-variant-price-surcharge-plugin
bin/console mmd:variant-price-surcharge:setup
bin/console cache:clear
Run the setup command right after an update. The price calculator and the variant form access the table
mmd_product_variant_price_surcharge_channel. If it is missing because the migration has not run yet, every variant with a surcharge silently returns its own price and the variant edit page in the admin reports an error. No further steps are needed: a shop without per-channel overrides behaves as before afterwards.
Uninstall
Keep this order, while the bundle is still registered:
- Check which variants carry a surcharge (overview in the admin). After uninstalling, every variant is priced at the price stored in its own channel pricing again.
- Roll back the migrations, newest first:
bin/console doctrine:migrations:execute --down 'Mmd\SyliusVariantPriceSurchargePlugin\Migrations\Version20261015135354'
bin/console doctrine:migrations:execute --down 'Mmd\SyliusVariantPriceSurchargePlugin\Migrations\Version20260905124014'
bin/console doctrine:migrations:execute --down 'Mmd\SyliusVariantPriceSurchargePlugin\Migrations\Version20260905080038'
- Remove the route import and the bundle entry.
- Remove the package:
composer remove mmd/sylius-variant-price-surcharge-plugin
Rolling back drops all three tables and with them every configured surcharge, including the per-channel overrides.