-
-
Save ASDAFF/4d50cf7a10f44e1f13951d809696f08c to your computer and use it in GitHub Desktop.
Получаем купоны доступные пользователю
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
\Bitrix\Main\Loader::includeModule("sale"); | |
global $USER; | |
$userID = $USER->GetID(); | |
$userGroup = $USER->GetUserGroupArray(); | |
$resCoupons = \Bitrix\Sale\Internals\DiscountCouponTable::getList([ | |
'order' => ['DATE_CREATE' => 'desc'], | |
'filter' => [ | |
// Выводим только с описанием и пользователь в группе доступных | |
// Или купон конкретно данного пользователя | |
'LOGIC' => 'OR', | |
[ | |
'USER_ID' => $userID, | |
'CouponGroup.GROUP_ID' => $userGroup, | |
'!DESCRIPTION' => false, | |
'ACTIVE' => 'Y' | |
], | |
// или общие многоразовые купоны для всех | |
[ | |
'USER_ID' => false, | |
'MAX_USE' => 0, | |
'CouponGroup.GROUP_ID' => $userGroup, | |
'!DESCRIPTION' => false, | |
'ACTIVE' => 'Y' | |
] | |
], | |
'select' => [ | |
'ID', | |
'COUPON', | |
'DESCRIPTION', | |
'MAX_USE', | |
'DISCOUNT_ID' | |
], | |
// Проверяем может ли пользователь в данной группе пользоваться данным купоном | |
'runtime' => [ | |
(new \Bitrix\Main\ORM\Fields\Relations\Reference( | |
'CouponGroup', | |
\Bitrix\Sale\Internals\DiscountGroupTable::class, | |
\Bitrix\Main\ORM\Query\Join::on('this.DISCOUNT_ID', 'ref.DISCOUNT_ID'))) | |
->configureJoinType('inner') | |
] | |
]); | |
$arCoupons = []; | |
while($coupon = $resCoupons->fetch()){ | |
$arCoupons[$coupon['ID']] = $coupon; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment