')),
buyNowBtn: gkt.$(document).find(gkt.selectors.buyNowBtn)
}
},
initialize: async function (jQuery) {
// gkt.$.ajaxSetup({global: true});
let tmpCartSettings = await gkt.f.getSettings();
gkt.f.setSettings(tmpCartSettings)
gkt.f.setSelectors();
gkt.state.page_type = gkt.f.getPageType();
gkt.elements = gkt.f.getElements(gkt.settings);
if ("" === gkt.state.page_type) return false;
gkt.utility.setLanguageLocale();
return gkt.f.bootstrap(gkt.settings);
},
globalListener: function (settings) {
let isIntervalActive = false
//if app is disabled reurn
if (settings.app.disableApp) {
return
} else {
if ("product" === gkt.state.page_type) {
gkt.productPage.init(settings)
}
if (settings.app.disableSideCart) {
if ("cart" === gkt.state.page_type) {
gkt.cartPage.init(settings)
}
} else {
gkt.cartPage.init(settings)
}
}
setInterval(async () => {
if (!isIntervalActive) {
// console.log("globalListener-active")
isIntervalActive = true
// insert productpage wrapper if productPage is initialized
if ("product" === gkt.state.page_type &&
gkt.elements.addToCartBtn.length > 0 &&
gkt.$(document).find(gkt.selectors.productPageWrapperV2).length == 0) {
console.log("productPage-insertWrapperIntoPage1")
gkt.productPage.f.insertWrapperIntoPage(settings)
}
let checkoutBtnEle = gkt.$(document).find(gkt.selectors.checkoutBtn)
// insert cartPage wrapper if cartPage is initialized
if (checkoutBtnEle.length > 0 &&
gkt.$(document).find(gkt.selectors.cartPageWrapperV2).length == 0) {
console.log("cartPage-insertWrapperIntoPage")
await gkt.cartPage.f.insertWrapperIntoPage(settings)
}
// check if comboproduct overwrite buyNowButton
if (false && gkt.gktCombo.state.comboHandle != "") {
gkt.gktCombo.f.comboBuyNowButtonOverwrite()
}
// check if giftCard overwrite buyNowButton
if (gkt.gktGiftCard.state.giftCardData) {
if(!gkt.elements.addToCartBtn.is(':visible')){
gkt.elements.addToCartBtn = gkt.$(document).find(gkt.selectors.addToCart)
gkt.gktGiftCard.f.giftCardAddToCartButtonOverwrite(gkt.gktGiftCard.state.giftCardData.isEmbededOnPage)
}
gkt.gktGiftCard.f.giftCardBuyNowButtonOverwrite()
if(!gkt.state.sendGiftcardOnPageBtnClicked){
gkt.gktGiftCard.f.changeGiftCardAddToCartButtonText(gkt.utility.renderLanguageValue(gkt.settings.languageData.giftcardV2.purchasePageFields.addToCartButtonText))
}
}
// check if giftwrap, message or oneclick upsell overwrite buyNowButton
if(gkt.state.isOverWriteBuyNowBtnTriggered && gkt.$(document).find(".gkt-overwrite-buy-now-btn").length == 0){
gkt.utility.overWriteBuyNowBtn()
}
if( (gkt.state.page_type == "cart" || "product" === gkt.state.page_type) &&
gkt.settings.rewardCampaigns.status == "ACTIVE" &&
gkt.settings.rewardCampaigns.campaignData &&
gkt.settings.rewardCampaigns.campaignData.freeGiftcardProduct &&
gkt.settings.rewardCampaigns.campaignData.freeGiftcardProduct.length &&
gkt.settings.rewardCampaigns.campaignData.freeGiftcardProduct.length > 0
){
await gkt.gktFreeGiftCardPopup.f.addFreeGiftcardProduct()
}
isIntervalActive = false
}
}, 1000)
}
},
utility: {
getActiveCurrencyRate : function(){
let currencyRate = 1;
if(window.Shopify && window.Shopify.currency && window.Shopify.currency.rate){
currencyRate = window.Shopify.currency.rate;
}
return currencyRate;
},
getCookie: function (cookieName) {
let name = cookieName + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(";");
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == " ") {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return null;
},
getLocale: function () {
if (window.Shopify && window.Shopify.locale) {
return window.Shopify.locale
}else{
return "en"
}
},
setLanguageLocale: function () {
let locale = gkt.utility.getLocale()
if(gkt.settings.languageData && gkt.settings.languageData.languageMode == "SINGLE"){
locale = "en"
}
if(!gkt.settings.languageData[locale]){
locale = "en"
}
gkt.settings.languageData = gkt.settings.languageData[locale]
},
setCookie: function (cookieName, cookieValue, expiryDays = 7) {
const d = new Date();
d.setTime(d.getTime() + expiryDays * 24 * 60 * 60 * 1000);
let expires = "expires=" + d.toUTCString();
document.cookie = cookieName + "=" + cookieValue + ";" + expires + ";path=/";
},
addToCart: async function (data) {
try {
// if there is nothing to add in cart..just return true
if (!data.id) {
return true
}
let result = await gkt.$.ajax({
url: "/cart/add.js",
data: data,
type: "POST",
dataType: "json",
})
return true
} catch (error) {
console.error("gkt-utility-addToCart");
console.error(error);
return false
}
},
updateCart: async function (data) {
try {
let result = await gkt.$.ajax({
type: "POST",
url: "/cart/update.js",
data: data,
dataType: "json",
});
return result
} catch (error) {
console.error("gkt-utility-updateCart");
console.error(error);
return false
}
},
changeCart: async function (data) {
try {
let result = await gkt.$.ajax({
type: "POST",
url: "/cart/change.js",
data: data,
dataType: "json",
});
return true
} catch (error) {
console.error("gkt-utility-changeCart");
console.error(error);
return false
}
},
getProductData: async function (productName) {
try {
let result = await gkt.$.ajax({
type: "GET",
url: "/products/" + productName,
// data: data,
dataType: "json",
});
return result;
} catch (error) {
console.error("gkt-utility-updateCart");
console.error(error);
return false
}
},
getProductDataV2: function (productName) {
try {
return new Promise((res, rej) => {
gkt.$.getJSON("/products/" + productName + ".js", function (product) {
console.log("success-productName: ", productName)
res(product)
}).fail(function () { console.log("fail-productName: ", productName); res(false) })
})
return result;
} catch (error) {
console.error("gkt-utility-getProductDataV2");
console.error(error);
return false
}
},
addToCartV2: function (data) {
try {
return new Promise((res, rej) => {
gkt.$.post('/cart/add.js', data)
.done(function () { console.log("success-/cart/add.js': "); res(true) })
.fail(function (e) {
console.log("fail-/cart/add.js", e);
res(false)
})
})
return result;
} catch (error) {
console.error("gkt-utility-addToCartV2");
console.error(error);
return false
}
},
clearCart: function (data) {
try {
return new Promise((res, rej) => {
gkt.$.post('/cart/clear.js', data)
.done(function () { console.log("success-/cart/clear.js': "); res(true) })
.fail(function () { console.log("fail-/cart/clear.js"); res(false) })
})
return result;
} catch (error) {
console.error("gkt-utility-clearCart");
console.error(error);
return false
}
},
getCart: async function (data) {
try {
let result = await gkt.$.ajax({
type: "GET",
url: "/cart.js",
dataType: "json",
});
return result
} catch (error) {
console.error("gkt-utility-getCart");
console.error(error);
return false
}
},
getCartTotalQuantity: async function () {
try {
let total = 0
let cartData = await gkt.$.ajax({
type: "GET",
url: "/cart.js",
dataType: "json",
});
for (var item of cartData['items']) {
total += item["quantity"]
}
return total
} catch (error) {
console.error("gkt-utility-getCart");
console.error(error);
return false
}
},
checkIfItemPresentInCart: function (searchedVariantId) {
if (gkt.state.cartData && gkt.state.cartData.items && gkt.state.cartData.items.length && gkt.state.cartData.items.length > 0) {
for (let i = 0; i < gkt.state.cartData.items.length; i++) {
let item = gkt.state.cartData.items[i]
if (item && item.variant_id && item.variant_id == searchedVariantId) {
return item
}
}
return false
} else {
return false
}
},
getNoteFromCart: function () {
if (gkt.state.cartData && gkt.state.cartData.note && gkt.state.cartData.note != "") {
return gkt.state.cartData.note
} else {
return false
}
},
isCartTotalMoreThan: async function(value){
gkt.state.cartData = await gkt.utility.getCart()
if(gkt.state.cartData && gkt.state.cartData.total_price && ((gkt.state.cartData.total_price)/100 >= parseFloat(value))){
return true
}else{
return false
}
},
cloneAddToCartBtn: function () {
},
overWriteBuyNowBtn: function (){
let buyNowBtnEle = gkt.$(document).find(gkt.selectors.buyNowBtn)
if(buyNowBtnEle && buyNowBtnEle.length > 0 && gkt.$(document).find(".gkt-overwrite-buy-now-btn").length == 0){
// buyNowBtnEle.show()
buyNowBtnEle.unbind().unbind("click").off().off("click");
newBuyNowBtnEle = buyNowBtnEle.clone()
buyNowBtnEle.before(newBuyNowBtnEle)
// buyNowBtnEle.hide()
newBuyNowBtnEle.addClass("gkt-overwrite-buy-now-btn")
buyNowBtnEle.css("visibility", "hidden")
buyNowBtnEle.css("height", "0")
buyNowBtnEle.css("width", "0")
buyNowBtnEle.css("padding", "0")
buyNowBtnEle.css("margin", "0")
buyNowBtnEle.css("line-height", "0");
buyNowBtnEle.css("min-height", "0");
// clone add to cart behavior
// newBuyNowBtnEle.on("click", async function (event) {
// gkt.$(this).attr("disabled", true);
// setTimeout(() => { gkt.$(this).attr("disabled", false); }, 1000)
// event.preventDefault();
// event.stopPropagation();
// let selectedVariantId = gkt.f.getSelectedVariant()
// let resAddToCart = await gkt.utility.addToCartV2({ "items": [
// {
// "id": selectedVariantId,
// "quantity": 1
// }
// ]})
// window.location.href = window.location.origin + "/cart/checkout"
// return
// })
newBuyNowBtnEle.on("click", function (event) {
event.preventDefault();
event.stopPropagation();
gkt.$(this).attr("disabled", true);
newBuyNowBtnEle.text("loading checkout...");
setTimeout(() => { gkt.$(this).attr("disabled", false)}, 3000)
addToCartBtnEle = gkt.$(document).find(gkt.selectors.addToCart)
sideCartEle = gkt.$(document).find(gkt.selectors.sideCartSelectors)
// gkt.$(document).find("body").addClass("loadingCheckoutPage")
// gkt.$(document).find("body").text("loading checkout...")
if(sideCartEle && sideCartEle.length > 0){
sideCartEle.css("display", "none")
}
if(addToCartBtnEle && addToCartBtnEle.length > 0){
addToCartBtnEle.trigger("click")
}
setTimeout(()=>{
window.location.href = gkt.settings.app.redirectUrlForSendGiftcardBtn
},1000)
})
}
},
emailValidation: function (emailString) {
var atSymbol = emailString.indexOf("@");
if (atSymbol < 1) return false;
var dot = emailString.lastIndexOf(".");
if (dot <= atSymbol + 2) return false;
// check that the dot is not at the end
if (dot === emailString.length - 1) return false;
return true;
},
renderLanguageValue: function (parent) {
if (parent){
return parent.value;
}
return;
},
slider: {
state: {
slideIndex: 0,
},
plusSlides: function (selector, n) {
this.showSlides(selector, this.state.slideIndex += n);
},
//minusSlides
minusSlides: function (selector, n) {
this.showSlides(selector, this.state.slideIndex -= n);
},
showSlides: function (selector, n) {
var i;
var slides = selector.find(".gktComboItemContainerItem1Img");
if (slides && slides.length) {
// slides = JSON.parse(slides);
// }
if (n > slides.length) { this.state.slideIndex = 1 }
if (n < 1) { this.state.slideIndex = slides.length }
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[this.state.slideIndex - 1].style.display = "block";
// plusSlides(1)
}
// setTimeout(function () { plusSlides(n + 1) }, 2000);
},
},
isMobileView: function () {
if (window.innerWidth < 768) {
return true;
} else {
return false;
}
},
displayLoadingSpinner: function () {
let loadingContainer = gkt.$("
").addClass("gktLoading");
let loadingSpinner = gkt.$("
").addClass("gktLoadingSpinner");
loadingContainer.append(loadingSpinner);
return loadingContainer;
},
dynamicStylesForBranding: function () {
let brandingColor = {
mainTextColor: gkt.settings.accountWidget.customization.mainTextColor,
subTextColor : gkt.settings.accountWidget.customization.subTextColor,
}
let style =
``
gkt.$('html > head').append(style);
return style;
},
getLocalDateIn_YYYY_MM_DD: function (date=new Date()) {
const year = date.getFullYear();
const month = ('0' + (date.getMonth() + 1)).slice(-2);
const day = ('0' + date.getDate()).slice(-2)
const dateInLocalTimeZone = `${year}-${month}-${day}`;
return dateInLocalTimeZone;
},
},
storage: {
loadValuesFromStorage: function (settings) {
var gktGiftMessageCheckbox = sessionStorage.getItem("gktGiftMessageCheckbox");
var gktMessageTextarea = sessionStorage.getItem("gktMessageTextarea");
var gktGiftWrapCheckbox = sessionStorage.getItem("gktGiftWrapCheckbox");
var gktGiftOptionsCheckbox = sessionStorage.getItem("gktGiftOptionsCheckbox");
gkt.$('.gktMessageTextarea').val(gktMessageTextarea);
if (gktGiftMessageCheckbox === null) {
gkt.$('.gktGiftMessageCheckbox').prop('checked', true);
} else {
gkt.$('.gktGiftMessageCheckbox').prop('checked', gktGiftMessageCheckbox === "true");
}
if (gktGiftWrapCheckbox === null) {
gkt.$('.gktGiftWrapCheckbox').prop('checked', true);
} else {
gkt.$('.gktGiftWrapCheckbox').prop('checked', gktGiftWrapCheckbox === "true");
}
if (gktGiftOptionsCheckbox === null) {
gkt.elements.cartPageWrapperV2.find(".gktGiftOptionsCheckbox").prop('checked', false)
gkt.elements.productPageWrapperV2.find(".gktGiftOptionsCheckbox").prop('checked', false)
gkt.$(document).find(".gktGiftOptionsCheckbox").prop('checked', false)
} else {
gkt.elements.cartPageWrapperV2.find(".gktGiftOptionsCheckbox").prop('checked', gktGiftOptionsCheckbox === "true")
gkt.elements.productPageWrapperV2.find(".gktGiftOptionsCheckbox").prop('checked', gktGiftOptionsCheckbox === "true")
gkt.$(document).find(".gktGiftOptionsCheckbox").prop('checked', gktGiftOptionsCheckbox === "true")
}
},
setItem: function (field, value) {
sessionStorage.setItem(field, value)
},
getItem: function (field) {
return sessionStorage.getItem(field)
}
},
drawerCart: {
init: function (settings) {
gkt.cartPage.init(settings)
}
},
themeSpecificCode: {
init: function (settings) {
gkt.themeSpecificCode.f.ventureTheme(settings)
gkt.themeSpecificCode.f.expressTheme(settings)
gkt.themeSpecificCode.f.craveTheme(settings)
gkt.themeSpecificCode.f.craftTheme(settings)
gkt.themeSpecificCode.f.senseTheme(settings)
},
f: {
ventureTheme: function () {
if (window.Shopify && window.Shopify.theme && window.Shopify.theme.theme_store_id && window.Shopify.theme.theme_store_id == gkt.constants.themesIds.VENTURE_THEME) {
// reload on save
gkt.selectors.sideCartDrawerOverlay = ""
}
},
expressTheme: function () {
if (window.Shopify && window.Shopify.theme && window.Shopify.theme.theme_store_id && window.Shopify.theme.theme_store_id == gkt.constants.themesIds.EXPRESS_THEME) {
// addd a css property of jusyify-items:cetner to cartpagewrapper
gkt.elements.cartPageWrapperV2.css("justify-items", "center")
if (window.location.pathname.includes("/cart")) {
gkt.selectors.checkoutBtn = ".cart__actions"
}
}
},
craveTheme: function () {
if (window.Shopify && window.Shopify.theme && window.Shopify.theme.theme_store_id && window.Shopify.theme.theme_store_id == gkt.constants.themesIds.CRAVE_THEME) {
// change css of cart__ctas in the document to block
gkt.$(document).find(".cart__ctas").css("display", "block")
}
},
craftTheme: function () {
if (window.Shopify && window.Shopify.theme && window.Shopify.theme.theme_store_id && window.Shopify.theme.theme_store_id == gkt.constants.themesIds.CRAFT_THEME) {
// change css of cart__ctas in the document to block
gkt.$(document).find(".cart__ctas").css("display", "block")
}
},
senseTheme: function () {
if (window.Shopify && window.Shopify.theme && window.Shopify.theme.theme_store_id && window.Shopify.theme.theme_store_id == gkt.constants.themesIds.SENSE_THEME) {
// change css of cart__ctas in the document to block
gkt.$(document).find(".cart__ctas").css("display", "block")
}
},
}
},
productPage: {
init: async function (settings) {
console.log("productPage-init")
gkt.state.cartData = await gkt.utility.getCart()
// gkt.state.insertWrapperOnPage.push("PRODUCT_PAGE")
gkt.gktMessage.init(settings, "PRODUCT_PAGE")
// gkt.gktCombo.init(settings)
// gkt.gktGiftMsgAndWrap.init(settings, "PRODUCT_PAGE")
gkt.gktOneClickUpsell.init(settings, "PRODUCT_PAGE")
gkt.gktGiftCard.init(settings, "PRODUCT_PAGE")
gkt.gktAccountWidget.init(settings,"CART_PAGE")
gkt.gktNotification.init(settings, "CART_PAGE")
},
f: {
insertWrapperIntoPage: function (settings) {
if ("undefined" != typeof gkt.elements.addToCartBtn) {
let addToCartBtnEle = gkt.$(document).find(gkt.elements.addToCartBtn)
addToCartBtnEle.each(function (index) {
if (gkt.$(this).is(":visible")) {
if(gkt.settings.app.addAfterAddTocartBtn){
gkt.$(this).after(gkt.elements.productPageWrapperV2);
}else{
gkt.$(this).before(gkt.elements.productPageWrapperV2);
}
}
});
}
},
},
actions: {
insertUpsellModal: function () {
// Gs.$("body").append(Gs.settings._modalHtml);
alert("popModal for upsell action")
},
},
},
cartPage: {
init: async function (settings) {
gkt.state.cartData = await gkt.utility.getCart()
gkt.gktMessage.init(settings, "CART_PAGE")
// gkt.gktGiftMsgAndWrap.init(settings, "CART_PAGE")
gkt.gktOneClickUpsell.init(settings, "CART_PAGE")
gkt.gktFreeGiftCardPopup.init(settings, "CART_PAGE")
gkt.gktAccountWidget.init(settings,"CART_PAGE")
gkt.gktNotification.init(settings, "CART_PAGE")
},
f: {
insertWrapperIntoPage: function (settings) {
return new Promise((res, rej) => {
if ("undefined" != typeof gkt.elements.checkoutBtn) {
let checkoutBtnEle = gkt.$(document).find(gkt.selectors.checkoutBtn)
checkoutBtnEle.each(function (index) {
// console.log("index", index)
if (gkt.$(this).is(":visible")) {
// check if theme ids matches otherwise add element to default position
if (window.Shopify && window.Shopify.theme && window.Shopify.theme.theme_store_id && window.Shopify.theme.theme_store_id == gkt.constants.themesIds.DAWN_THEME) {
gkt.$(this).parent().before(gkt.elements.cartPageWrapperV2);
} else if(gkt.settings.app.addAftercheckoutBtn) {
gkt.$(this).after(gkt.elements.cartPageWrapperV2);
}else{
gkt.$(this).before(gkt.elements.cartPageWrapperV2);
}
}
});
}
res()
})
},
},
events: {
ajaxSuccess: function (cartSettings) {
console.log("register ajax success event")
gkt.$(document).ajaxSuccess(function (event, xhr, settings) {
console.log("ajaxSuccess", settings.url)
if (settings.url == "/change.js?line=1&quantity=0" || settings.url == "change.js?line=1&quantity=0" || settings.url == "change.js" || settings.url == "/change.js" || settings.url == "/cart.js" || settings.url == "cart.js" || settings.url == "cart" || settings.url == "/cart") {
setTimeout(function () {
console.log("ajaxSuccess")
}, 2000);
}
});
}
}
},
gktOneClickUpsell: {
init: async function (settings, parent) {
await gkt.gktOneClickUpsell.initialize(settings, parent)
gkt.gktOneClickUpsell.f.registerEvents()
},
initialize: async function (settings, parent) {
let productHandle = gkt.f.getProductPageHandle(settings)
// write function which return two list
// oneClickUpsell products that need to be shown on this product page
// get the list of oneClickUpsellProducts that need to be shown on cart page
let { oneClickUpsellListForCartPage, oneClickUpsellListForProductPage } = gkt.gktOneClickUpsell.f.segregateOneClickUpsells(settings.oneClickUpsells, productHandle)
if (parent == "PRODUCT_PAGE" && oneClickUpsellListForProductPage && oneClickUpsellListForProductPage.length && oneClickUpsellListForProductPage.length > 0) {
let variantListToBeShownOnProductPage = await gkt.gktOneClickUpsell.f.findVariantListToBeShown(oneClickUpsellListForProductPage)
let oneClickUpsellProductPageHTML = gkt.gktOneClickUpsell.f.prepareUI(settings, variantListToBeShownOnProductPage, parent)
gkt.gktOneClickUpsell.f.insertIntoProductPageWrapper(settings, oneClickUpsellProductPageHTML)
console.log("variantListToBeShownOnProductPage", variantListToBeShownOnProductPage)
gkt.utility.overWriteBuyNowBtn()
gkt.state.isOverWriteBuyNowBtnTriggered = true
console.log("PRODUCT_PAGE")
}
if (parent == "CART_PAGE" && oneClickUpsellListForCartPage && oneClickUpsellListForCartPage.length && oneClickUpsellListForCartPage.length > 0) {
let variantListToBeShownOnCartPage = await gkt.gktOneClickUpsell.f.findVariantListToBeShown(oneClickUpsellListForCartPage)
let oneClickUpsellCartPageHTML = gkt.gktOneClickUpsell.f.prepareUI(settings, variantListToBeShownOnCartPage, parent)
gkt.gktOneClickUpsell.f.insertIntoCartPageWrapper(settings, oneClickUpsellCartPageHTML)
console.log("variantListToBeShownOnCartPage", variantListToBeShownOnCartPage)
console.log("CART_PAGE")
}
},
f: {
segregateOneClickUpsells: function (oneClickUpsells, currProductHandle) {
let oneClickUpsellListForCartPage = []
let oneClickUpsellListForProductPage = []
for (let i = 0; i < oneClickUpsells.length; i++) {
let oneClickUpsell = oneClickUpsells[i]
// add products to cart page list
if (oneClickUpsell.isVisibleOnCart) {
oneClickUpsellListForCartPage.push(oneClickUpsell)
}
// add products to product page list
if (oneClickUpsell.isVisibleOnAllProductPages) {
oneClickUpsellListForProductPage.push(oneClickUpsell)
} else if (oneClickUpsell.isVisibleOnSpecificProductPages &&
oneClickUpsell.visibleOnSpecificProductPages &&
oneClickUpsell.visibleOnSpecificProductPages.find(x => x.handle === currProductHandle)) {
oneClickUpsellListForProductPage.push(oneClickUpsell)
}
}
return {
oneClickUpsellListForCartPage: oneClickUpsellListForCartPage,
oneClickUpsellListForProductPage: oneClickUpsellListForProductPage
}
},
findVariantListToBeShown: async function (oneClickUpsellList) {
let responseData = []
let variantListSelectedByUser = []
let apiCalls = []
for (let i = 0; i < oneClickUpsellList.length; i++) {
let oneClickUpsell = oneClickUpsellList[i]
for (let j = 0; j < oneClickUpsell.upsellProducts.length; j++) {
let oneClickUpsellProduct = oneClickUpsell.upsellProducts[j]
apiCalls.push(gkt.utility.getProductDataV2(oneClickUpsellProduct.handle))
for (let k = 0; k < oneClickUpsellProduct.variants.length; k++) {
variantListSelectedByUser.push(parseInt(oneClickUpsellProduct.variants[k].variantId))
}
}
}
let oneClickUpsellProducts = await Promise.all(apiCalls)
// get required variants and return
for (let i = 0; i < oneClickUpsellProducts.length; i++) {
let oneClickUpsellProduct = oneClickUpsellProducts[i]
if (!oneClickUpsellProduct) {
continue
}
for (let j = 0; j < oneClickUpsellProduct.variants.length; j++) {
let variant = oneClickUpsellProduct.variants[j]
//if variant.featured_image is null then take the onceClickUpsellProduct.featured_image
if (variant.featured_image) {
variant.featured_image = variant.featured_image.src
} else {
variant.featured_image = oneClickUpsellProduct.featured_image
}
//console.log("ashfaq");
// if variant is not available dont add it
if (!variant.available) {
continue
}
// if variant is not selected in admin ui, dont add it
if (variantListSelectedByUser.indexOf(variant.id) == -1) {
continue
}
responseData.push(variant)
}
}
return responseData
},
insertIntoProductPageWrapper: function (settings, oneClickUpsellHTML) {
gkt.elements.productPageWrapperV2.find(".gktProductPageUpsellWrapper").css("display", "block")
// // insert into parent element
// gkt.elements.gktGiftMsgAndWrapWrapperParent.find(".gktGiftMsgAndWrapWrapperInnerEle").append(settings.giftingOptions.shopifyPageinnerHTML); //cartPageText
// insert final element into productPageWrapperV2
gkt.elements.productPageWrapperV2.find(".gktProductPageUpsellWrapper").append(oneClickUpsellHTML);
},
insertIntoCartPageWrapper: function (settings, oneClickUpsellHTML) {
gkt.elements.cartPageWrapperV2.find(".gktCartUpsellWrapper").css("display", "block")
// insert into parent element
// gkt.elements.gktCartGiftMsgAndWrapWrapperParent.find(".gktGiftMsgAndWrapWrapperInnerEle").append(settings.giftingOptions.shopifyPageinnerHTML); //cartPageText
// insert final element into productPageWrapperV2
// gkt.elements.cartPageWrapperV2.find(".gktCartUpsellWrapper").append(gkt.elements.gktCartGiftMsgAndWrapWrapperParent);
gkt.elements.cartPageWrapperV2.find(".gktCartUpsellWrapper").append(oneClickUpsellHTML);
},
prepareUI: function (settings, variantListToBeShown, parent) {
let gktOneClickUpsellContainer = gkt.$("
").addClass('gktOneClickUpsellContainer')
for (let i = 0; i < variantListToBeShown.length; i++) {
let variant = variantListToBeShown[i]
let gktOneClickUpsellItemContainer = gkt.$("
").addClass('gktOneClickUpsellItemContainer')
let gktOneClickUpsellItemContainerCheckboxLable = gkt.$("