- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/compatible/discountcompatibility.php
- Класс: BitrixSaleCompatibleDiscountCompatibility
- Вызов: DiscountCompatibility::calculateBasketItemDiscount
static function calculateBasketItemDiscount($code, $fields)
{
if (CSaleBasketHelper::isSetItem($fields))
return true;
if (empty(self::$basketDiscountList[$code]))
return true;
$itemData = array(
'MODULE_ID' => $fields['MODULE'],
'PRODUCT_ID' => $fields['PRODUCT_ID'],
'BASKET_ID' => $code
);
foreach (self::$basketDiscountList[$code] as $index => $discount)
{
$discountResult = self::convertDiscount($discount);
if (!$discountResult->isSuccess())
return false;
$orderDiscountId = $discountResult->getId();
$discountData = $discountResult->getData();
$orderCouponId = '';
self::$basketDiscountList[$code][$index]['ORDER_DISCOUNT_ID'] = $orderDiscountId;
if ($discountData['USE_COUPONS'] == 'Y')
{
if (empty($discount['COUPON']))
return false;
$couponResult = self::convertCoupon($discount['COUPON'], $orderDiscountId);
if (!$couponResult->isSuccess())
return false;
$orderCouponId = $couponResult->getId();
SaleDiscountCouponsManager::setApplyByProduct($itemData, array($orderCouponId));
unset($couponResult);
}
unset($discountData, $discountResult);
if (!isset(self::$discountResult['BASKET'][$code]))
self::$discountResult['BASKET'][$code] = array();
self::$discountResult['BASKET'][$code][$index] = array(
'DISCOUNT_ID' => $orderDiscountId,
'COUPON_ID' => $orderCouponId,
'RESULT' => array(
'APPLY' => 'Y',
'DESCR' => false,
'DESCR_DATA' => false
)
);
$orderApplication = (
!empty(self::$discountsCache[$orderDiscountId]['APPLICATION'])
? self::$discountsCache[$orderDiscountId]['APPLICATION']
: null
);
if (!empty($orderApplication))
{
$fields['DISCOUNT_RESULT'] = (
!empty(self::$discountsCache[$orderDiscountId]['ACTIONS_DESCR_DATA'])
? self::$discountsCache[$orderDiscountId]['ACTIONS_DESCR_DATA']
: false
);
$applyProduct = null;
eval('$applyProduct='.$orderApplication.';');
if (is_callable($applyProduct))
$applyProduct($fields);
unset($applyProduct);
if (!empty($fields['DISCOUNT_RESULT']))
{
self::$discountResult['BASKET'][$code][$index]['RESULT']['DESCR_DATA'] = $fields['DISCOUNT_RESULT']['BASKET'];
self::$discountResult['BASKET'][$code][$index]['RESULT']['DESCR'] = self::formatDescription($fields['DISCOUNT_RESULT']);
}
unset($fields['DISCOUNT_RESULT']);
}
unset($orderApplication);
}
unset($discount, $index);
return true;
}