<reponame>alexeisanko/bakery-shop<filename>bakery_shop/static/assets/js/basket.js<gh_stars>0$('.more__btn').click(function(){
    $(this).siblings('.count').css('display', 'flex');
    $(this).css('display', 'none');
    const addition_id = $(this).attr('id')
    const api = $(this).attr('api')
    $.ajax({
    type: 'POST',
    url: api,
    dataType: 'json',
    data: {
        'addition_id': addition_id
    },
    success: function (data) {
        $('#countaddition_'+data.id).text(data.quantity);
        $('.summary__price').text(data.total_price_order);
        $('.cashback__num').text(data.received_cashback);
        $('.basket__price').text(data.total_price_order);
    },
    });
})

function ChangeCount(element) {
    const dish_id = $(element).siblings('.count__text').attr('id')
    const api = $(element).attr('api')
    $.ajax({
        type: 'POST',
        url: api,
        dataType: 'json',
        data: {
            'dish_id': dish_id
        },
        success: function (data) {
            if (data.quantity == '0 шт') {
                const update = $('itemdelid_' + data.id).attr('update')
                $.ajax({
                    type: 'GET',
                    url: update,
                    success: function (){
                        location.reload();
                    }
                })
            } else {
                $('#countdish_'+data.id).text(data.quantity);
                $('#costdish_'+data.id).text(data.total_price_dishes);
            }
            $('.summary__price').text(data.total_price_order);
            $('.cashback__num').text(data.received_cashback);
            $('.basket__price').text(data.total_price_order);
        },
        });
};

function ChangeCountAddition(element) {
    const addition_id = $(element).siblings('.count__text').attr('id')
    const api = $(element).attr('api')
    $.ajax({
        type: 'POST',
        url: api,
        dataType: 'json',
        data: {
            'addition_id': addition_id
        },
        success: function (data) {
            if (data.quantity == '0 шт') {
                $('#btnaddition_' + data.id).css('display', 'flex');
                $('#btnaddition_' + data.id).siblings('.more__count').css('display', 'none');
            } else {
                $('#countaddition_'+data.id).text(data.quantity);
            }
            $('.summary__price').text(data.total_price_order);
            $('.cashback__num').text(data.received_cashback);
            $('.basket__price').text(data.total_price_order);
        },
        });
};