Получить скидку / цена с учетом скидки bitrix
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
/** * Возвращает скидочную цены/цену с учетом скидки * @param boolean $type [true/false] * @return [int] [Если true возвращаем скидку, иначе возвращает сумму с учетом скидки] */ function getDiscountPrice($type = true) { $dbBasketItems = CSaleBasket::GetList( array("ID" => "ASC"), array( 'FUSER_ID' => CSaleBasket::GetBasketUserID(), 'LID' => SITE_ID, 'ORDER_ID' => 'NULL', ), false, false, array( 'ID', 'PRODUCT_ID', 'QUANTITY', 'PRICE', 'DISCOUNT_PRICE', 'WEIGHT', ) ); $allSum = 0; $allWeight = 0; $arItems = array(); while ($arBasketItems = $dbBasketItems->Fetch()) { $allSum += ($arItem["PRICE"] * $arItem["QUANTITY"]); $allWeight += ($arItem["WEIGHT"] * $arItem["QUANTITY"]); $arItems[] = $arBasketItems; } $arOrder = array( 'SITE_ID' => SITE_ID, 'USER_ID' => $GLOBALS["USER"]->GetID(), 'ORDER_PRICE' => $allSum, 'ORDER_WEIGHT' => $allWeight, 'BASKET_ITEMS' => $arItems, ); $arOptions = array( 'COUNT_DISCOUNT_4_ALL_QUANTITY' => 'Y', ); $arErrors = array(); CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors); $PRICE_ALL = 0; $DISCOUNT_PRICE_ALL = 0; $QUANTITY_ALL = 0; foreach ($arOrder["BASKET_ITEMS"] as $arOneItem) { $PRICE_ALL += $arOneItem["PRICE"] * $arOneItem["QUANTITY"]; $DISCOUNT_PRICE_ALL += $arOneItem["DISCOUNT_PRICE"] * $arOneItem["QUANTITY"]; $QUANTITY_ALL += $arOneItem['QUANTITY']; } $result['PRICE_ALL'] = $PRICE_ALL; // Цена у учетом скидки $result['DISCOUNT_PRICE_ALL'] = $DISCOUNT_PRICE_ALL; // Скидка $result['QUANTITY_ALL'] = $QUANTITY_ALL; // Кол-во товара return ($type) ? $result['DISCOUNT_PRICE_ALL'] : $result['PRICE_ALL']; } |