|
|
@ -389,68 +389,50 @@ jQuery(document).ready(function($) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$('.detail form.cart').on('submit', function(e) { |
|
|
|
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var $form = $(this); |
|
|
|
$('body').on('submit', 'form.cart', function(e) { |
|
|
|
product_id = $form.find('button[name=add-to-cart]').val(), |
|
|
|
e.preventDefault(); |
|
|
|
quantity = $form.find('input.qty').val() || 1; |
|
|
|
|
|
|
|
console.log(product_id); |
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
|
|
|
|
url: wc_add_to_cart_params.ajax_url, |
|
|
|
|
|
|
|
type: 'POST', |
|
|
|
|
|
|
|
data: { |
|
|
|
|
|
|
|
action: 'woocommerce_ajax_add_to_cart', |
|
|
|
|
|
|
|
product_id: product_id, |
|
|
|
|
|
|
|
quantity: quantity, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
success: function(response) { |
|
|
|
|
|
|
|
if (response.error && response.product_url) { |
|
|
|
|
|
|
|
window.location = response.product_url; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateCartFragment(); |
|
|
|
const $form = $(this); |
|
|
|
updateNotices(); |
|
|
|
const $button = $form.find('button[type="submit"]'); |
|
|
|
openBasketOnFirstAdd(); |
|
|
|
const product_id = $form.find('[name="add-to-cart"]').val(); |
|
|
|
}, |
|
|
|
const quantity = $form.find('input.qty').val() || 1; |
|
|
|
error: function(xhr) { |
|
|
|
|
|
|
|
console.log('AJAX Error:', xhr.responseText); |
|
|
|
|
|
|
|
alert('Ошибка добавления товара.'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const formData = new FormData($form[0]); |
|
|
|
|
|
|
|
|
|
|
|
jQuery(function($){ |
|
|
|
// Явно добавим обязательные поля
|
|
|
|
$('form.cart').on('submit', function(e){ |
|
|
|
formData.append('action', 'woocommerce_ajax_add_to_cart'); |
|
|
|
e.preventDefault(); |
|
|
|
formData.append('product_id', product_id); |
|
|
|
|
|
|
|
formData.append('quantity', quantity); |
|
|
|
|
|
|
|
|
|
|
|
var $form = $(this); |
|
|
|
// Spinner/Loading
|
|
|
|
var $button = $form.find('button[type="submit"]'); |
|
|
|
$button.addClass('loading'); |
|
|
|
|
|
|
|
const originalText = $button.html(); |
|
|
|
|
|
|
|
$button.html('<span class="spinner" style="width:20px;height:20px;display:inline-block;"><svg width="20" height="20" viewBox="0 0 50 50"><circle cx="25" cy="25" r="20" fill="none" stroke="#ffffff" stroke-width="5" stroke-linecap="round" stroke-dasharray="31.415, 31.415" transform="rotate(72.3246 25 25)"><animateTransform attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.7s" repeatCount="indefinite"/></circle></svg></span>'); |
|
|
|
|
|
|
|
|
|
|
|
var product_id = $button.val(); |
|
|
|
|
|
|
|
var quantity = $form.find('input.qty').val() || 1; |
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
$.ajax({ |
|
|
|
type: 'POST', |
|
|
|
type: 'POST', |
|
|
|
url: wc_add_to_cart_params.ajax_url, |
|
|
|
url: wc_add_to_cart_params.ajax_url, |
|
|
|
data: { |
|
|
|
data: formData, |
|
|
|
action: 'woocommerce_ajax_add_to_cart', |
|
|
|
contentType: false, |
|
|
|
product_id: product_id, |
|
|
|
processData: false, |
|
|
|
quantity: quantity, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
beforeSend: function() { |
|
|
|
|
|
|
|
$button.addClass('loading'); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
success: function(response) { |
|
|
|
success: function(response) { |
|
|
|
if (response.error && response.product_url) { |
|
|
|
if (response.error && response.product_url) { |
|
|
|
window.location = response.product_url; |
|
|
|
window.location = response.product_url; |
|
|
|
return; |
|
|
|
} else { |
|
|
|
|
|
|
|
$(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash, $button]); |
|
|
|
|
|
|
|
updateCartFragment(); |
|
|
|
|
|
|
|
updateNotices(); |
|
|
|
|
|
|
|
openBasketOnFirstAdd(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
$(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash, $button]); |
|
|
|
complete: function() { |
|
|
|
$button.removeClass('loading'); |
|
|
|
$button.removeClass('loading'); |
|
|
|
|
|
|
|
$button.html(originalText); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
error: function(xhr) { |
|
|
|
|
|
|
|
console.error('AJAX Error:', xhr.responseText); |
|
|
|
|
|
|
|
alert('Ошибка добавления товара в корзину.'); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -461,3 +443,5 @@ jQuery(function($){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|