WDDiscountApp.PDPage.DisplayTiers = function () { if(globalFields.isProductPage){ var storeTime = globalFields.Storetime() ? globalFields.Storetime() : undefined; // 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("#wd_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) { $(".wd__days").html(days); $(".wd__hours").html(exactHour); $(".wd__minutes").html(minutes); $(".wd_sec, .wd__colon.seconds").hide(); } else { $(".wd__hours").html(exactHour); $(".wd__minutes").html(minutes); $(".wd__seconds").html(seconds); $(".wd_day, .wd__colon.hours").hide(); $(".wd_sec, .wd__colon.seconds").show(); } } else { jQuery('.wd__settings__table, #wd_countDown').remove(); } setTimeout(function () { jQuery('.wd__settings__table').after(jQuery("#wd_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); } this.DisplayTiersFn = function () { setTimeout(function () { jQuery('.wd__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(); let ProductPage = globalFields.TableProductPage != undefined && globalFields.TableProductPage != '' ? globalFields.TableProductPage : 'true'; ProductPage = ProductPage == 'true' ? true : false; if (selectedVariant != null && globalFieldsProductPage_WD.productMetafield != '[]' && globalFieldsProductPage_WD.productMetafield != undefined && ProductPage) { let tierObj = globalFields.GetTierObject(globalFieldsProductPage_WD.productMetafield, selectedVariant); let DiscountAppliedOn = false; let Location_Tag_s = false; if (tierObj != undefined) { DiscountAppliedOn = tierObj.DiscountAppliedON != null && tierObj.DiscountAppliedON != '' && tierObj.DiscountAppliedON != undefined ? true : false; Location_Tag_s = tierObj.Location_Tag_ != null && tierObj.Location_Tag_ != '' && tierObj.Location_Tag_ != undefined ? true : false; } if (DiscountAppliedOn) { // 1 if (Location_Tag_s) { // 2 let DiscountAppliedOnTag = tierObj.DiscountAppliedON == 'Both_Store' || tierObj.DiscountAppliedON == 'Online_Store' ? true : false; let LocationObject = Object.keys(tierObj.Location_Tag_); if (LocationObject[0] == 'StoreLocation') { let StoreLocationcheck = tierObj.Location_Tag_[LocationObject[0]].includes(globalFields.Storecountry) || tierObj.Location_Tag_[LocationObject[0]].includes(globalFields.Storecity) ? true : false; if (tierObj != undefined && tierObj.status && globalFields.StartEndDateValid(tierObj.start_date, tierObj.end_date) && DiscountAppliedOnTag && StoreLocationcheck) { var getDates = globalFields.TimerStartEndDateValid(tierObj.start_date, tierObj.end_date); getDates.valid; getDates.start_date; getDates.end_date; let timer_settings = parsed_timer_settings; 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); } } else { // 3 let TierLocation = tierObj.Location_Tag_[LocationObject[0]]; let CusotmerCountryLocation = globalFields.Customercountry; let CusotmerCityLocation = globalFields.Customercity; let CustomerLocationcheck_1 = (arr, arr1) => { return arr.some(item => arr1.includes(item)) }; let CustomerLocationcheck_2 = (arr2, arr3) => { return arr2.some(item => arr3.includes(item)) }; let CityValue = CustomerLocationcheck_1(TierLocation, CusotmerCountryLocation); let CountryValue = CustomerLocationcheck_2(TierLocation, CusotmerCityLocation); if (tierObj != undefined && tierObj.status && globalFields.StartEndDateValid(tierObj.start_date, tierObj.end_date) && DiscountAppliedOnTag && (CityValue || CountryValue)) { var getDates = globalFields.TimerStartEndDateValid(tierObj.start_date, tierObj.end_date); getDates.valid; getDates.start_date; getDates.end_date; let timer_settings = parsed_timer_settings; 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); } } } else { // 4 if (tierObj != undefined && tierObj.status && globalFields.StartEndDateValid(tierObj.start_date, tierObj.end_date) && (tierObj.DiscountAppliedON == 'Both_Store' || tierObj.DiscountAppliedON == 'Online_Store')) { var getDates = globalFields.TimerStartEndDateValid(tierObj.start_date, tierObj.end_date); getDates.valid; getDates.start_date; getDates.end_date; let timer_settings = undefined//parsed_timer_settings; 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); } } } else { // 5 let temptimer = globalFields.StartEndDateValid(tierObj.start_date, tierObj.end_date) if (tierObj != undefined && tierObj.status && 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//parsed_timer_settings; 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 () { $(".js.product-form__input label").click(function () { displayTiers.DisplayTiersFn(); }); }, 2000); } var TableHeadHtml = function (contentHtml, tableSelector, position) { jQuery(tableSelector).before(contentHtml) } var WriteTableHeading = function (tierObj) { var tableSelector = 'form[action="/cart/add"] .core__blocks .ecom-block.ecom-core.core__block.elmspace.ecom-fi8xx2s8bov'; if (globalFields.settings.selected_table == "table1") { TableHeadHtml('
' + globalFields.settings.table_headers.header1_value + ' | ' + globalFields.settings.table_headers.header2_value + ' |
---|
' + globalFields.settings.table_headers.header1_value + ' | ' + globalFields.settings.table_headers.header2_value + ' | ' + globalFields.settings.table_headers.header3_value + ' |
---|
' + globalFields.settings.table_headers.header1_value + ' | ' + globalFields.settings.table_headers.header2_value + ' | ' + globalFields.settings.table_headers.header3_value + ' |
---|
${globalFields.formatMoney(originalPrice_*100, globalFields.amount)}
`) //} updatedItemPrice = globalFields.formatMoney(Number(updatedItemPrice).toFixed(2), globalFields.amount); jQuery('.ecom-product-single__price--sale.ecom-product-single__price-normal').html('
${globalFields.formatMoney(originalPrice_*100, globalFields.amount)}
`) // jQuery('.ecom-product-single__price .ecom-product-single__price-container').html(`
${globalFields.formatMoney(originalPrice_*100, globalFields.amount)}
`) // } if (isBreakLoop) { break; } } } } //function for get cost price async function getCostPrice1(variantId){ console.log("cost price"); let accessToken = "***********"; const myHeaders = new Headers(); myHeaders.append("X-Shopify-Access-Token", accessToken ); const requestOptions = { method: "GET", headers: myHeaders, redirect: "follow" }; try { let resData = await fetch(`https://6edc19.myshopify.com/admin/api/2024-01/variants/${variantId}.json`, requestOptions); let data = await resData.json(); console.log("data", data); let inventryId = data.variant.inventory_item_id; //for cost price let responseData = await fetch(`https://6edc19.myshopify.com/admin/api/2024-01/inventory_items/${inventryId}.json`, requestOptions); let costData = await responseData.json(); let costPrice = costData.inventory_item.cost; console.log(">>>", costPrice); return costPrice; } catch (er){ console.log("err>>>>", er) } } //end function //function for get cost price by backend async function getCostPrice(variantId){ let accessToken = "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" const myHeaders = new Headers(); myHeaders.append("X-Shopify-Access-Token", accessToken ); const requestOptions = { method: "GET", headers: myHeaders, redirect: "follow" }; try { let resData = await fetch(`https://wholesale.apptiv.in/storeFront/getVariantCost?Shop=${Shopify.shop}&variantId=${variantId}`, requestOptions); let costPrice = await resData.json(); return costPrice.data; } catch (er){ console.log("err>>>>", er) } } //end function var globalFieldsProductPage_WD = new WDDiscountApp.PDPage.Global(), displayTiers = new WDDiscountApp.PDPage.DisplayTiers(); displayTiers.DisplayTiersFn(); displayTiers.OnVariantChange();