Coupons
Coupon Parameters
Creating a Coupon-Based Promotion
/** @var PromotionInterface $promotion */ $promotion = $this->container->get('sylius.factory.promotion')->createNew(); $promotion->setCode('free_shipping'); $promotion->setName('Free Shipping'); // Set the promotion's channel $promotion->addChannel($this->container->get('sylius.repository.channel')->findOneBy(['code' => 'US_Web_Store'])); $promotion->setCouponBased(true);/** @var CouponInterface $coupon */ $coupon = $this->container->get('sylius.factory.promotion_coupon')->createNew(); $coupon->setCode('FREESHIPPING'); $promotion->addCoupon($coupon);/** @var PromotionActionFactoryInterface $actionFactory */ $actionFactory = $this->container->get('sylius.factory.promotion_action'); // Use a float for percentage discounts (1 = 100%, 0.1 = 10%) $action = $actionFactory->createShippingPercentageDiscount(1); $promotion->addAction($action); // Save the promotion to the repository $this->container->get('sylius.repository.promotion')->add($promotion);
Applying a Coupon to an Order
Generating Multiple Coupons
Last updated
Was this helpful?
