From c409beb89c3abd7ed04c74d4e9c64b47f12fc691 Mon Sep 17 00:00:00 2001 From: Vincent Lopes-Vicente Date: Thu, 15 Apr 2021 16:26:23 +0200 Subject: [PATCH] Fix coupon error without message --- Config/module.xml | 2 +- Controller/Front/CouponController.php | 12 +++++++++--- I18n/fr_FR.php | 7 ++++--- Model/Api/Cart.php | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Config/module.xml b/Config/module.xml index 46543ce..415f91f 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -20,7 +20,7 @@ en_US fr_FR - 1.0.11 + 1.0.13 Vincent Lopes-Vicente diff --git a/Controller/Front/CouponController.php b/Controller/Front/CouponController.php index ba80c51..665213a 100644 --- a/Controller/Front/CouponController.php +++ b/Controller/Front/CouponController.php @@ -4,6 +4,7 @@ namespace OpenApi\Controller\Front; +use Front\Front; use OpenApi\Model\Api\Coupon; use OpenApi\Model\Api\Error; use OpenApi\OpenApi; @@ -14,6 +15,7 @@ use OpenApi\Annotations as OA; use Symfony\Component\Routing\Annotation\Route; use Thelia\Core\Translation\Translator; +use Thelia\Exception\UnmatchableConditionException; use Thelia\Model\CouponQuery; /** @@ -71,9 +73,13 @@ public function submitCoupon(Request $request) throw new \Exception(Translator::getInstance()->trans('No coupons were found for this coupon code.', [], OpenApi::DOMAIN_NAME)); } - $event = new CouponConsumeEvent($openApiCoupon->getCode()); - $this->getDispatcher()->dispatch(TheliaEvents::COUPON_CONSUME, $event); - $openApiCoupon = $this->getModelFactory()->buildModel('Coupon', $theliaCoupon); + try { + $event = new CouponConsumeEvent($openApiCoupon->getCode()); + $this->getDispatcher()->dispatch(TheliaEvents::COUPON_CONSUME, $event); + $openApiCoupon = $this->getModelFactory()->buildModel('Coupon', $theliaCoupon); + } catch (UnmatchableConditionException $exception) { + throw new \Exception(Translator::getInstance()->trans('You should sign in or register to use this coupon.', [], OpenApi::DOMAIN_NAME)); + } return $this->jsonResponse($openApiCoupon); } diff --git a/I18n/fr_FR.php b/I18n/fr_FR.php index 9dab933..5191ffa 100755 --- a/I18n/fr_FR.php +++ b/I18n/fr_FR.php @@ -1,8 +1,9 @@ 'Cette valeur ne peut pas être vide', - 'No customer found for this email.' => 'Aucun compte client correspondant', + 'Content does not exist.' => 'Le contenu demandé n\'éxiste pas.', 'No coupons were found for this coupon code.' => 'Aucun code promo correspondant', - 'Content does not exist.' => "Le contenu demandé n'éxiste pas." + 'No customer found for this email.' => 'Aucun compte client correspondant', + 'This value should not be blank' => 'Cette valeur ne peut pas être vide', + 'You should sign in or register to use this coupon.' => 'Vous devez vous connecter ou vous inscrire pour utiliser ce coupon', ); diff --git a/Model/Api/Cart.php b/Model/Api/Cart.php index 6907902..b4c7fdf 100644 --- a/Model/Api/Cart.php +++ b/Model/Api/Cart.php @@ -252,7 +252,7 @@ public function getDiscount() */ public function setDiscount($discount) { - $this->discount = $discount; + $this->discount = (float)$discount; return $this; }