Подскажите как исправить ошибку. Хочу добавить возможность изменять количество товаров после добавления в корзину (фото прикреплено).
В файл cart.twig добавлена разметка:
<td>
<div class="cart_quantity_button">
<a style="font-size:20px; cursor:pointer" class="cart_quantity_down" data-key="{{ product.cart_id }}">-</a>
<input class="cart_quantity_input" type="text" name="quantity" value="{{ product.quantity }}" autocomplete="off" size="2" readonly>
<a style="font-size:20px; cursor:pointer" class="cart_quantity_up" data-key="{{ product.cart_id }}">+</a>
</div>
</td>
И в файл common.js добавлено функцию и слушатели:
function updateCart(key, quantity) {
$.ajax({
url: 'index.php?route=checkout/cart/edit',
type: 'post',
data: 'key=' + key + '&quantity=' + (typeof (quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
beforeSend: function () {
$('#cart > button').button('loading');
},
complete: function () {
$('#cart > button').button('reset');
},
success: function (data) {
// Обновление количества товаров в корзине
$('#cart-total').html(data['total']);
// Обновление содержимого корзины
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
location = 'index.php?route=checkout/cart';
} else {
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
},
error: function (jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect. Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found (404).');
} else if (jqXHR.status == 500) {
alert('Internal Server Error (500).');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error. ' + jqXHR.responseText);
}
}
});
}
$('.cart_quantity_up').on('click', function () {
var key = $(this).data('key');
var quantity = $(this).parent().find('.cart_quantity_input').val();
quantity++;
$(this).parent().find('.cart_quantity_input').val(quantity);
updateCart(key, quantity);
});
$('.cart_quantity_down').on('click', function () {
var key = $(this).data('key');
var quantity = $(this).parent().find('.cart_quantity_input').val();
if (quantity > 1) {
quantity--;
$(this).parent().find('.cart_quantity_input').val(quantity);
updateCart(key, quantity);
}
});
При нажатии на +/- срабатывает событие, количество увеличивается/уменьшается и вызывается функция updateCart() которая должна обновить содержимое корзины. Но метод success не выполняется, так как получаю ошибку "parsererror". (фото прикреплено)