Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Получить скидки товара, включая правила работы с корзиной
$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;
@Scarboroid

This comment has been minimized.

Copy link

@Scarboroid Scarboroid commented Nov 28, 2017

while ($arBasketItems = $dbBasketItems->Fetch())
{   
    $allSum += ($arItem["PRICE"] * $arItem["QUANTITY"]);
    $allWeight += ($arItem["WEIGHT"] * $arItem["QUANTITY"]);
    $arItems[] = $arBasketItems;
} 

Неизвестно откуда взялась переменная $arItem. Наверно она должна быть вместо $arBasketItems.

@nikolays93

This comment has been minimized.

Copy link

@nikolays93 nikolays93 commented Nov 16, 2018

Не считает Оптовую скидку :(

@EASemashko

This comment has been minimized.

Copy link

@EASemashko EASemashko commented Sep 10, 2020

Не считает наценку из правил корзины

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment