S
S
Sergey Miller2020-06-08 00:43:55
opencart
Sergey Miller, 2020-06-08 00:43:55

Why is the product not being added to the cart (only from the product page)?

Hello.

Opencart 3.0.3.3

There is a problem - everywhere the goods are added to the cart as expected, but from the product page in no way, even though there are options, even if they are not there - nothing is added. Although when clicking on the "buy" button, the "buy" button changes its text as it was laid out from the "button" method from bootstrap.js, but nothing else happens, when the page is refreshed, the product also does not go to the cart. There are no errors in the console.

Maybe some tag or id was accidentally deleted?! But judging by the script, I have everything in the markup, I have been racking my brains for the second day, I decided to ask for a fresh look.

div#product exists, it has input and select options

<script type="text/javascript">
//add
$('#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',
beforeSend: function() {
$('#button-cart').button('loading');
},
complete: function() {
$('#button-cart').button('reset');
},
success: function(json) {
if (json['error']) {
if (json['error']['option']) {
for (i in json['error']['option']) {
var element = $('#input-option' + i.replace('_', '-'));
$.jGrowl(json['error']['option'][i]);
}
}

if (json['error']['recurring']) {
$.jGrowl(json['error']['recurring']);
}
}
if (json['success']) {
$.jGrowl(json['success']);

$('#cart > button').html('<span id="cart-total">' + json['total'] + '</span>');

$('#cart .inner').load('index.php?route=common/cart/info .inner .mini_product'); //тут не как из коробки, так как менял разметку корзины, НО написано тут все правильно, так как тоже самое работает в common.js (оттуда же и копировал строку)
}
},
error: function(xhr, ajaxOptions, thrownError) {
$.jGrowl(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Miller, 2020-06-08
@blackseabreathe

The question is closed. This was not in the markup:

<input type="hidden" name="product_id" value="{{ product_id }}" />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question