`; } else if (i == 1) { contentHtml += ``; } else if (i == 2) { contentHtml += ``; } } tabs.innerHTML = tabsHtml; content.innerHTML = contentHtml; } function sizeActions(id, oos, sku) { selectItem(id, oos); selectVariant(sku); } function loadSizeOptions(productObj) { var sizes = productObj.options[1].values; var outContentSizes = ""; for (var i = 0; i < sizes.length; i++) { var id = "option-template--14375466827830__main-1-" + i; var oos = ""; var sku = ""; for (var v = 0; v < productObj.variants.edges.length; v++) { if (productObj .variants .edges[v] .node .selectedOptions[1] .value == sizes[i]) { if (productObj .variants .edges[v] .node .availableForSale) { oos = ""; } else { oos = "oos"; } sku = productObj .variants .edges[v] .node .sku; } } var stock = 'ins'; if (oos == 'oos') { stock = 'oos'; } outContentSizes += `
` + sizes[i] + ` `; } var sizesValues = document.querySelector(".SizeSwatchList"); sizesValues.innerHTML = outContentSizes; } function loadVariantIds(productObj) { const variantId = document.querySelector('[name="id"]'); const priceElems = document.querySelectorAll('.Price__Container, .ProductMeta__PriceList'); var elements = variantId.options; for (var i = 0; i < elements.length; i++) { elements[i].selected = false; } var idContent = ""; for (var v = 0; v < productObj.variants.edges.length; v++) { var disabled = ""; if (! productObj .variants .edges[v] .node .availableForSale) { disabled = 'disabled="disabled"'; } var id = productObj .variants .edges[v] .node .id .replace("gid://shopify/ProductVariant/", ""); // atob(productObj.variants.edges[v].node.id).slice(29); var color = productObj .variants .edges[v] .node .selectedOptions[0] .value; var size = productObj .variants .edges[v] .node .selectedOptions[1] .value; var price = productObj .variants .edges[v] .node .price; idContent += `
` + color + ` / ` + size + ` - ` + price + ` `; } variantId.innerHTML = idContent; var productid = productObj.id.replace("gid://shopify/Product/", ""); // atob(productObj.id).slice(22); const price0 = productObj .variants .edges[0] .node .price .amount; const compareAtPrice0 = productObj .variants .edges[0] .node .compareAtPrice != undefined ? productObj .variants .edges[0] .node .compareAtPrice .amount : 0; let priceContent = '
$' + parseInt(price0).toFixed(2) + ' '; priceContent = priceContent + ' '; if (compareAtPrice0 && price0 < compareAtPrice0) priceContent += '
$' + parseInt(compareAtPrice0).toFixed(2) + ' ' priceElems.forEach(function(price) { price.innerHTML = priceContent; }); var yotpoapi = new Yotpo.API(yotpo); yotpoapi.refreshWidgets(); } function loadThumbs(productObj) { console.log("Starting loadThumbs function") console.log("Product object received:", productObj) var thumbContent = "" var title = productObj.title console.log("Product title:", title) var imgSizes = [] var content = document.querySelector(".Product__SlideshowNavScroller") console.log("Slideshow content container:", content) var left = 0 content.innerHTML = '' console.log("Cleared innerHTML of the slideshow container.") for (var i = 0; i < productObj.images.edges.length; i++) { console.log(`Processing image ${ i + 1 } of ${ productObj.images.edges.length }`) var option = "" var name = productObj.images.edges[ i ].node.originalSrc console.log("Original source URL:", name) var cleanSize = '' var media_option = name.split("products/") console.log("Media option split by 'products/':", media_option) if (media_option != null && media_option.length > 1) { var media_detail = media_option[ 1 ].split(".jpg") console.log("Media detail split by '.jpg':", media_detail) if (media_detail != null && media_detail.length > 0) { var option_names = media_detail[ 0 ].split("_") console.log("Option names split by '_':", option_names) if (option_names != null && option_names.length > 0) { option = option_names[ option_names.length - 1 ] console.log("Last option name:", option) let pattern = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi let result = option.match(pattern) ? "Match" : "Not Match" console.log(`Regex match result for UUID: ${ result }`) if (result == "Not Match") { cleanSize = option console.log("Clean size:", cleanSize) if (imgSizes.indexOf(cleanSize) == -1) { imgSizes.push(cleanSize) } } else { option = option_names[ option_names.length - 2 ] cleanSize = option console.log("Fallback clean size:", cleanSize) if (imgSizes.indexOf(cleanSize) == -1) { imgSizes.push(cleanSize) } } } } } var id = productObj.images.edges[ i ].node.id.replace("gid://shopify/ProductImage/", "") console.log("Image ID:", id) if (cleanSize == '') { cleanSize = i.toString() console.log("Default clean size set to index:", cleanSize) } thumbContent += `
` } content.innerHTML = thumbContent console.log("Updated innerHTML with thumbnails.") var wearInfo = document.querySelector('.Product__Gallery__Info') console.log("Wear info container:", wearInfo) var wearingHtml = '' if (imgSizes.length == 1) { wearingHtml = '
Model is Wearing: ' + imgSizes[ 0 ] + '
' } else { wearingHtml = '
See on other sizes: ' imgSizes.forEach(function (size) { wearingHtml += '' }) } wearInfo.innerHTML = wearingHtml console.log("Updated wear info with size options.") // Clearing references thumbContent = null title = null imgSizes = null content = null left = null console.log("Cleared all internal references.") } function MoveImage(type) { var tbButtons = document.querySelectorAll('.Product__SlideshowMobileNav button'); var pos = 0; var move = 0; for (var i = 0; i < tbButtons.length; i++) { if (tbButtons[i].classList.contains('is-selected')) { move = i; if (type == 'N') { pos = i + 1; if (pos > tbButtons.length) { pos = tbButtons.length - 1; } } else { pos = i - 1; if (pos <= 0) { pos = 0; } } } }// var move = tbButtons[pos].getAttribute('data-position');// if(move == undefined){// move = "2.5";// pos = 0;// } if ((pos - 1) >= 0) { changeImage(move, pos - 1); } } function loadGallery(productObj) { allGalleryImgs.length = 0; var galleryContent = ""; var title = productObj.title; var content = document.querySelector(".flickity-viewport"); var flickityElem = content.parentElement; Flickity.data(flickityElem).destroy(); content.innerHTML = ''; var left = 2.5; for (var i = 0; i < productObj.images.edges.length; i++) { var option = ""; var img = productObj .images .edges[i] .node .originalSrc; var id = productObj .images .edges[i] .node .id .replace("gid://shopify/ProductImage/", ""); // atob(productObj.images.edges[i].node.id).slice(29); var arrImg = img.split(".jpg"); var imgDataSource = ""; for (var p = 0; p < 8; p++) { var pos = 0; if (p == 3) { pos = 700; } else if (p == 5) { pos = 900; } else { pos = p + 200; } if (p == 7) { imgDataSource += arrImg[0] + `_` + pos + `x.jpg` + arrImg[1] + ` ` + pos + `w`; } else { imgDataSource += arrImg[0] + `_` + pos + `x.jpg` + arrImg[1] + ` ` + pos + `w, `; } }// if (i == 0) { galleryContentImg = `
`;// } else {// left += 92.5;// galleryContentImg =// `
`;// } galleryContent += galleryContentImg; allGalleryImgs.push(document.createRange().createContextualFragment(galleryContentImg).childNodes[0]); } allGalleryImgs = Array.from(allGalleryImgs); flickityElem.innerHTML = galleryContent; new Flickity(flickityElem, JSON.parse(flickityElem.dataset.flickityConfig)); } function changeImage(pos, id) { var container = document.querySelector(".flickity-slider"); container.style.transform = "translateX(" + pos + ")"; let elements = document.getElementsByClassName("Product__SlideItem--image"); for (let i = 0; i < elements.length; i++) { elements[i].classList.add("Product__SlideItem--hidden--custom"); elements[i].classList.remove("is-selected"); var data_id = elements[i].getAttribute("data-media-id"); if (data_id == id) { elements[i].classList.add("is-selected"); elements[i].classList.remove("Product__SlideItem--hidden"); elements[i].classList.remove("Product__SlideItem--hidden--custom"); } } } function loadRelatedProducts(handles) { var content = `
`; content += `
`; var productAside = document.querySelector(".Product__Aside__Content"); productAside.innerHTML = content; productAside.style.display = "none"; handles.forEach((handle) => { this.productByHandle(handle, false).then((res) => {}); }); } function writeRelatedProduct(productObj) { var content = ``; var img = productObj .images .edges[0] .node .originalSrc; var id = atob(productObj .images .edges[0] .node .id).slice(29); var price = productObj .variants .edges[0] .node .price; var arrImg = img.split(".jpg"); var imgDataSource = ""; for (var i = 0; i < 7; i++) { var pos = i + 200; if (i == 6) { imgDataSource += arrImg[0] + `_` + pos + `x.jpg` + arrImg[1] + ` ` + pos + `w`; } else { imgDataSource += arrImg[0] + `_` + pos + `x.jpg` + arrImg[1] + ` ` + pos + `w, `; } } content += `
`; content += `
`; content += `
`; content += ``; content += ``; content += ``; content += ``; content += ``; content += ` `; content += `
`; content += `
` + productObj.title + ` `; content += `
`; content += `` + price + ` `; content += `
`; content += `
`; content += `
`; content += `View product `; content += `
`; content += `
`; var productAside = document.querySelector(".Product__Aside__Content"); productAside.innerHTML += content; productAside.style.display = "block"; } function selectVariant(sku) { const variantId = document.querySelector('[name="id"]'); var elements = variantId.options; for (var i = 0; i < elements.length; i++) { elements[i].selected = false; } for (var i = 0; i < elements.length; i++) { var datasku = elements[i].getAttribute("data-sku"); if (datasku == sku) { elements[i].selected = true; } } } function productByHandle(handle, load) { console.log("productByHandle: ", handle, load ); const productQuery = `{ productByHandle(handle: \"${handle}\") { ${productSchema} } }`; return this.sendQuery(productQuery).then((res) => { console.log("productByHandle query response: ", res) if (res.data && res.data && res.data.productByHandle) { const resData = res.data.productByHandle; return this.formatObject(resData, load); } return res; }); } function checkComparePrice(variant) { if (variant) { if (variant.compare_at_price) return variant.compare_at_price && Number(variant.compare_at_price) > Number(variant.price); else return variant.compareAtPrice && Number(variant.compareAtPrice) > Number(variant.price); } return null; } function money(num) { const formattedPrice = (num * 1).toFixed(0); return `${formattedPrice}`; } function sendQuery(query) { console.log("sendQuery: ", query);// graphql request, params, headers and configs const headers = { "Content-Type": "application/json", "X-Shopify-Storefront-Access-Token": token, Accept: "application/json" }; const body = JSON.stringify({query, variables: {}}); window.body = body; return axios({headers, method: "post", data: body, url: "https://curvy-couture-innovation.myshopify.com/api/2023-07/graphql.json"}).then((result) => { return result.data; }).catch((error) => { console.log(error); }); } function formatObject(obj, load) {// removing edges and nodes in graphql response const originalObj = { ... obj }; let newObj = originalObj.products && originalObj.products.edges ? originalObj.products : originalObj; if (load) { loadProduct(newObj); } else { writeRelatedProduct(newObj); } if ((originalObj.products && originalObj.products.edges) || originalObj.edges) newObj = newObj.edges.map(({node}) => node); return newObj; }