Skip to content

Setono/SyliusCouponUrlApplicationPlugin

Repository files navigation

Sylius Coupon URL Application Plugin

Latest Version Software License Build Status Code Coverage Mutation testing

Apply coupons by going to example.com/coupon or directly from the URL by going to example.com/?coupon=CODE.

Installation

composer require setono/sylius-coupon-url-application-plugin

Import routing

# config/routes/setono_sylius_coupon_url_application.yaml
setono_sylius_coupon_url_application:
    resource: "@SetonoSyliusCouponUrlApplicationPlugin/config/routes.yaml"

or if your app doesn't use locales:

# config/routes/setono_sylius_coupon_url_application.yaml
setono_sylius_coupon_url_application:
    resource: "@SetonoSyliusCouponUrlApplicationPlugin/config/routes_no_locale.yaml"

Install assets

php bin/console assets:install

How coupon application works

The plugin's main use case is sending coupon links from email campaigns, newsletters, ads, etc. A customer clicks https://example.com/?coupon=CHRISTMAS and the coupon is attached to their cart immediately — even before they have added a single item. As soon as the cart matches the promotion's rules (e.g. a minimum cart total, a required taxon), the discount activates.

To support this flow, the plugin runs the coupon application in two stages:

  1. Coupon-level eligibility (PromotionCouponEligibilityCheckerInterface) — gates whether the coupon is attached at all. This checks the coupon's start/end dates, total usage limit, per-customer usage limit, and channel applicability. If any of these fail, the coupon is rejected with an error flash and not attached to the cart.

  2. Promotion-level eligibility (PromotionEligibilityCheckerInterface) — determines which flash the customer sees after the coupon is attached. This includes the underlying promotion's rules (cart-total threshold, taxon/product allow-lists, etc.):

    • Cart already qualifies → success flash setono_sylius_coupon_url_application.coupon_applied ("The coupon code is now activated in your cart")
    • Cart doesn't qualify yet → info flash setono_sylius_coupon_url_application.coupon_applied_not_fulfilled ("The coupon code is saved in your cart, but the discount is not active yet because your cart does not contain the items, amounts or meet other criteria that the coupon requires…")

This deliberately differs from Sylius's built-in cart coupon widget, which rejects coupons up-front when the cart doesn't satisfy promotion rules. The plugin's leniency is the point — customers should be able to click the link in an email before shopping, not after.

About

Apply coupons directly from the URL or on a separate page

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors