Answer the question
In order to leave comments, you need to log in
Why does the data on the basket either come or not?
Good,
I'm trying to get data on the quantity in the basket. Information that is, then no, but the goods regularly get into the basket.
What am I doing wrong? I think about the cache, but it should not be on the idea.
api for the current quantity in the cart
use Bitrix\Main\Loader;
Loader::includeModule('sale');
Loader::includeModule('catalog');
$cntBasketItems2 = CSaleBasket::GetList(
array(),
array(
"FUSER_ID" => CSaleBasket::GetBasketUserID(),
"LID" => "s5",
"ORDER_ID" => "NULL"
),
array()
);
<div id="" class="bx-basket bx-opener" style="display: contents;">
<a href="/dverimall/personal/cart/" class="basket-button">
<i class="basket-button__icon">
<span class="basket-button__count" style="" id="tt"><?echo $cntBasketItems2;?></span>
</i>
</a>
</div>
$.get('/bitrix/templates/dveri/ajax/count_basket.php').done(function(data){
data = $.parseJSON(data);
$('#tt').text(data);
});
use Bitrix\Main\Loader;
Loader::includeModule('sale');
Loader::includeModule('catalog');
$cntBasketItems = CSaleBasket::GetList(
array(),
array(
"FUSER_ID" => CSaleBasket::GetBasketUserID(),
"LID" => "s5",
"ORDER_ID" => "NULL"
),
array()
);
if ($cntBasketItems === 0) {
// Если в корзине нет товаров
}
echo json_encode($cntBasketItems);
Answer the question
In order to leave comments, you need to log in
Landmark - you have several ajax-s triggered. js is asynchronous. And even though you think that the first time works correctly for you, and the second one doesn’t work correctly - it’s not so, in one of the n-tsat attempts the first time will also work incorrectly
1st ajax
$.ajax({
url: '/bitrix/templates/dveri/ajax/basket.php'
$.get('/bitrix/templates/dveri/ajax/count_basket.php').done(function(data){
$.ajax({
//.............
async: false,
//.............
//.............
$("#send").on("click", async function () {
//.............
await $.ajax({
//.............
await $.get('/bitrix/templates/dveri/ajax/count_basket.php').done(function(data){
//.............
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question