var mag = []; var mag_cod_iso = []; var currency = ''; const range_increment = 0.05; const max_qta_ordered = 10.00; const bypassMaxCheck = false; let timerInfoAggiornate; const timerValueInfoAggiornate = 900; const min_qta_prod = 0.05; let delayTimerGestioneIncrementiDecrementi = null; let timeoutRemoveProduct; function changeDestination(){ $('.js-destinations-products').on('change', function() { toogleWaitingOn(0.2); var quantity = []; var id_address = ''; id_address = $(this).val(); var product_id = ''; product_id = $(this).data('product-id'); var warehouse_id = ''; warehouse_id = $(this).data('warehouse-id'); var warehouse_qta = ''; warehouse_qta = $(this).data('warehouse-qta'); var id_cart_row = ''; id_cart_row = $(this).data('id-cart-row'); var json = {}; json = { "warehouse_id": warehouse_id, "quantity": warehouse_qta, "company_address_id": id_address } quantity.push(json); updateAddressProduct(product_id, quantity, id_cart_row); }); } function prepareQuantity(sweetAlertMessage = false, timerUpdate = true, product_id, nota = '', el, add_product = 0, id_cart_row = '', isoCodOnlyOneMagToUpdate = ''){ var quantity = []; var json = {}; if(isoCodOnlyOneMagToUpdate == '') { mag.forEach(function (single_mag) { let id_rows_cart = getIdRowsCart(el, product_id, single_mag.iso.toLowerCase(), id_cart_row); json = { "warehouse_id": single_mag.id, "quantity": parseFloat($(id_rows_cart).val()).toFixed(2), "company_address_id": -1 } if ($('.js-add-cart-note').length > 0 && nota != null && nota != ' ' && nota != '' && nota != undefined) { Object.assign(json, { "note": nota }); } quantity.push(json); }); } else if(isoCodOnlyOneMagToUpdate != '') { let dest_prod = $("#dest-prod-"+product_id+"-mag-"+isoCodOnlyOneMagToUpdate+"-"+id_cart_row).val(); let company_address_id = ""; if(typeof dest_prod != "undefined" && dest_prod != null && dest_prod.trim() != ""){ company_address_id = dest_prod; } else { company_address_id = -1; } let magToUpdate = (Array.isArray(mag) ? mag : Array.from(mag)).find(o => String(o?.iso?? "").trim().toUpperCase() === isoCodOnlyOneMagToUpdate.toUpperCase()) || null; let id_rows_cart = getIdRowsCart(el, product_id, isoCodOnlyOneMagToUpdate, id_cart_row); json = { "warehouse_id": magToUpdate.id, "quantity": parseFloat($(id_rows_cart).val()).toFixed(2), "company_address_id": company_address_id } if ($('.js-add-cart-note').length > 0 && nota != null && nota != ' ' && nota != '' && nota != undefined) { Object.assign(json, { "note": nota }); } quantity.push(json); } updateCart(product_id, quantity, '', '', timerUpdate, sweetAlertMessage, add_product, el, id_cart_row); } function gestione_incrementi_decrementi(el, sweetAlertMessage = false, timerUpdate = true, product_id, class_context = '', id_cart_rows = '', isoCodMagToUpdate = 'it'){ let float_value_is_ok = false; if(el != null && el != '' && el != ' ' & el != undefined) { /* mag_cod_iso.forEach(function (mag) { */ if($(el).hasClass(isoCodMagToUpdate)) { let current_value_qta = 0.00; if(class_context != ''){ if(id_cart_rows != '') { current_value_qta = $(class_context + ' #js-input-text-prod-' + product_id + '-mag-' + isoCodMagToUpdate + '-' + id_cart_rows).val(); } else { current_value_qta = $(class_context + ' #js-input-text-prod-' + product_id + '-mag-' + isoCodMagToUpdate).val(); } } else { if(id_cart_rows != '') { current_value_qta = $('#js-input-text-prod-' + product_id + '-mag-' + isoCodMagToUpdate + '-' + id_cart_rows).val(); } else { current_value_qta = $('#js-input-text-prod-' + product_id + '-mag-' + isoCodMagToUpdate).val(); } } if($(el).hasClass(isoCodMagToUpdate)) { newValue = 0.00; if($(el).find('i').hasClass('fa-plus') || $(el).find('i').hasClass('fa-angle-up')){ var newValue = (parseFloat(current_value_qta) + parseFloat(range_increment)).toFixed(2); } else if ($(el).find('i').hasClass('fa-minus') || $(el).find('i').hasClass('fa-angle-down')){ var newValue = (parseFloat(current_value_qta) - parseFloat(range_increment)).toFixed(2); } var newAllowedValue = adjustQuantity(newValue, max_qta_ordered, range_increment); if(class_context != ''){ if(id_cart_rows != '') { $(class_context + ' #js-input-text-prod-' + product_id + '-mag-' + isoCodMagToUpdate + '-' + id_cart_rows).val(newAllowedValue); } else { $(class_context + ' #js-input-text-prod-' + product_id + '-mag-' + isoCodMagToUpdate).val(newAllowedValue); } } else { if(id_cart_rows != '') { $('#js-input-text-prod-' + product_id + '-mag-' + isoCodMagToUpdate + '-' + id_cart_rows).val(newAllowedValue); } else { $('#js-input-text-prod-' + product_id + '-mag-' + isoCodMagToUpdate).val(newAllowedValue); } } if(newAllowedValue != undefined && newAllowedValue != '' && newAllowedValue != ' ' && newAllowedValue != null && newAllowedValue > 0.00 && newValue > 0.00){ float_value_is_ok = true; } } } /*});*/ if(!$(el).hasClass('js-not-update-qta') && float_value_is_ok){ if (delayTimerGestioneIncrementiDecrementi !== null) { clearTimeout(delayTimerGestioneIncrementiDecrementi); } delayTimerGestioneIncrementiDecrementi = setTimeout(() => { prepareQuantity(sweetAlertMessage, timerUpdate, product_id, '', el, 0, id_cart_rows, el.classList[1]); delayTimerGestioneIncrementiDecrementi = null; }, 500); } } } function get_value_add_product_variable(el){ let add_product = 0; if(el && typeof el !== "undefined" && el != ''){ add_product = el.data('add-product'); } return add_product; } function componiAggiuntaProdotto(fromMag, quantity, el, product_id, fromMagId){ var json = {}; let id_rows_cart = getIdRowsCart(el, product_id, fromMag); json = { "warehouse_id": fromMagId, "quantity": parseFloat($(id_rows_cart).val()).toFixed(2), "company_address_id": -1 } if ($('.js-add-cart-note').length > 0 && nota != null && nota != ' ' && nota != '' && nota != undefined) { Object.assign(json, { "note": nota }); } quantity.push(json); return quantity; } function aggiungi_prodotto(el = '', fromMag = '', fromMagId){ let add_product = get_value_add_product_variable(el); var quantity = []; let product_id; product_id = el.closest('.js-add-cart-container-btn').find('.js-product-id').val(); if( fromMag != null && typeof fromMag != "undefined" && fromMag != ''){ quantity = componiAggiuntaProdotto(fromMag, quantity, el, product_id, fromMagId); } else { mag.forEach(function (single_mag){ quantity = componiAggiuntaProdotto(single_mag.iso.toLowerCase(), quantity, el, product_id, fromMagId); }); } if(quantity.length == 1 && quantity[0]['quantity'] == 0){ swal({ text: "