/** * Checks if given Coupon is valid. To determine its validity, this service * will evaluate all rules if there are any. * * @param CartInterface $cart Cart * @param CouponInterface $coupon Coupon * * @return boolean Coupon is valid */ public function checkCouponValidity(CartInterface $cart, CouponInterface $coupon) { $rule = $coupon->getRule(); if (null === $rule) { return true; } try { return $this->ruleManager->evaluate($rule, ['cart' => $cart, 'coupon' => $coupon]); } catch (\Exception $e) { // Maybe log something in case of exception? } return false; }
/** * Checks if given Coupon is valid. To determine its validity, this service * will evaluate all rules if there are any. * * @param CartInterface $cart Cart * @param CouponInterface $coupon Coupon * * @throws CouponRulesNotValidateException Rules not valid */ public function validateCartCouponRules(CartInterface $cart, CouponInterface $coupon) { $rule = $coupon->getRule(); if (null === $rule) { return; } try { $isValid = $this->ruleManager->evaluate($rule, ['cart' => $cart, 'coupon' => $coupon]); if (!$isValid) { throw new CouponRulesNotValidateException(); } return; } catch (Exception $e) { // Maybe log something in case of exception? } throw new CouponRulesNotValidateException(); }