Answer the question
In order to leave comments, you need to log in
Why are the functions not working?
The Mbasket class has such functions to increase and decrease the amount of goods in the basket
function Minus($iBlock, $iElement){ // ФУНКЦИЯ управляет количеством товара
$arrBasket = MBasket::GetBasketArray(); // Получить массив корзины
foreach($arrBasket['basket']['products'] as $key=>$val){
if($val['IBLOCK_ID'] == $iBlock and $val['ELEMENT_ID'] == $iElement){
print_r($val['COUNT']);
$val['COUNT']=$val['COUNT'] - 1;
print_r($val['COUNT']);
}
}
MBasket::SetBasketArray($arrBasket);
return true;
}
function Plus($iBlock, $iElement){ // ФУНКЦИЯ управляет количеством товара
$arrBasket = MBasket::GetBasketArray(); // Получить массив корзины
foreach($arrBasket['basket']['products'] as $key=>$val){
if($val['IBLOCK_ID'] == $iBlock and $val['ELEMENT_ID'] == $iElement){
$val['COUNT']=$val['COUNT'] + 1;
}
}
MBasket::SetBasketArray($arrBasket);
return true;
}
<button type="button" onclick="Minus(<?=$arProd['IBLOCK_ID']?>,<?=$arProd['ELEMENT_ID']?>)" class="btn btn-default"><i class="fa fa-minus" aria-hidden="true"></i></button> <button onclick="Plus(<?=$arProd['IBLOCK_ID']?>,<?=$arProd['ELEMENT_ID']?>)" type="button" class="btn btn-default"><i class="fa fa-plus" aria-hidden="true"></i></button>
<
function Minus(iBlockID, elementID) {
$.ajax({
type: "GET",
url: "_minus.php",
data: ({IBLOCK_ID : iBlockID, ELEMENT_ID : elementID}),
success: function(data){
$("#basket").load("/sect_basket.php");
$("#basket-page").load("/basket/index_basket-page.php");
},
error: function() {
alert("Ошибка. Обратитесь к администратору!");
}
});
}
function Plus(iBlockID, elementID) {
$.ajax({
type: "GET",
url: "_plus.php",
data: ({IBLOCK_ID : iBlockID,ELEMENT_ID : elementID }),
success: function(data){
$("#basket").load("/sect_basket.php");
$("#basket-page").load("/basket/index_basket-page.php");
},
error: function() {
alert("Ошибка. Обратитесь к администратору!");
}
});
}
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("top10_basket");
MBasket::Minus($_GET["IBLOCK_ID"],$_GET["ELEMENT_ID"]);
?>
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("top10_basket");
MBasket::Plus($_GET["IBLOCK_ID"],$_GET["ELEMENT_ID"]);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question