Skip to content

Commit

Permalink
Fix coupon error without message
Browse files Browse the repository at this point in the history
  • Loading branch information
lopes-vincent committed Apr 15, 2021
1 parent fa1e6c9 commit c409beb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.0.11</version>
<version>1.0.13</version>
<authors>
<author>
<name>Vincent Lopes-Vicente</name>
Expand Down
12 changes: 9 additions & 3 deletions Controller/Front/CouponController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace OpenApi\Controller\Front;


use Front\Front;
use OpenApi\Model\Api\Coupon;
use OpenApi\Model\Api\Error;
use OpenApi\OpenApi;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions I18n/fr_FR.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

return array(
'This value should not be blank' => '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',
);
2 changes: 1 addition & 1 deletion Model/Api/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function getDiscount()
*/
public function setDiscount($discount)
{
$this->discount = $discount;
$this->discount = (float)$discount;
return $this;
}

Expand Down

0 comments on commit c409beb

Please sign in to comment.