Дока<?php
// Include Sale module
Bitrix\Main\Loader::includeModule("sale");
// Query: Get all cart items for current user
$res = CSaleBasket::GetList(
array(),
array(
"FUSER_ID" => CSaleBasket::GetBasketUserID(),
"LID" => SITE_ID,
"ORDER_ID" => NULL,
"CAN_BUY" => "Y"
),
false,
false,
array(
"QUANTITY",
"BASE_PRICE",
"PRICE",
"DISCOUNT_PRICE"
)
);
$totalPrice = 0;
// Temp array with cart items
$arItems = array();
// Fetching query
while($arFields = $res->Fetch()){
// Check for base price
if(!isset($arFields['BASE_PRICE']) || (float)$arFields['BASE_PRICE'] <= 0){
$arFields['BASE_PRICE'] = $arFields['PRICE'] + $arFields['DISCOUNT_PRICE'];
}
// Calculate total price without discount
$totalPrice += $arFields["PRICE"] * $arFields["QUANTITY"];
$arItems[] = $arFields;
}
// Make array for discount calculation
$arOrder = array(
'SITE_ID' => SITE_ID,
'ORDER_PRICE' => $totalPrice,
'BASKET_ITEMS' => $arItems
);
// Checking for authorized user
if(is_object($GLOBALS["USER"])){
$arOrder['USER_ID'] = $GLOBALS["USER"]->GetID();
$arErrors = array();
// Calculate discount
CSaleDiscount::DoProcessOrder($arOrder, array(), $arErrors);
}
// All done!
echo $arOrder['ORDER_PRICE'];