aldtimofeev
@aldtimofeev
front-end / html-верстальщик

Почему перестала срабатывать кнопка «купить» у товара на opencart?

Устанавливаю свою вёрстку на opencart. Потихоньку меняю дефолтный шаблон в header.tpl. Изначально кнопка "купить" работала, но в какой-то момент перестала, не успел заметить из-за чего. В консоли пишет:
Uncaught TypeError: $.ajax is not a function
at Object.add (common.js:151)
at HTMLButtonElement.onclick (index.php?route=common/home:319)


Сама кнопка такая:
<button type="button" onclick="cart.add('40');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">Купить</span></button>


В common.js на строке 151:
$.ajax({
			url: 'index.php?route=checkout/cart/add',
			type: 'post',
			data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
			dataType: 'json',
			beforeSend: function() {
				$('#cart > button').button('loading');
			},
			complete: function() {
				$('#cart > button').button('reset');
			},
			success: function(json) {
				$('.alert, .text-danger').remove();

				if (json['redirect']) {
					location = json['redirect'];
				}

				if (json['success']) {
					$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

					// Need to set timeout otherwise it wont update the total
					setTimeout(function () {
						$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
					}, 100);

					$('html, body').animate({ scrollTop: 0 }, 'slow');

					$('#cart > ul').load('index.php?route=common/cart/info ul li');
				}
			},
			error: function(xhr, ajaxOptions, thrownError) {
				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
			}
		});
  • Вопрос задан
  • 1287 просмотров
Решения вопроса 1
freislot
@freislot
Frontend-разработчик
что-то мне подсказывает что у вас не подключена jQuery библиотека
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы