Если вы удалите продукты из корзины и попытаетесь добавить снова, обновленная корзина не будет отображаться или если вы хотите добавить к этому больше, то это тоже не сработает. Ящик тележки открывается только в первый раз. Я использую тему Shopify Flow.
Код: Выделить всё
function addProductsToCart(variantIdRegular, variantIdSubscription, selling_plan_id) {
var itemsToAdd = [{ id: variantIdRegular, quantity: 1 }];
if ($("input[name=payment-option]").is(":checked")) {
itemsToAdd.push({ id: variantIdSubscription, quantity: 1, selling_plan: selling_plan_id });
}
$.ajax({
url: '/cart/add.js',
type: 'post',
dataType: 'json',
contentType: "application/json",
data: JSON.stringify({ 'items': itemsToAdd }),
success: function(response) {
console.log('Both products added', response);
var cartDrawerButtonSelector = ".js-drawer-open-right-link";
var cartDrawerButton = document.querySelector(cartDrawerButtonSelector);
cartDrawerButton.click();
},
error: function(xhr, status, error) {
console.error('Failed to add products', xhr.responseJSON);
}
});
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... flow-theme
Мобильная версия