Coupons
Coupons are tightly integrated with Sylius Cart Promotions, allowing promotions to be activated by unique codes. Here’s how to create, apply, and generate coupons for promotions.
Coupon Parameters
Each coupon has the following attributes:
Code: The unique identifier for the coupon.
Expiration Date: The date when the coupon expires.
Usage Limit: The maximum number of times it can be used.
Usage Count: Tracks how many times the coupon has been used.
Creating a Coupon-Based Promotion
To create a coupon-based promotion, follow these steps:
Create a Promotion
Begin by creating a new promotion and setting it as coupon-based. Only coupon-based promotions can hold multiple coupons.
Create a Coupon and Link It to the Promotion
Next, create a coupon and associate it with your promotion:
Add a Promotion Action
Define what action the promotion should take when applied. For a free shipping promotion, create a 100% shipping discount action:
Applying a Coupon to an Order
To apply a promotion coupon we've just created to an order:
Ensure the order has shipments (as the above coupon applies a promotion on shipping).
Set the promotion coupon on the order (this simulates a customer applying the coupon code at checkout).
Process the order with the OrderProcessor to apply the promotion.
Generating Multiple Coupons
For larger promotions, manually creating codes is tedious. Sylius offers the CouponGenerator service to automatically generate coupon codes in bulk.
Retrieve the Promotion
First, find the promotion to which you want to add coupons.
Configure the Coupon Generator
Use
PromotionCouponGeneratorInstruction
to specify the number of coupons, code length, expiration date, and usage limit.This example generates 10 coupons with the prefix
NEW_YEAR_
and suffix_SALE
for thesimple_promotion
promotion.
Last updated