Answer the question
In order to leave comments, you need to log in
How is data transmitted and how does Bitrix 1c cart receive data?
Good day to all! Guys, please tell me how the basket works in 1C Bitrix.
I did not implement!
- How the AJAX request works
Here is the request code, the data from the form (Product ID and Quantity) are sent by the script
$(document).ready(function(){
$(".offer .add_tovar").click(function(){
var cnt = $(this).closest(".offer").find("input").val();
var id = $(this).closest(".offer").attr("data-id");
console.log(id);
console.log(cnt);
$.ajax({
type: "POST",
url: "/catalog/ajax_add.php",
data: ( {"quant" : cnt,"id" : id} ),
success: function(html){
window.location.reload();
//console.log(html);
//$('.header3 .korzina').html(html);
}
});
});
$(".offer .cnt_btn").click(function(){
console.log("!");
var val = $(this).closest(".offer").find("input").val();
val = Number(val);
if($(this).hasClass("minus")){if(val>=2){val--;}}else{val++;}
$(this).closest(".offer").find("input").val(val);
});
});
<? require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule('catalog');
CModule::IncludeModule("sale");
$quant = (int)$_POST['quant'];
$id = (int)$_POST['id'];
if($id>0 && $quant>0)
{
$prop = array();
$add = Add2BasketByProductID(
$id,
$quant,
array(),
array($prop)
);
echo "add=$add";
}
?>
Answer the question
In order to leave comments, you need to log in
The product ID and Quantity are transmitted, what happens to them next, can you explain?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question