How to add a product to the cart via the API?

Hello. Make adding items to your cart. Use CSaleBasket::Add($arFields);. The product is added, but how to add the price of the goods? do this:
CModule::IncludeModule("sale");
CModule::IncludeModule("product");
CModule::IncludeModule("iblock");
 $arFilterOffers = array("IBLOCK_TYPE" => "catalog", 'ID' => $id);
 $rsOffers = CIBlockElement::GetList(array(),$arFilterOffers, false, false, array("NAME", "CATALOG_GROUP_2", "XML_ID", "EXTERNAL_ID", "DETAIL_PAGE_URL"));
 while($Offers = $rsOffers->GetNext()){
 $arOffers = $Offers;
}
 $dbPrices = CPrice::GetList(
array(),
 array("PRODUCT_ID" => $id,"CATALOG_GROUP_ID" => 2),
false,
false,
array()
);
 while($price = $dbPrices->Fetch()){
 $OffersCost = $price;
}

 $arFields = array(
 "PRODUCT_ID" => $arOffers["ID"],
 "PRODUCT_PRICE_ID" => $OffersCost["ID"],
 "PRICE" => $OffersCost["PRICE"],
 "CURRENCY" => "USD",
 "QUANTITY" => 1,
 "LID" => 's1'
 "DELAY" => "N",
 "CAN_BUY" => "Y",
 "NAME" => $arOffers["NAME"],
 "MODULE" => "catalog",
 "DETAIL_PAGE_URL" => $arOffers["DETAIL_PAGE_URL"]
);
 CSaleBasket::Add($arFields);

In field, $arFields["PRICE"] can insert any price. Can determine the price discount, and add it. But after adding product to cart, the price will be the one that I pointed out, but there will be discounts on merchandise. Like when you add product to the cart, add the discount? Discount created in Bitrix.
Item in cart, added through the API (the Price I give it 36900)
5c9e06d5ac087930389681.pngItem in cart, added using standard functionality from the catalog.
5c9e06df78b62334395584.png

PS. In the method CSaleBasket::Add($arFields); has a parameter PRODUCT_PROVIDER_CLASS, suggest how to use. I don't know how.
March 19th 20 at 09:11
2 answers
March 19th 20 at 09:13
You need to use the method CSaleOrder::DoCalculateOrder - this method will recalculate with the discount at the time of order creation.
But it is likely there is no need:
CModule::IncludeModule("product");
CModule::IncludeModule("iblock");
March 19th 20 at 09:15
Try
'PRODUCT_PROVIDER_CLASS' => 'CCatalogProductProvider'


As well as view in the direction D7

Find more questions by tags 1C-Bitrix