127 lines
3.9 KiB
JavaScript
127 lines
3.9 KiB
JavaScript
$(function () {
|
|
const empikProductExportButtonSelector = '.js-empik-products-export';
|
|
const empikOfferExportButtonSelector = '.js-empik-offers-export';
|
|
const empikPriceInputSelector = '.js-empik-price-input';
|
|
|
|
$(document).on('click', empikProductExportButtonSelector, function (e) {
|
|
e.preventDefault();
|
|
|
|
$(this).attr('disabled', 'disabled');
|
|
|
|
let page = 0;
|
|
ajaxRequest();
|
|
|
|
function ajaxRequest() {
|
|
|
|
const formData = new FormData();
|
|
formData.append('action', 'exportProducts');
|
|
formData.append('page', page);
|
|
|
|
$.ajax({
|
|
method: 'post',
|
|
url: empikAjaxUrl,
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
if (response.success) {
|
|
if (response.continue) {
|
|
page++;
|
|
ajaxRequest();
|
|
} else {
|
|
window.location = response.redirect;
|
|
$(this).removeAttr('disabled');
|
|
}
|
|
} else {
|
|
alert(response.errors[0]);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
});
|
|
|
|
$(document).on('click', empikOfferExportButtonSelector, function (e) {
|
|
e.preventDefault();
|
|
|
|
$(this).attr('disabled', 'disabled');
|
|
|
|
let page = 0;
|
|
ajaxRequest();
|
|
|
|
function ajaxRequest() {
|
|
|
|
const formData = new FormData();
|
|
formData.append('action', 'exportOffers');
|
|
formData.append('page', page);
|
|
|
|
$.ajax({
|
|
method: 'post',
|
|
url: empikAjaxUrl,
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
dataType: 'json',
|
|
success: function (response) {
|
|
if (response.success) {
|
|
if (response.continue) {
|
|
page++;
|
|
ajaxRequest();
|
|
} else {
|
|
window.location = response.redirect;
|
|
$(this).removeAttr('disabled');
|
|
}
|
|
} else {
|
|
alert(response.errors[0]);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
});
|
|
|
|
$(document).on('change', empikPriceInputSelector, function (e) {
|
|
const value = $(this).val();
|
|
|
|
// replace , with .
|
|
let formattedValue = value.replace(',', '.');
|
|
|
|
// remove all non-numeric characters
|
|
formattedValue = formattedValue.replace(/[^0-9\.]/g, '');
|
|
|
|
formattedValue = parseFloat(formattedValue);
|
|
|
|
// check is value is a number
|
|
if (isNaN(formattedValue)) {
|
|
formattedValue = 0.00;
|
|
}
|
|
|
|
formattedValue = formattedValue.toFixed(2);
|
|
|
|
$(this).val(formattedValue);
|
|
});
|
|
|
|
$(document).on('change', empikPriceInputSelector, function (e) {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData();
|
|
formData.append('action', $(this).data('action'));
|
|
formData.append('id_product', $(this).data('product-id'));
|
|
formData.append('id_product_attribute', $(this).data('product-attribute-id'));
|
|
formData.append('price', $(this).val());
|
|
|
|
$.ajax({
|
|
method: 'post',
|
|
url: empikAjaxUrl,
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
dataType: 'json',
|
|
success: (response) => {
|
|
if (response.success && typeof response.message !== 'undefined') {
|
|
showSuccessMessage(response.message);
|
|
}
|
|
},
|
|
});
|
|
});
|
|
});
|