Перейти до вмісту
Пошук в
  • Детальніше...
Шукати результати, які ...
Шукати результати в ...

Не работает кнопка "купить"


Recommended Posts

Добрый день. При переносе блока с кнопками "купить" и "быстрый заказ"  немного выше в карточке товара перестаёт работать кнопка "купить". При этом кнопка "быстрый заказ" работает. Подскажите где искать решение.

Сайт sfera.by

Надіслати
Поділитися на інших сайтах


 

  В 21.12.2022 в 19:13, esculapra сказав:

так воспроизведите непонятку - сейчас все работает

Expand  

Просто сейчас вернул всё как было до этого.

Сейчас сделаю опять.

Надіслати
Поділитися на інших сайтах


  В 21.12.2022 в 19:22, five сказав:
Expand  

 

Кнопка работает, данных только для нее нет тк нет селектора #product на странице

Надіслати
Поділитися на інших сайтах

попробуй изменить код

<button type="button" id="button-cart" data-loading-text="Загрузка..." class="us-product-btn us-product-btn-active" onClick="addCart()">В корзину</button>
это
<script>
$('#button-cart').on('click', function() {
    $.ajax({
        url: 'index.php?route=checkout/cart/add',
        type: 'post',
        data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
        dataType: 'json',
        cache: false,
        beforeSend: function() {
            $('#button-cart').button('loading');
        },
        complete: function() {
            $('#button-cart').button('reset');
        },
        success: function(json) {
            $('.alert-dismissible, .text-danger').remove();
            $('.form-group').removeClass('has-error');

            if (json['error']) {
                if (json['error']['option']) {
                    let errorOption = '';
                    for (i in json['error']['option']) {
                        var element = $('#input-option' + i.replace('_', '-'));

                        if (element.parent().hasClass('input-group')) {
                            element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                        } else {
                            element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                        }
                        errorOption += '<div class="alert-text-item">' + json['error']['option'][i] + '</div>';
                    }
                    usNotify('danger', errorOption);
                }

                if (json['error']['error_warning']) {
                    usNotify('danger', json['error']['error_warning']);
                }

                if (json['error']['recurring']) {
                    $('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
                }

                // Highlight any found errors
                $('.text-danger').parent().addClass('has-error');
            }

            if (json['success']) {
                if (json['isPopup']) {
                    octPopupCart();
                } else {
                    usNotify('success', json['success']);
                }

                if(typeof octYandexEcommerce == 'function') {
                    octYandexEcommerce(json);
                }

                // Need to set timeout otherwise it wont update the total
                setTimeout(function () {
                    $('#oct-cart-quantity, .header-cart-index, #mobile_cart_index').html(json['total_products']);
                    $('.us-cart-text').html(json['total_amount']);
                }, 100);
            }
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
    });
});
</script>

на это
<script>
function addCart() {
alert('bla-bla-bla');// ну шоб бачити шо все норм.
    $.ajax({
        url: 'index.php?route=checkout/cart/add',
        type: 'post',
        data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
        dataType: 'json',
        cache: false,
        beforeSend: function() {
            $('#button-cart').button('loading');
        },
        complete: function() {
            $('#button-cart').button('reset');
        },
        success: function(json) {
            $('.alert-dismissible, .text-danger').remove();
            $('.form-group').removeClass('has-error');

            if (json['error']) {
                if (json['error']['option']) {
                    let errorOption = '';
                    for (i in json['error']['option']) {
                        var element = $('#input-option' + i.replace('_', '-'));

                        if (element.parent().hasClass('input-group')) {
                            element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                        } else {
                            element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                        }
                        errorOption += '<div class="alert-text-item">' + json['error']['option'][i] + '</div>';
                    }
                    usNotify('danger', errorOption);
                }

                if (json['error']['error_warning']) {
                    usNotify('danger', json['error']['error_warning']);
                }

                if (json['error']['recurring']) {
                    $('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
                }

                // Highlight any found errors
                $('.text-danger').parent().addClass('has-error');
            }

            if (json['success']) {
                if (json['isPopup']) {
                    octPopupCart();
                } else {
                    usNotify('success', json['success']);
                }

                if(typeof octYandexEcommerce == 'function') {
                    octYandexEcommerce(json);
                }

                // Need to set timeout otherwise it wont update the total
                setTimeout(function () {
                    $('#oct-cart-quantity, .header-cart-index, #mobile_cart_index').html(json['total_products']);
                    $('.us-cart-text').html(json['total_amount']);
                }, 100);
            }
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
    });
}
</script>
Змінено користувачем esculapra
Надіслати
Поділитися на інших сайтах

  В 21.12.2022 в 19:36, spectre сказав:

данных только для нее нет тк нет селектора #product на странице

Expand  

там только рокировка 2-х кнопок, то есть все данные на странице есть.

Надіслати
Поділитися на інших сайтах

  В 21.12.2022 в 20:04, five сказав:

Всё равно не работает

Expand  

короче, сохрани страницу когда работает, и измененную. и запакуй мне в архив. сейчас на 2 часа электрику отключили - до полуночи не будет.

Надіслати
Поділитися на інших сайтах

  В 21.12.2022 в 20:06, esculapra сказав:

короче, сохрани страницу когда работает, и измененную. и запакуй мне в архив. сейчас на 2 часа электрику отключили - до полуночи не будет.

Expand  

Ок. Передал в личку

Надіслати
Поділитися на інших сайтах


Створіть аккаунт або увійдіть для коментування

Ви повинні бути користувачем, щоб залишити коментар

Створити обліковий запис

Зареєструйтеся для отримання облікового запису. Це просто!

Зареєструвати аккаунт

Вхід

Уже зареєстровані? Увійдіть тут.

Вхід зараз
  • Зараз на сторінці   0 користувачів

    • Ні користувачів, які переглядиють цю сторінку
×
×
  • Створити...

Important Information

На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність.