Skip to content
Code-Schnipsel Gruppen Projekte

feat: show errors direclty under the input

Zusammengeführt Michael Danielczok schlägt vor, 20-feat-ux-error-handling in next-2.x zu mergen.
5 Dateien
+ 156
64
Änderungen vergleichen
  • Nebeneinander
  • In der Reihe
Dateien
5
+ 27
38
<?php
/**
* This file contains package_quiqqer_coupons_ajax_delete
* This file contains package_quiqqer_coupons_ajax_frontend_redeem
*/
use QUI\ERP\Coupons\Handler;
@@ -13,6 +13,15 @@
* @param int $id - CouponCode ID
* @return bool - success
*/
/**
* Redeem a CouponCode
* @param string $code - coupon code
* @param string $orderHash - Order hash
*
* @throws QUI\Exception
* @throws QUI\ERP\Coupons\CouponCodeException
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_coupons_ajax_frontend_redeem',
function ($code, $orderHash) {
@@ -23,20 +32,14 @@ function ($code, $orderHash) {
} catch (QUI\ERP\Coupons\CouponCodeException $Exception) {
QUI\System\Log::writeDebugException($Exception);
QUI::getMessagesHandler()->addError($Exception->getMessage());
return false;
throw $Exception;
} catch (Exception $Exception) {
QUI\System\Log::writeException($Exception);
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'quiqqer/coupons',
'message.ajax.general_error'
)
);
return false;
throw new QUI\Exception([
'quiqqer/coupons',
'message.ajax.general_error'
]);
}
$Order = QUI\ERP\Order\Handler::getInstance()->getOrderByHash($orderHash);
@@ -49,40 +52,28 @@ function ($code, $orderHash) {
foreach ($discounts as $Discount) {
if (!DiscountEvents::isDiscountUsableWithQuantity($Discount, $productCount)) {
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'quiqqer/coupons',
'exception.CouponCode.discounts_invalid'
)
);
return false;
throw new QUI\Exception([
'quiqqer/coupons',
'exception.CouponCode.discounts_invalid'
]);
}
if ($Discount->getAttribute('scope') === QUI\ERP\Discount\Handler::DISCOUNT_SCOPE_GRAND_TOTAL) {
if (!DiscountEvents::isDiscountUsableWithPurchaseValue($Discount, $sum)) {
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'quiqqer/coupons',
'exception.CouponCode.discounts_invalid'
)
);
return false;
throw new QUI\Exception([
'quiqqer/coupons',
'exception.CouponCode.discounts_invalid'
]);
}
continue;
}
if (!DiscountEvents::isDiscountUsableWithPurchaseValue($Discount, $subSum)) {
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'quiqqer/coupons',
'exception.CouponCode.discounts_invalid'
)
);
return false;
throw new QUI\Exception([
'quiqqer/coupons',
'exception.CouponCode.discounts_invalid'
]);
}
}
@@ -104,8 +95,6 @@ function ($code, $orderHash) {
if ($Order instanceof QUI\ERP\Order\OrderInProcess) {
$CouponCode->addToOrder($Order);
}
return true;
},
['code', 'orderHash']
);