public function addCouponByCode(
        CartInterface $cart,
        $couponCode
    ) {
        $coupon = $this
            ->couponRepository
            ->findOneBy([
                'code' => $couponCode,
                'enabled' => true,
            ]);

        if (!($coupon instanceof CouponInterface)) {
            throw new CouponNotAvailableException();
        }

        return $this
            ->addCoupon(
                $cart,
                $coupon
            );
    }
public function addCouponByCode(
        CartInterface $cart,
        $couponCode
    ) {
        $coupon = $this
            ->couponRepository
            ->findOneBy([
                'code' => $couponCode,
                'enabled' => true,
            ]);

        if (!($coupon instanceof CouponInterface)) {
            throw new CouponNotAvailableException();
        }

        return $this
            ->addCoupon(
                $cart,
                $coupon
            );
    }
public function addCouponByCode ( CartInterface $ cart , $ couponCode ) { $ coupon = $ this -> couponRepository -> findOneBy ( [ 'code' => $ couponCode , 'enabled' => true , ] ) ; if ( ! ( $ coupon instanceof CouponInterface ) ) { throw new CouponNotAvailableException ( ) ; } return $ this -> addCoupon ( $ cart , $ coupon ) ; }
Given a coupon code, applies it to cart.

@param CartInterface $cart       Cart
@param string        $couponCode Coupon code

@throws AbstractCouponException

@return bool Coupon has added to Cart
Given a coupon code applies it to cart .