public function tryAutomaticCoupons(CartInterface $cart)
    {
        if ($cart->getCartLines()->isEmpty()) {
            return;
        }

        $automaticCoupons = $this->getNonAppliedAutomaticCoupons($cart);

        foreach ($automaticCoupons as $coupon) {
            try {
                $this
                    ->cartCouponManager
                    ->addCoupon($cart, $coupon);
            } catch (AbstractCouponException $e) {
                // Silently tries next coupon on controlled exception
            }
        }
    }
public function tryAutomaticCoupons(CartInterface $cart)
    {
        if ($cart->getCartLines()->isEmpty()) {
            return;
        }

        $automaticCoupons = $this->getNonAppliedAutomaticCoupons($cart);

        foreach ($automaticCoupons as $coupon) {
            try {
                $this
                    ->cartCouponManager
                    ->addCoupon($cart, $coupon);
            } catch (AbstractCouponException $e) {
                // Silently tries next coupon on controlled exception
            }
        }
    }
public function tryAutomaticCoupons ( CartInterface $ cart ) { if ( $ cart -> getCartLines ( ) -> isEmpty ( ) ) { return ; } $ automaticCoupons = $ this -> getNonAppliedAutomaticCoupons ( $ cart ) ; foreach ( $ automaticCoupons as $ coupon ) { try { $ this -> cartCouponManager -> addCoupon ( $ cart , $ coupon ) ; } catch ( AbstractCouponException $ e ) { // Silently tries next coupon on controlled exception } } }
Method subscribed to PreCartLoad event.

Iterate over all automatic Coupons and check if they apply.
If any applies, it will be added to the Cart

@param CartInterface $cart Cart
Method subscribed to PreCartLoad event .