Ну как-то так:
use \Bitrix\Sale;
use Bitrix\Main\Context,
Bitrix\Currency\CurrencyManager,
Bitrix\Sale\Order,
Bitrix\Sale\Basket;
Bitrix\Main\Loader::includeModule("sale");
Bitrix\Main\Loader::includeModule("catalog");
Bitrix\Main\Loader::includeModule('iblock');
$basket = Sale\Basket::loadItemsForFUser(Sale\Fuser::getId(), Bitrix\Main\Context::getCurrent()->getSite());
$fields = [
[
'PRODUCT_ID' => 7050,
'QUANTITY' => 22
],
[
'PRODUCT_ID' => 7130,
'QUANTITY' => 1
],
];
foreach($fields as $field) {
$res = CIBlockElement::GetByID($ITEM['PRODUCT_ID']);
if($PRODUCT_INFO = $res->GetNext()){
if ($item = $basket->getExistsItem('basket', $field['PRODUCT_ID']))
{
$item->setField('QUANTITY' , $field['QUANTITY']);
}
else
{
$PRICE_INFO = CPrice::GetBasePrice($field['PRODUCT_ID']);
$dbPrice = CPrice::GetList(
array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC", "SORT" => "ASC"),
array("PRODUCT_ID" => $field['PRODUCT_ID']),
false,
false,
array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO")
);
while ($arPrice = $dbPrice->Fetch())
{
$arDiscounts = CCatalogDiscount::GetDiscountByPrice(
$arPrice["ID"],
1,
"N",
SITE_ID
);
$discountPrice = CCatalogProduct::CountPriceWithDiscount(
$arPrice["PRICE"],
$arPrice["CURRENCY"],
$arDiscounts
);
}
$item = $basket->createItem('basket', $field['PRODUCT_ID']);
$item->setFields(array(
'QUANTITY' => 1,
'NAME' => $PRODUCT_INFO['NAME'],
'PRICE' => $discountPrice,
'CURRENCY' => Bitrix\Currency\CurrencyManager::getBaseCurrency(),
'LID' => Bitrix\Main\Context::getCurrent()->getSite(),
'PRODUCT_PROVIDER_CLASS' => 'CCatalogProductProvider',
));
}
$basket->save();
}
}