ACDiscountApp.PDPage.DisplayTiers = function () { var storeTime = globalFields.Storetime(); // Parse the date string into individual components let [currentYear, currentMonth, currentDay, currentHours, currentMinutes, currentSeconds] = storeTime.split(/[\sT:-]/); currentYear = parseInt(currentYear); currentMonth = parseInt(currentMonth); // Months are zero-based in JavaScript currentDay = parseInt(currentDay); currentHours = parseInt(currentHours); currentMinutes =parseInt(currentMinutes); currentSeconds = parseInt(currentSeconds); function makeTimer(end_date) { if(globalFields.isProduct_Page){ if(end_date != null){ jQuery("#ac_countDown").css("display", "block"); var endTime = end_date; // Increment seconds by 1 currentSeconds++; // Adjust minutes, hours, and day if necessary if (currentSeconds >= 60) { currentSeconds = 0; currentMinutes++; if (currentMinutes >= 60) { currentMinutes = 0; currentHours++; if (currentHours >= 24) { currentHours = 0; currentDay++; } } } // Reformat the updated timestamp let currentStoreTime = `${currentYear}-${currentMonth.toString().padStart(2, '0')}-${currentDay.toString().padStart(2, '0')}T${currentHours.toString().padStart(2, '0')}:${currentMinutes.toString().padStart(2, '0')}:${currentSeconds.toString().padStart(2, '0')}`; endTime = (Date.parse(endTime) / 1000); var now = currentStoreTime; now = (Date.parse(now) / 1000); var timeLeft = endTime - now; var days = Math.floor(timeLeft / 86400); var hours = Math.floor(timeLeft / 3600); var exactHour = hours % 24; var minutes = Math.floor((timeLeft - (hours * 3600 )) / 60); var seconds = Math.floor((timeLeft - (hours * 3600) - (minutes * 60))); var isDays = false; if (days > 0 || hours > 24){isDays = true;} if (days < 0) { days = "00"; /*hours = "0"; minutes = "0"; seconds = "0";*/ } if (hours < 10) { hours = "0" + hours; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; } if(timeLeft > 0){ if(isDays){ $(".ac__days").html(days); $(".ac__hours").html(exactHour); $(".ac__minutes").html(minutes); $(".ac_sec, .ac__colon.seconds").hide(); } else{ $(".ac__hours").html(exactHour); $(".ac__minutes").html(minutes); $(".ac__seconds").html(seconds); $(".ac_day, .ac__colon.hours").hide(); $(".ac_sec, .ac__colon.seconds").show(); } } else{jQuery('.ac__settings__table, #ac_countDown').remove();} setTimeout(function () { jQuery('.ac__settings__table').after(jQuery("#ac_countDown")); }, 500); } } } var hide_buttons = null; var HideAdditionalPayments = function() { hide_buttons = setInterval(function() { if(jQuery('.shopify-payment-button__button').length>0){ jQuery('.shopify-payment-button__button').hide(); clearInterval(hide_buttons); } }, 500); } function checkDiscountId(discounts,id) { const found = discounts.some(discount => discount.id === id); return !found; // Return false if found, else true } this.DisplayTiersFn = function () { setTimeout(function () { jQuery('.ac__settings__table').remove(); var selectedVariant = jQuery('input[name^=id]:checked, select[name^=id], input[name=id], hidden[name^=id]', jQuery('form[action="/cart/add"]')).val(); if (selectedVariant != null) { var tierObj = globalFields.GetTierObject(globalFieldsProductPage_AC.productMetafield, selectedVariant); if (tierObj != undefined && tierObj.status && checkDiscountId(tierObj.excludeProducts,globalFields.productId) && globalFields.StartEndDateValid(tierObj.start_date, tierObj.end_date)) { var getDates = globalFields.TimerStartEndDateValid(tierObj.start_date, tierObj.end_date); getDates.valid; getDates.start_date; getDates.end_date; let timer_settings = undefined; WriteTableHeading(tierObj); WriteTableRows(tierObj, selectedVariant); if(timer_settings != undefined){ if(timer_settings.TimerStatus){ if(getDates.valid){ setInterval(function() { makeTimer(getDates.end_date); }, 1000); } } } jQuery('.shopify-payment-button__button').hide(); setTimeout(function(){ jQuery('.shopify-payment-button__button').hide(); HideAdditionalPayments(); }, 2000); setTimeout(function(){ clearInterval(hide_buttons); }, 5000); } } }, 200); } setTimeout(function(){ clearInterval(hide_buttons); }, 10000); this.OnVariantChange = function () { setTimeout(function () { $(".single-option-selector,.single-option-selector__radio").change(function () { displayTiers.DisplayTiersFn(); }); }, 2000); } this.changePrice = function(){ var productPrice = jQuery('form[action="/cart/add"] .price-list .money').text().split('£')[1]; productPrice = globalFields.formatMoney(Number(productPrice).toFixed(2), globalFields.amount); // alert(productPrice); if(jQuery('table.ac__settings__table').length > 0){ var discountedPrice = jQuery('table.ac__settings__table .ac__tr:last td:eq(1) .money').text().split('£')[1]; discountedPrice = globalFields.formatMoney(Number(discountedPrice).toFixed(2), globalFields.amount); var discountedQty = jQuery('table.ac__settings__table .ac__tr:last td:eq(0)').text().split('+')[0]; discountedQty = Number(discountedQty); var originalChangeQty = jQuery('form[action="/cart/add"] input.quantity-selector__value').val(); originalChangeQty = Number(originalChangeQty); if(isNaN(originalChangeQty)){ originalChangeQty = 1; } // console.log('discountedQty', discountedQty); // console.log('originalChangeQty', originalChangeQty); // alert(originalChangeQty); var updatedItemPrice = 0 var selectedVariant = jQuery('input[name^=id]:checked, select[name^=id], input[name=id], hidden[name^=id]', jQuery('form[action="/cart/add"]')).val(); if(selectedVariant == ""){ let id_= Object.keys(globalFieldsProductPage_AC.variantsPriceArray_PD) selectedVariant = id_[0]; } if (selectedVariant != null && globalFieldsProductPage_AC.productMetafield != '[]' && globalFieldsProductPage_AC.productMetafield != undefined && selectedVariant != "") { var tierObj = globalFields.GetTierObject(globalFieldsProductPage_AC.productMetafield, selectedVariant); if (tierObj != undefined && tierObj.status && globalFields.StartEndDateValid(tierObj.start_date, tierObj.end_date)) { for (i = 0; i < tierObj.tier_min.length; i++) { var tierPrice = parseFloat(tierObj.tier_values[i]); var minTier = parseInt(tierObj.tier_min[i]), maxTier = tierObj.tier_max[i] != 'max' ? parseInt(tierObj.tier_max[i]) : tierObj.tier_max[i]; var updatedLinePrice = 0, condition1 = false, condition2 = false; var originalPrice_ = jQuery('form[action="/cart/add"] .price-list .money').text().split('£')[1]; originalPrice_ = Number(originalPrice_); condition1 = originalChangeQty >= minTier; condition2 = maxTier == "max" || originalChangeQty <= maxTier; if (condition1 && condition2) { break; } } if (condition1 && condition2) { if (tierObj.discount_type == 'percentage') { var originalPriceCut = parseFloat(globalFields.ConvertToFixedDecimalNumber((parseFloat(tierPrice) / 100) * globalFields.ConvertToFixedDecimalNumber(originalPrice_))); updatedItemPrice = globalFields.ConvertToFixedDecimalNumber(globalFields.ConvertToFixedDecimalNumber(originalPrice_) - originalPriceCut); } else if (tierObj.discount_type == 'fixed') { updatedItemPrice = globalFields.ConvertToFixedDecimalNumber(globalFields.ConvertToFixedDecimalNumber(originalPrice_) - parseFloat(tierPrice)); } else if (tierObj.discount_type == 'fixed_price') { updatedItemPrice = globalFields.ConvertToFixedDecimalNumber(parseFloat(tierPrice)); } updatedItemPrice = globalFields.formatMoney(Number(updatedItemPrice).toFixed(2), globalFields.amount); jQuery('form[action="/cart/add"] .price-list').html(`