Answer the question
In order to leave comments, you need to log in
How to add a product to cart via API?
Hello. I'm adding items to the cart. I use CSaleBasket::Add($arFields); . The product is added, but how to add the price of the product correctly? I do like 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" => "RUB",
"QUANTITY" => 1,
"LID" => 's1',
"DELAY" => "N",
"CAN_BUY" => "Y",
"NAME" => $arOffers["NAME"],
"MODULE" => "catalog",
"DETAIL_PAGE_URL" => $arOffers["DETAIL_PAGE_URL"]
);
CSaleBasket::Add($arFields);
Answer the question
In order to leave comments, you need to log in
You need to use the CSaleOrder::DoCalculateOrder method - this method will recalculate taking into account the discount at the moment the order is created.
But this is probably not needed here:
CModule::IncludeModule("product");
CModule::IncludeModule("iblock");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question