Markus Michalski FAQ

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.

Deutsche Version

Back to overview

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.

  1. 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
  1. Register the bundle in config/bundles.php:
Mmd\SyliusVariantPriceSurchargePlugin\MmdSyliusVariantPriceSurchargePlugin::class => ['all' => true],
  1. 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.yaml contains no routes, so you do not need to import it.

  1. Run the setup command:
bin/console mmd:variant-price-surcharge:setup
  1. 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:

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

  1. Open a product in the admin and edit a variant. The new Price surcharge section appears there.
  2. 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:

  1. 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.
  2. 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'
  1. Remove the route import and the bundle entry.
  2. 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.