Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save YuriDan/7c4a75093eaf3939bd6a to your computer and use it in GitHub Desktop.
Save YuriDan/7c4a75093eaf3939bd6a to your computer and use it in GitHub Desktop.
Получить скидки товара, включая правила работы с корзиной
$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
Copy link

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

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

@sukhikh18
Copy link

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

@EASemashko
Copy link

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

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