Skip to content
Code-Schnipsel Gruppen Projekte

Revisionen vergleichen

Änderungen werden so angezeigt, als ob die Quellrevision mit der Zielrevision zusammengeführt würde. Erfahre mehr über den Vergleich von Revisionen.

Quelle

Zielprojekt auswählen
No results found

Ziel

Zielprojekt auswählen
  • quiqqer/coupons
1 Ergebnis
Änderungen anzeigen
Commits auf Quelle (3)
<?php <?php
/** /**
* This file contains package_quiqqer_coupons_ajax_delete * This file contains package_quiqqer_coupons_ajax_frontend_redeem
*/ */
use QUI\ERP\Coupons\Handler; use QUI\ERP\Coupons\Handler;
...@@ -13,6 +13,15 @@ ...@@ -13,6 +13,15 @@
* @param int $id - CouponCode ID * @param int $id - CouponCode ID
* @return bool - success * @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( QUI::$Ajax->registerFunction(
'package_quiqqer_coupons_ajax_frontend_redeem', 'package_quiqqer_coupons_ajax_frontend_redeem',
function ($code, $orderHash) { function ($code, $orderHash) {
...@@ -23,20 +32,14 @@ function ($code, $orderHash) { ...@@ -23,20 +32,14 @@ function ($code, $orderHash) {
} catch (QUI\ERP\Coupons\CouponCodeException $Exception) { } catch (QUI\ERP\Coupons\CouponCodeException $Exception) {
QUI\System\Log::writeDebugException($Exception); QUI\System\Log::writeDebugException($Exception);
QUI::getMessagesHandler()->addError($Exception->getMessage()); throw $Exception;
return false;
} catch (Exception $Exception) { } catch (Exception $Exception) {
QUI\System\Log::writeException($Exception); QUI\System\Log::writeException($Exception);
QUI::getMessagesHandler()->addError( throw new QUI\Exception([
QUI::getLocale()->get( 'quiqqer/coupons',
'quiqqer/coupons', 'message.ajax.general_error'
'message.ajax.general_error' ]);
)
);
return false;
} }
$Order = QUI\ERP\Order\Handler::getInstance()->getOrderByHash($orderHash); $Order = QUI\ERP\Order\Handler::getInstance()->getOrderByHash($orderHash);
...@@ -49,40 +52,28 @@ function ($code, $orderHash) { ...@@ -49,40 +52,28 @@ function ($code, $orderHash) {
foreach ($discounts as $Discount) { foreach ($discounts as $Discount) {
if (!DiscountEvents::isDiscountUsableWithQuantity($Discount, $productCount)) { if (!DiscountEvents::isDiscountUsableWithQuantity($Discount, $productCount)) {
QUI::getMessagesHandler()->addError( throw new QUI\Exception([
QUI::getLocale()->get( 'quiqqer/coupons',
'quiqqer/coupons', 'exception.CouponCode.discounts_invalid'
'exception.CouponCode.discounts_invalid' ]);
)
);
return false;
} }
if ($Discount->getAttribute('scope') === QUI\ERP\Discount\Handler::DISCOUNT_SCOPE_GRAND_TOTAL) { if ($Discount->getAttribute('scope') === QUI\ERP\Discount\Handler::DISCOUNT_SCOPE_GRAND_TOTAL) {
if (!DiscountEvents::isDiscountUsableWithPurchaseValue($Discount, $sum)) { if (!DiscountEvents::isDiscountUsableWithPurchaseValue($Discount, $sum)) {
QUI::getMessagesHandler()->addError( throw new QUI\Exception([
QUI::getLocale()->get( 'quiqqer/coupons',
'quiqqer/coupons', 'exception.CouponCode.discounts_invalid'
'exception.CouponCode.discounts_invalid' ]);
)
);
return false;
} }
continue; continue;
} }
if (!DiscountEvents::isDiscountUsableWithPurchaseValue($Discount, $subSum)) { if (!DiscountEvents::isDiscountUsableWithPurchaseValue($Discount, $subSum)) {
QUI::getMessagesHandler()->addError( throw new QUI\Exception([
QUI::getLocale()->get( 'quiqqer/coupons',
'quiqqer/coupons', 'exception.CouponCode.discounts_invalid'
'exception.CouponCode.discounts_invalid' ]);
)
);
return false;
} }
} }
...@@ -104,8 +95,6 @@ function ($code, $orderHash) { ...@@ -104,8 +95,6 @@ function ($code, $orderHash) {
if ($Order instanceof QUI\ERP\Order\OrderInProcess) { if ($Order instanceof QUI\ERP\Order\OrderInProcess) {
$CouponCode->addToOrder($Order); $CouponCode->addToOrder($Order);
} }
return true;
}, },
['code', 'orderHash'] ['code', 'orderHash']
); );
...@@ -32,7 +32,8 @@ define('package/quiqqer/coupons/bin/frontend/classes/CouponCodes', [ ...@@ -32,7 +32,8 @@ define('package/quiqqer/coupons/bin/frontend/classes/CouponCodes', [
'package': pkg, 'package': pkg,
code: code, code: code,
orderHash: orderHash, orderHash: orderHash,
onError: reject onError: reject,
showError: false // disable quiqqer message in frontend
}); });
}); });
} }
......
.quiqqer-coupons-couponcodeinput { .quiqqer-coupons-couponcodeinput {
--_qui-error-text-color: var(--qui-error-text-color, red);
--_qui-error-input-border-color: var(--qui-error-input-border-color, red);
container-type: inline-size; container-type: inline-size;
} }
...@@ -14,13 +16,28 @@ ...@@ -14,13 +16,28 @@
} }
.quiqqer-coupons-couponcodeinput-input { .quiqqer-coupons-couponcodeinput-input {
min-width: min(250px, 100cqi); min-width: min(200px, 100cqi);
} }
.quiqqer-coupons-remove { .quiqqer-coupons-remove {
margin-left: 1rem; margin-left: 1rem;
} }
/* error handling */
input.quiqqer-coupons-couponcodeinput-input[data-invalid] {
border-color: var(--_qui-error-input-border-color)
}
.quiqqer-coupons-couponcodeinput__errorMsg:not([data-show]) {
display: none;
}
:where(.quiqqer-coupons-couponcodeinput__errorMsg[data-show]) {
font-size: 0.875rem;
color: var(--_qui-error-text-color);
margin-top: 0.25rem;
}
/** /**
* Simple Checkout * Simple Checkout
*/ */
......
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
</label> </label>
<div class="quiqqer-coupons-couponcodeinput__inputGroup"> <div class="quiqqer-coupons-couponcodeinput__inputGroup">
<input class="quiqqer-coupons-couponcodeinput-input" <input class="quiqqer-coupons-couponcodeinput-input"
type="text" name="code-input" id="code-input" data-name="code-input" type="text" name="code-input" id="code-input" data-ref="code-input"
placeholder="{{labelInputPlaceholder}}" placeholder="{{labelInputPlaceholder}}"
autocomplete="off"
/> />
<button class="quiqqer-coupons-couponcodeinput-btn btn btn-success" data-name="submit-coupon-code"> <button class="quiqqer-coupons-couponcodeinput-btn btn btn-success" data-ref="submit-coupon-code">
{{submitBtnText}} {{submitBtnText}}
</button> </button>
</div> </div>
<div class="quiqqer-coupons-couponcodeinput__errorMsg" data-ref="errorMsg"></div>
</div> </div>
\ No newline at end of file
...@@ -31,16 +31,19 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [ ...@@ -31,16 +31,19 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [
Type: 'package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', Type: 'package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput',
Binds: [ Binds: [
'$submit' '$submit',
'handleError'
], ],
initialize: function(options) { initialize: function(options) {
this.parent(options); this.parent(options);
this.$Input = null; this.$Input = null;
this.$ErrorMsgContainer = null;
this.Loader = new QUILoader(); this.Loader = new QUILoader();
this.$running = false; this.$running = false;
this.addEvents({ this.addEvents({
onInject: this.$onInject onInject: this.$onInject
}); });
...@@ -65,17 +68,42 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [ ...@@ -65,17 +68,42 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [
submitBtnText: QUILocale.get(lg, lgPrefix + 'submitBtnText') submitBtnText: QUILocale.get(lg, lgPrefix + 'submitBtnText')
})); }));
this.$ErrorMsgContainer = this.$Elm.querySelector('[data-ref="errorMsg"]');
this.Loader.inject(this.$Elm); this.Loader.inject(this.$Elm);
this.$Input = this.$Elm.getElement('input[data-name="code-input"]'); this.$Input = this.$Elm.getElement('[data-ref="code-input"]');
let timeoutId = null;
let previousValue = '';
let currentValue = '';
const keyUpFunc = function(event ){
currentValue = self.$Input.value.trim();
this.$Input.addEvent('keyup', function(event) {
if (event.code === 13) { if (event.code === 13) {
clearTimeout(timeoutId);
previousValue = currentValue;
self.$submit(); self.$submit();
} else {
clearTimeout(timeoutId);
timeoutId = setTimeout(function() {
if (
(currentValue !== previousValue || currentValue === '') &&
self.$ErrorMsgContainer.getAttribute('data-show')
) {
self.hideErrorMessage();
self.resetInvalidInput();
}
previousValue = currentValue;
}, 400);
} }
}); };
this.$Input.addEvent('keyup', keyUpFunc);
this.$Elm.getElement('[data-name="submit-coupon-code"]').addEvent('click', function(event) { this.$Elm.getElement('[data-ref="submit-coupon-code"]').addEvent('click', function(event) {
event.stop(); event.stop();
self.$submit(); self.$submit();
}); });
...@@ -153,12 +181,7 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [ ...@@ -153,12 +181,7 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [
this.$running = false; this.$running = false;
this.Loader.hide(); this.Loader.hide();
}).catch((err) => { }).catch(self.handleError);
console.error(err);
this.$running = false;
this.Loader.hide();
});
}, { }, {
'package': 'quiqqer/order-simple-checkout', 'package': 'quiqqer/order-simple-checkout',
orderHash: orderHash orderHash: orderHash
...@@ -184,7 +207,7 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [ ...@@ -184,7 +207,7 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [
'package': 'quiqqer/order' 'package': 'quiqqer/order'
}); });
}); });
}); }).catch(self.handleError);
}, { }, {
'package': 'quiqqer/order' 'package': 'quiqqer/order'
}); });
...@@ -197,18 +220,15 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [ ...@@ -197,18 +220,15 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [
OrderProcess.Loader.show(); OrderProcess.Loader.show();
OrderProcess.getOrder().then(function(orderHash) { OrderProcess.getOrder().then(function(orderHash) {
return CouponCodes.addCouponCodeToBasket(code, orderHash); CouponCodes.addCouponCodeToBasket(code, orderHash).then(() => {
}).then(function(redeemed) { self.$running = false;
self.$running = false;
if (redeemed === false) { self.$addCouponCodeToSession(code).then(function() {
OrderProcess.reload();
});
}).catch((err) => {
OrderProcess.Loader.hide(); OrderProcess.Loader.hide();
self.Loader.hide(); self.handleError(err);
return;
}
self.$addCouponCodeToSession(code).then(function() {
OrderProcess.reload();
}); });
}); });
}, },
...@@ -285,6 +305,69 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [ ...@@ -285,6 +305,69 @@ define('package/quiqqer/coupons/bin/frontend/controls/CouponCodeInput', [
}); });
}); });
}); });
},
/**
* Show error message container
* @param msg
*/
showErrorMessage: function( msg) {
if (!msg) {
console.log("no error message provided");
return;
}
if (!this.$ErrorMsgContainer) {
return;
}
this.$ErrorMsgContainer.set('html', msg);
this.$ErrorMsgContainer.setAttribute('data-show', '1');
},
/**
* Hide error message container
*/
hideErrorMessage: function() {
if (!this.$ErrorMsgContainer) {
return;
}
this.$ErrorMsgContainer.removeAttribute('data-show');
},
/**
* Set data-invalid attribute to the input
*/
highlightInvalidInput: function() {
this.$Input.setAttribute('data-invalid', '1');
},
/**
* Remove data-invalid attribute from the input
*/
resetInvalidInput: function() {
this.$Input.removeAttribute('data-invalid');
},
/**
* Handle error message (show error message and highlight invalid input)
*
* @param err
*/
handleError: function(err) {
console.error(err);
if (err.options !== undefined && err.options.message) {
const msg = err.options.message;
this.showErrorMessage(msg);
this.highlightInvalidInput();
}
this.$running = false;
this.Loader.hide();
} }
}); });
}); });