With this Sylius plugin a minimum order value can be set for each channel.
Installs: 6 573
Open Issues: 0
- php: ^7.4 || ^8.0
- sylius/sylius: >=1.10.2 <1.11.0
- behat/behat: ^3.8
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink-extension: ^2.4
- friends-of-behat/page-object-extension: ^0.3
- friendsofsymfony/oauth-server-bundle: ^1.6 || >2.0.0-alpha.0 ^2.0@dev
- matthiasnoback/symfony-config-test: ^4.2
- matthiasnoback/symfony-dependency-injection-test: ^4.2
- mockery/mockery: ^1.4
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12
- phpstan/phpstan-doctrine: ^0.12
- phpstan/phpstan-strict-rules: ^0.12.0
- phpstan/phpstan-webmozart-assert: ^0.12
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.5
This plugin adds the option of configuring a minimum order value for each channel.
When a minimum order value is configured it is not possible to checkout the order if the subtotal of all of the items in the cart is lower the configured minimum.
Configuration by administrator:
Configuring a minimum order value is possible by logging in as an administrator and navigating to the channel configuration:
Choose to edit an existing channel or to add a new one:
This plugin adds a segment to the add/edit pane that can be used to set the desired minimum order value in the base currency:
By default the toggle is set to the off position and the field to enter the minimum order value is disabled. To configure the desired value use the toggle to enable the minimum order value and enter the value in the field.
What do visitors see?
When visiting the shop and not having added enough items to the shopping cart they will not be able to proceed to checkout:
The checkout button is disabled and a message is displayed, providing more insight in the current status:
When clicking the cart widget button, the checkout button is hidden:
If a visitor tries to skip ahead to the checkout process (for example by entering the url manually), the visitor will automatically be redirected to the cart summary page.
How does it work?
Technically what this plugin does is a few things. It adds an optional field to the channel entity and the option to configure the fields value through the admin system.
This value is used by the MinimumOrderValueReached class, which is configured as a guard on all of the transitions of the "sylius_order_checkout" state machine.
By overriding the "sylius.resolver.checkout" service and disabling the original service, the plugin is able to redirect the visitor to the cart summary page when the guard blocks the transition.
Overriding that service also means that the service needs to be configured slightly differently then before (only applicable if you have a customised checkout resolver configuration):
Whereas before the the checkout resolver could be configured through key "sylius_shop", it now needs to be done through key "nedac_sylius_minimum_order_value":
nedac_sylius_minimum_order_value: checkout_resolver: pattern: /checkout/.+ route_map: empty_order: route: sylius_shop_cart_summary cart: route: sylius_shop_checkout_address addressed: route: sylius_shop_checkout_select_shipping shipping_selected: route: sylius_shop_checkout_select_payment shipping_skipped: route: sylius_shop_checkout_select_payment payment_selected: route: sylius_shop_checkout_complete payment_skipped: route: sylius_shop_checkout_complete
This is the default configuration added by this plugin in
src/Resources/config/config.yaml. It can be overridden on an
application level as with any Symfony bundle configuration.
Please see the official Sylius docs on how to configure the checkout resolver, should there be any need to do so.
Supported Sylius versions:
NOTE: This plugin requires PHP 7.4 or up
Install using composer:
composer require nedac/sylius-minimum-order-value-plugin
Generate and run database migration:
bin/console doctrine:migrations:diff bin/console doctrine:migrations:migrate
The flex recipe should take care of enabling the bundle, copying the configuration file and copying the templates that
need to be overridden. It is quite possible that you're already overriding one or more templates.
In that case you'll have to edit/merge those templates manually with the templates that can be found in