Внесу трішки роз'яснення для чайників тай для себе коли прийде час повторити щоб довго не шукав).
Для автоматичного переходу в корзину потрібно редагувати файл:
/catalog/view/theme/default/template/product/product.twig
після рядків
if (json['success']) {
....
$('#cart > ul').load('index.php?route=common/cart/info ul li');
додати
window.location.href = "/index.php?route=checkout/checkout";
оновити кєш і буде прцювати, але так не цікаво креще додати ще одну кнопку яка буде Купити а звичайні змінити ім'я на "В Кошик"
наприклад додати кнопку:
після
<input type="hidden" name="product_id" value="{{ product_id }}" />
<br/>
додати
<button type="button" id="button-cart-buy" data-loading-text="{{ text_loading }}" class="btn btn-primary btn-lg btn-block">{{ button_cart_buy }}</button>
потім потрібно в Файлі перекладу /catalog/language/uk-ua/uk-ua.phg додати переклад та в інших мовах
$_['button_cart_buy'] = 'Купити';
та змінити
$_['button_cart'] = 'до Кошика'
потім додаємо скрипт для його роботи в product.twig
<script type="text/javascript"><!--
$('#button-cart-buy').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-buy').button('loading');
},
complete: function() {
$('#button-cart-buy').button('reset');
},
success: function(json) {
$('.alert-dismissible, .text-danger').remove();
$('.form-group').removeClass('has-error');
if (json['error']) {
if (json['error']['option']) {
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>');
}
}
}
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']) {
$('.breadcrumb').after('<div class="alert alert-success alert-dismissible">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">×</button></div>');
$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
window.location.href = "/index.php?route=checkout/simplecheckout";
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
//--></script>
Також можливо додати таку кнопку в категорії та пошук, тільки common.js потрібно додати функцію
'buy': function(product_id, quantity) {
$.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-dismissible, .text-danger').remove();
if (json['redirect']) {
location = json['redirect'];
}
if (json['success']) {
//$('#content').parent().before('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">×</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');
window.location.href = "/index.php?route=checkout/simplecheckout";
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
},
Та додаємо кнопку чи в категоріях чи пошуку
<div class="button">
<button type="button-buy" class="btn btn-primary btn-lg btn-block" onclick="cart.buy('{{ product.product_id }}', '{{ product.minimum }}');">{{ button_cart_buy }}</button>
</div>