/** * Check if this coupon is already applied to the cart. * * @param CartInterface $cart Cart * @param CouponInterface $coupon Coupon * * @throws CouponAlreadyAppliedException Coupon already applied */ public function validateDuplicatedCoupon(CartInterface $cart, CouponInterface $coupon) { $cartCoupon = $this->cartCouponRepository->findOneBy(['cart' => $cart, 'coupon' => $coupon]); if (null !== $cartCoupon) { throw new CouponAlreadyAppliedException(); } }
/** * Check if this coupon is already applied to the cart * * @param CartCouponOnApplyEvent $event Event * * @throws CouponAlreadyAppliedException */ public function checkDuplicates(CartCouponOnApplyEvent $event) { $cartCoupon = $this->cartCouponRepository->findOneBy(['cart' => $event->getCart(), 'coupon' => $event->getCoupon()]); if (null !== $cartCoupon) { throw new CouponAlreadyAppliedException(); } }