Z
Z
Zzpro2022-01-26 14:26:18
1C-Bitrix
Zzpro, 2022-01-26 14:26:18

How to catch entering a coupon in the bitrix cart?

Something I am completely confused in the documentation, I can’t catch the input of a specific coupon in the basket through init.php.

Tell me good people what events to catch

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Tkachev, 2022-01-26
@Real_Farmer

Sparvka on this event. It occurs before the end of the recalculation of the cost of the basket
https://dev.1c-bitrix.ru/api_d7/bitrix/sale/events...
/// checking users to apply the coupon WELCOME10
\Bitrix\Main\EventManager::getInstance()- >addEventHandler(
'sale', 'OnBeforeSaleOrderFinalAction', 'chkCupon'
);
function chkCupon(Bitrix\Main\Event $event) {
$groupId = 10;
$couponName = 'WELCOME10';
$order = $event->getParameter("ENTITY");
$arOrderVals = $order->getFields()->getValues();
$orderId = $arOrderVals['ID'];
$userId = $order->getUserId();
$discountData = $order->getDiscount()->
if (key($discountData['COUPON_LIST']) == $couponName) {
$arGroups = CUser::GetUserGroup($userId);
unset($arGroups[array_search($groupId, $arGroups)]);
CUser::SetUserGroup($userId, $arGroups);
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question