A
A
animr2018-05-29 10:49:43
1C-Bitrix
animr, 2018-05-29 10:49:43

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);
  });
  
});


This is where the data is passed (ajax_add.php)

<? 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";
}
?>


And how does the Add2BasketByProductID() function work in general?

The product ID and Quantity are transmitted, what happens to them next, can you explain?
And how to track what data was received in $_POST, why var_dump( $_POST ) does not display anything?

Maybe the question for knowledgeable people is very stupid, but I'm just learning, don't scold me much!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mrPoison, 2018-05-29
@mrPoison

The product ID and Quantity are transmitted, what happens to them next, can you explain?

Find the Add2BasketByProductID function and see what happens next)
I can do it for you: bxapi.ru/src/?module_id=catalog&name=Add2BasketByP...
Question "how to trace?": the answer is var_dump, i.e. you yourself know.
If it is empty, then there is no data.)
It can be assumed that you do not expect to see it at the wrong moment. Your POST request is sent by ajax, => you need to look at var_dump in the response to this ajax.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question