M
M
Maria Popova2017-04-28 13:50:31
PHP
Maria Popova, 2017-04-28 13:50:31

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

from the cart, I call them using the processing of a get request, and that is
<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>
<

these buttons call ajax and get function:
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("Ошибка. Обратитесь к администратору!");
    }
  });
      }

In files, calling functions already from the class:
<?

    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"]);
  

?>

But the quantity does not change, what's the matter? Tell me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrTimon, 2017-04-28
@MrTimon

When you change the quantity or then the array itself does not change. You need to either change these entries to these and or put the & sign in front of the $val declaration, it will turn out something like this:
Most likely the error is here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question