Answer the question
In order to leave comments, you need to log in
How to display products with discounts in the Bitrix cart using the API?
Good afternoon! the situation is as follows - when the goods in the cart are discounted depending on how many goods are in the cart and for what amount.
normal display of the basket and its contents
<?
// Выведем актуальную корзину для текущего пользователя
$arBasketItems = array();
$dbBasketItems = CSaleBasket::GetList(
array(
"NAME" => "ASC",
"ID" => "ASC"
),
array(
"FUSER_ID" => CSaleBasket::GetBasketUserID(),
"LID" => SITE_ID,
"ORDER_ID" => "NULL"
),
false,
false,
array("ID", "NAME", "CALLBACK_FUNC", "MODULE",
"PRODUCT_ID", "QUANTITY", "DELAY",
"CAN_BUY", "PRICE", "WEIGHT")
);
while ($arItems = $dbBasketItems->Fetch())
{
if (strlen($arItems["CALLBACK_FUNC"]) > 0)
{
CSaleBasket::UpdatePrice($arItems["ID"],
$arItems["NAME"],
$arItems["CALLBACK_FUNC"],
$arItems["MODULE"],
$arItems["PRODUCT_ID"],
$arItems["QUANTITY"]);
$arItems = CSaleBasket::GetByID($arItems["ID"]);
}
$arBasketItems[] = $arItems;
$name[] = $arItems["NAME"];
$price[] = round($arItems["PRICE"], 2);
}
?>
<?
$a = array($price);
$sum = array_sum($price);
echo $sum;?>
Answer the question
In order to leave comments, you need to log in
2 answers found: 1)
<?$fuserId = CSaleBasket::GetBasketUserID();
$dbBasketItems = CSaleBasket::GetList(
array("ID" => "ASC"),
array(
"FUSER_ID" => $fuserId,
"LID" => SITE_ID,
"ORDER_ID" => "NULL",
"DELAY"=>"N"
),
false,
false,
array(
"ID", "NAME", "CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "PRODUCT_PRICE_ID", "QUANTITY", "DELAY", "CAN_BUY",
"PRICE", "WEIGHT", "DETAIL_PAGE_URL", "NOTES", "CURRENCY", "VAT_RATE", "CATALOG_XML_ID",
"PRODUCT_XML_ID", "SUBSCRIBE", "DISCOUNT_PRICE", "PRODUCT_PROVIDER_CLASS", "TYPE", "SET_PARENT_ID"
)
);
while ($arBasketItems = $dbBasketItems->Fetch())
{
$allSum = ($arBasketItems["PRICE"] * $arBasketItems["QUANTITY"]);
$allWeight = ($arBasketItems["WEIGHT"] * $arBasketItems["QUANTITY"]);
$arResult[] = $arBasketItems;
}
$arOrder = array(
'SITE_ID' => SITE_ID,
'USER_ID' => $GLOBALS["USER"]->GetID(),
'ORDER_PRICE' => $allSum, // сумма всей корзины
'ORDER_WEIGHT' => $allWeight, // вес всей корзины
'BASKET_ITEMS' => $arResult // товары сами
);
$arOptions = array(
'COUNT_DISCOUNT_4_ALL_QUANTITY' => "Y",
);
$arErrors = array();
CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors);
echo $arOrder["ORDER_PRICE"];?>
<?$basket = \Bitrix\Sale\Basket::loadItemsForFUser(
\Bitrix\Sale\Fuser::getId(),
\Bitrix\Main\Context::getCurrent()->getSite()
); // текущая корзина
$fuser = new \Bitrix\Sale\Discount\Context\Fuser($basket->getFUserId(true));
$discounts = \Bitrix\Sale\Discount::buildFromBasket($basket, $fuser);
$discounts->calculate();
$result = $discounts->getApplyResult(true);
$prices = $result['PRICES']['BASKET']; // цены товаров с учетом скидки
print_r($prices);
foreach ($prices as $price):
//echo $price[PRICE];?><br>
<?
$summs[]=$price[PRICE];
?>
<?endforeach;?>
<?
$a = array($summs);
$summsss = array_sum($summs);
echo $summsss;?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question