A
A
alexwprof2019-09-11 14:51:32
1C-Bitrix
alexwprof, 2019-09-11 14:51:32

How to change the number of items in the Bitrix cart?

There are items in the cart. Removing them from the cart is implemented, but changing the number of products cannot be done. I change using By analogy with deletion, using the default template as an example, I tracked where requests go when the quantity in the field changes. Requests go to: 1. /bitrix/components/bitrix/sale.basket.basket/ajax.php 2. /bitrix/components/bitrix/sale.basket.basket.line/ajax.php 3. /bitrix/components/bitrix /sale.products.gift.basket/ajax.php 4. /bitrix/components/bitrix/sale.products.gift.basket/ajax.php 4 requests in total. The second one changes the number of elements in the cart icon . The first one goes to the script that processes the calculation of the amount and returns the changed values. 3 and 4 - I do not touch requests.
<input type="number">
As a result, I send one request to the first address from the list with Ajax.
Json is returned, but the number in it is not changed
Ajax script:

$(document).on('click','#cart_to_quantity',function(){
        $.ajax({
            url: '/bitrix/components/bitrix/sale.basket.basket/ajax.php',
            type: 'POST',
            dataType: 'json',
            data: $(this).serialize(),
            success: function (result) {
                console.log(result);
                BX.onCustomEvent('OnBasketChange');
            }
        });

        return false;


    });

Submit a request form
<form id="cart_to_quantity">
  <input class="clic_item" type="number" name="basket[QUANTITY__<?=$item['ID']?>]" value="<?=$item['QUANTITY']?>">
<input type="hidden" name="basketAction" value="recalculateAjax"
 <input type="hidden" name="site_template_id" value=" bertonv">
  <input type="hidden" name="site_id" value="s1">
  <input type="hidden" name="sessid" value="<?=$my_func?>">
</form>

These requests were tracked when clicking on the increase or decrease of the product
basket[QUANTITY_407]: 12
lastAppliedDiscounts:
basketAction: recalculateAjax
via_ajax: Y
site_id: s1
site_template_id: bertonv
sessid: 3637c1980b2c166cedf20809a4a5d6c7
I don't send via_ajax: Y - otherwise the parameter is empty, lastDiscounts -Applied is empty , it makes no sense to send it. It is
necessary to record changes and return json already changed . Perhaps there is some way out, make a request using BX or something else. I tried to do it as in the default, but I couldn’t repeat it, it’s not clear how everything happens, there’s probably an easier way <input type="number">

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question