Answer the question
In order to leave comments, you need to log in
Bitrix API why the product is not added to the cart?
I send the quantity and ID of the goods through Ajax. Why is it not added to the cart? tell me plz. post comes.
$_POST['id'] - product id
<?require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
//$count = $_POST['count'];
//$id = $_POST['id'];
$add = $_POST['add'];
$mess = '';
$PRICE_ID = '1';
//CModule::IncludeModule('iblock');
CModule::IncludeModule('catalog');
//CModule::IncludeModule('currency');
CModule::IncludeModule("sale");
?>
<?
if (CModule::IncludeModule("catalog") && CModule::IncludeModule("sale")) {
// ADD TO CART
if ($_POST['id']) {
$count = ($_POST['count']) ? $_POST['count'] : 1;
$result = Add2BasketByProductID(
$_POST['id'],
$count
);
}
// UPDATE QUANTITY
if ($_POST['update'] == 'Y' && $_POST['id'] && $_POST['count']) {
$arFields = array(
"QUANTITY" => $_POST['count'],
);
CSaleBasket::Update($_POST['id'], $arFields);
}
// DELETE PRODUCT
if ($_POST['delete'] == 'Y' && $_POST['id']) {
CSaleBasket::Delete($_POST['id']);
}
}
else { echo "Не подключены модули"; }
AddMessage2Log("<br/><br/><pre>".print_r($result,true)."</pre><br/><br/>", "test");
echo $mess;
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");
?>
Answer the question
In order to leave comments, you need to log in
Didn't understand your writing. Add a product like this:
Bitrix\Main\Loader::includeModule("catalog");
$fields = [
'PRODUCT_ID' => 98
'QUANTITY' => 2
];
$r = Bitrix\Catalog\Product\Basket::addProduct($fields);
if (!$r->isSuccess()) {
var_dump($r->getErrorMessages());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question