1
0
Fork 0
mirror of synced 2025-04-20 01:21:01 +00:00

add error message

This commit is contained in:
Sergey Chazov 2020-10-07 12:04:28 +03:00
parent c1fed4d606
commit ac63557af5
5 changed files with 51 additions and 19 deletions

View file

@ -1,18 +1,31 @@
$(document).ready(function() {
let intervalId;
function make_ajax_request(e) {
function make_ajax_request() {
setTimeout(function() {
$('#bonus-msg').html('Сколько бонусов потратить?');
BX.Sale.OrderAjaxComponent.sendRequest();
console.log('test');
}, 2000);
}, 1005);
}
$('#bonus-input')
.on('keydown', function() {
$('#bonus-msg').html('Обработка информации');
clearInterval(intervalId);
})
$('#bonus-input').keyup(function(){
let availableBonuses = Number.parseInt($('#available-bonus-input').val());
let inputBonuses = Number.parseInt($('#bonus-input').val());
if (inputBonuses > availableBonuses) {
$('#bonus-input-error').html('Вы не можете потратить более ' + availableBonuses + ' бонусов');
}else{
$('#bonus-input-error').html(null);
}
});
$('#bonus-input').on('keydown',
_.debounce(make_ajax_request, 1300));
_.debounce(make_ajax_request, 1000));
});

View file

@ -1,3 +1,6 @@
#bonus-input-error{
color: #a94442;
}
.bx-soa { padding-bottom:20px;}
.bx-soa-section {
border-radius: 2px;

View file

@ -436,11 +436,12 @@ if (strlen($request->get('ORDER_ID')) > 0) {
<div class="bx-soa-section-content container-fluid" id="bx-soa-intaro-content">
<div class="bx-soa-coupon">
Сколько бонусов потратить:
<div id="bonus-msg">Сколько бонусов потратить?</div>
<div class="bx-soa-coupon-block">
<div class="bx-input">
<input name='bonus-input' class="form-control" type="number" max="<?=$arResult['AVAILABLE_BONUSES']?>" id='bonus-input'>
<input name="available-bonuses" class="form-control" type="hidden" id='bonus-input' value="<?=$arResult['AVAILABLE_BONUSES']?>">
<input name="available-bonuses" class="form-control" type="hidden" id='available-bonus-input' value="<?=$arResult['AVAILABLE_BONUSES']?>">
<div id="bonus-input-error"></div>
</div>
</div>
<div>Всего бонусов: <label id="total-bonuses-count"><?=$arResult['TOTAL_BONUSES_COUNT']?></label></div>

View file

@ -65,14 +65,6 @@ class EventsHandlers
AddMessage2Log('OnSaleStatusOrderChangeHandler work! ' . $event->getDebugInfo());
}
/**
* @param \Bitrix\Main\Event $event
*/
public function OnSaleOrderSavedHandler(Event $event): void
{
AddMessage2Log('OnSaleOrderSavedHandler work! ' . $event->getDebugInfo());
}
/**
* @param \Bitrix\Main\Event $event
*/
@ -102,7 +94,14 @@ class EventsHandlers
return $arResult;
}
public function OnSaleComponentOrderResultPreparedHandler($order, $arUserResult, HttpRequest $request, $arParams, &$arResult)
/**
* @param $order
* @param $arUserResult
* @param \Bitrix\Main\HttpRequest $request
* @param $arParams
* @param $arResult
*/
public function OnSaleComponentOrderResultPreparedHandler($order, $arUserResult, HttpRequest $request, $arParams, &$arResult): void
{
if (ConfigProvider::getLoyaltyProgramStatus() === 'Y') {
$isBonusError = false;
@ -120,10 +119,26 @@ class EventsHandlers
&& $isBonusError === false
&& $arResult['JS_DATA']['TOTAL']['ORDER_TOTAL_PRICE'] > $bonusInput
) {
$arResult['JS_DATA']['TOTAL']['ORDER_TOTAL_PRICE'] = $arResult['JS_DATA']['TOTAL']['ORDER_TOTAL_PRICE'] - $bonusInput;
$arResult['JS_DATA']['TOTAL']['ORDER_TOTAL_PRICE_FORMATED'] = number_format($arResult['JS_DATA']['TOTAL']['ORDER_TOTAL_PRICE'], 0, ',', ' ' );
$arResult['JS_DATA']['TOTAL']['BONUS_PAYMENT'] = $bonusInput;
$arResult['JS_DATA']['TOTAL']['ORDER_TOTAL_PRICE'] -= $bonusInput;
$arResult['JS_DATA']['TOTAL']['ORDER_TOTAL_PRICE_FORMATED'] = number_format($arResult['JS_DATA']['TOTAL']['ORDER_TOTAL_PRICE'], 0, ',', ' ');
$arResult['JS_DATA']['TOTAL']['BONUS_PAYMENT'] = $bonusInput;
}
}
}
/**
* @param \Bitrix\Main\Event $event
*/
public function OnSaleOrderSavedHandler(Event $event): void
{
$order = $event->getParameter("ENTITY");
$oldValues = $event->getParameter("VALUES");
$isNew = $event->getParameter("IS_NEW");
if ($isNew)
{
$sum = $order->getPrice();
}
}
}