').append($link).html(); // console.log(ownersManual_Data,"ownersManual_Data:"); var explodedView = jsonData.exploded_veiw_btn; if(explodedView){ // var ownersManual_DD = 'https://encompass.com/'+ ownersManual_Data +'' ; $('.btncustomid ').append(explodedView); }else{ $('.btncustomid ').hide(); } if(ownersManual_Data){ // var ownersManual_DD = 'https://encompass.com/'+ ownersManual_Data +'' ; $('#owner_manuals').append(ownersManual_Data); }else{ $('#owner_manuals').hide(); } var serviceManual_Data = jsonData.data.data.serviceManualLink; // console.log("serviceManual_Data",serviceManual_Data) var $linkser = $(serviceManual_Data); // console.log("$linkser",$linkser) var href = $linkser.attr('href'); // console.log("href",href) $linkser.attr('href', 'https://encompass.com' + href); serviceManual_Data = $('
').append($linkser).html(); // console.log(serviceManual_Data,"serviceManual_Data:"); if(serviceManual_Data){ $('#service_Manual').append(serviceManual_Data); }else{ $('#service_Manual').hide(); } var partNumArray = []; if(productParts){ productParts.forEach(function(part) { // console.log("part",part) // var titleData = { // mfgName: part.mfgName, // partNumber: part.partNumber, // partDescription: part.partDescription // }; var partMfgName = part.mfgName; var partNumber = part.partNumber; partNumArray.push(partNumber); var partDescription = part.partDescription; var partPrice = part.partPrice; var imagePath = part.picturePath; var partBasePN = part.basePN; // console.log("imagePathimagePath>>",imagePath,partPrice) // console.log("titleData",titleData) // var Divappend = `
//
//
${partMfgName} ${partNumber} ${partDescription}
//
//
// //
//
//
${partPrice}
//
//
// Add to Cart //
//
` // // console.log("DivappendDivappend",Divappend) // $('#product-append').append(Divappend); }); } // console.log(" partNumArray>>>>",partNumArray) const queryParts = partNumArray.join(" OR "); // console.log("queryParts",queryParts) var storefront_AccessToken = '275e2c2c71750cf915068494bbd5c366'; async function getProduct_Details() { var productArray = []; // for (i=0; i<=10; i++) { // console.log("partNumArray[i]partNumArray[i]",partNumArray[i]) const product_response = await fetch("https://bertazzoniparts.myshopify.com/api/2023-04/graphql.json", { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Shopify-Storefront-Access-Token': storefront_AccessToken, }, body: JSON.stringify({ query: `{ products(query: "${queryParts} AND product_type:Part", first: 250) { nodes { id title description handle tags vendor variants(first: 250) { nodes { id sku priceV2 { amount currencyCode } } } images(first: 1) { nodes { originalSrc } } } } } `, }), }); // console.log("product_response",product_response) const product_result = await product_response.json(); // console.log("product_result",product_result) if (product_result.data.products) { productArray.push(product_result.data.products); } // } // console.log("productPartsproductParts>>>", productParts);// console.log("productArrayproductArrayproductArray", productArray);var allParentNodes = [];// console.log("productPartsproductParts>>>", productParts);// console.log("productArrayproductArrayproductArray", productArray);// Copying the productParts arrayvar copiedProductParts = [...productParts];// Array to store matched SKUsvar matchedSKUs = [];// Loop through productArray to find matchesfor (var j = 0; j < productArray[0].nodes.length; j++) { var productNode = productArray[0].nodes[j]; var variants = productNode.variants.nodes; // Correctly access the node's variants // Loop through variants nodes for (var k = 0; k < variants.length; k++) { var storefrontSKU = variants[k].sku.toLowerCase(); // Convert to lowercase // Find the index of the matched part number in the copied array var matchedIndex = copiedProductParts.findIndex(part => part.partNumber.toLowerCase() === storefrontSKU); // If a match is found, remove the matched part number from the copied array if (matchedIndex !== -1) { matchedSKUs.push(productNode); // Store the full product object copiedProductParts.splice(matchedIndex, 1); break; // Break to avoid duplicate entries for the same product } }}// Push matched SKUs into allParentNodesif (matchedSKUs.length > 0) { allParentNodes.push({ nodes: matchedSKUs });}// Push the remaining unmatched partscopiedProductParts.forEach(part => { allParentNodes.push({ node: [part] });});// console.log("allParentNodes", allParentNodes); if(allParentNodes){ // console.log("all nodes Done") var subcatArray = []; var webcatArray = []; var categoryArray = []; allParentNodes.forEach(function(Data) { // console.log("DataData",Data) if (Data.nodes) { // console.log("Data.nodes",Data.nodes) var dataNode = Data.nodes let nodesWithoutImages = []; // Iterate over the array from the beginning for (let i = 0; i < Data.nodes.length; i++) { let node = Data.nodes[i]; // Check if the node has no originalSrc in images if (!node.images || node.images.nodes.length === 0 || !node.images.nodes[0].originalSrc) { nodesWithoutImages.push(node); // Store nodes without images Data.nodes.splice(i, 1); // Remove the node from the original array i--; // Adjust the index after removal } } // Push nodes without images to the end of the original array dataNode.push(...nodesWithoutImages); // console.log(dataNode,"new Data.nodes "); dataNode.forEach(node => { // console.log("node",node) const partTitle = node.title; const proVen = node.vendor; // console.log("proVen:", proVen); const partHandle = node.handle; // console.log("Handle:", partHandle); const partDescription = node.description; // console.log("Description:", node.description); var parttags = node.tags; // console.log("parttagsparttags", parttags) if (parttags && parttags.length > 0) { parttags.forEach(function(tag) { if (tag.startsWith("subcate:")) { subcatArray.push(tag.split(":")[1]); } else if (tag.startsWith("webcat:")) { webcatArray.push(tag.split(":")[1]); } }); } // const webcatTags = parttags.filter(tag => tag.startsWith("webcat:")); // console.log("webcatTags",webcatTags); // const webcatTagsSTR = webcatTags[0].split(":")[1].trim(); // console.log("webcatTagsSTR",webcatTagsSTR); // console.log("node.variantsnode.variants",node.variants.nodes[0].priceV2) // if (node.variants && node.variants.nodes.length > 0) { // console.log("SKU:", node.variants.nodes[0].sku); const partprice = node.variants.nodes[0].priceV2.amount; const variantId = node.variants.nodes[0].id; // console.log("variantId:",variantId) var partvariantId = variantId.split('/').pop(); // console.log("partvariantId:",partvariantId) // console.log("partprice null vartaint ",partprice) // } let partImage = ''; if (node.images && node.images.nodes.length > 0) { partImage = node.images.nodes[0].originalSrc; // console.log("Image Path:", node.images.nodes[0].originalSrc); // Assuming images have a path property }else{ // console.log("Brandlinecode>>>2",Brandlinecode) // var newApiImage = 'https://encompass-11307.kxcdn.com/imageDisplay?mfgCode='+ Brandlinecode + '&type=b&size=s'; // console.log("newApiImage",newApiImage) partImage = 'https://encompass-11307.kxcdn.com/imageDisplay?mfgCode='+ Brandlinecode + '&type=b&size=s'; } // console.log("partImage",partImage) // let partImage1; // if (node.images && node.images.nodes && node.images.nodes.length > 0 && node.images.nodes[0].originalSrc) { // partImage1 = node.images.nodes[0].originalSrc; // console.log("Image Path:", partImage); // } else { // partImage1 = "path/to/demo-image.jpg"; // Replace this with the actual path to your demo image // console.log("Image not found. Using demo image:", partImage1); // } if(proVen == "Carrier"){ // console.log("proVen:1", "Carrier"); var Divappend = `
${partTitle}
$${partprice}
Contact support
` // console.log("DivappendDivappend",Divappend) $('#product-append').append(Divappend); } $('.loader_product').css('display','none') $('.divconatin').each(function() { let partprice = parseFloat($(this).find('a').text().replace('$', '')); // Extract the price and convert to a number if(partprice <= 1.0 || partprice === "CALL" ){ // console.log("Price Less than or equal to 1.0"); $(this).css('display','none'); // Hide this div $(this).next('.Cont_support').css('display', 'block'); // $(this).next('.divbttn').css('display', 'none'); } else { // console.log("Price Greater Than 1.0"); $(this).next('.Cont_support').css('display', 'none'); } }); // $('.Cont_support').each(function() { // let partprice = parseFloat($(this).find('a').text().replace('$', '')); // Extract the price and convert to a number // if(partprice <= 1.0 || partprice === "CALL" ){ // console.log("Price Less than or equal to 1.0"); // // $(this).css('display','none'); // Hide this div // $(this).find(".Cont_support").css('display','block'); // } else { // console.log("Price Greater Than 1.0"); // } // }); }); } if (Data.node) { Data.node.forEach(node => { // console.log("node for encompass data ",node) const partmfgCode = node.mfgCode; const partBasePN = node.basePN; // console.log("partBasePN",partBasePN) const partCategoryName = node.categoryName; // console.log("partCategoryName",partCategoryName) var formattedCategoryName = partCategoryName.split(',').map(category => category.trim()).join(' | '); // console.log("formattedCategoryName", formattedCategoryName); const categoriesArray = partCategoryName.split(','); // console.log("categoriesArray",categoriesArray) // Iterate over each category and log it // $.each(categoriesArray, function(index, category) { // const trimmedCategory = $.trim(category); // Trim leading/trailing spaces // console.log(`Category ${index + 1}:`, trimmedCategory); // var formattedCategoryName = partCategoryName.split(',').map(category => category.trim()).join(' | '); webcatArray.push(formattedCategoryName) // Perform additional operations if needed, e.g., append to a list // $('#sidebar_webcat_list_item').append(`
`); // }); // if (formattedCategoryName && formattedCategoryName.length > 0) { // console.log("for Part Tag") // formattedCategoryName.forEach(function(tag) { // if (tag.startsWith("subcate:")) { // subcatArray.push(tag.split(":")[1]); // } else if (tag.startsWith("webcat:")) { // webcatArray.push(tag.split(":")[1]); // } // }); // } categoryArray.push(partCategoryName); const partMfgName = node.mfgName; const partDescription = node.partDescription; const partNumber = node.partNumber; // console.log("partNumber",partNumber) const imagePath = node.picturePath; // console.log("imagePath",imagePath) const partPrice = node.partPrice; // console.log("partprice>>>",partPrice) if (partCategoryName && partCategoryName.length > 0) { // partCategoryName.forEach(function(tag) { // if (tag.startsWith("subcate:")) { // subcatArray.push(tag.split(":")[1]); // } else if (tag.startsWith("webcat:")) { // webcatArray.push(tag.split(":")[1]); // } // }); } let finalPath; if (imagePath.startsWith("http")) { // If imagePath starts with 'http', use the same path finalPath = imagePath; } else { // If imagePath does not start with 'http', prepend the necessary URL const finalPath2 = "https://encompass-11307.kxcdn.com/imageDisplay?" + imagePath + '&type=b&size=s'; finalPath = finalPath2.replace(/([?&]size=)[^&]*/, '$1s'); } // Modify the thumbnail size if it exists in the URL finalPath = finalPath.replace(/(thumbnail=)\d+/, '$1500'); // console.log("finalPath", finalPath); // finalPath = finalPath.replace(/([?&]size=)[^&]*/, '$1s'); // console.log("New finalPath",finalPath); var Divappend = `
${partMfgName} ${partNumber}
$${partPrice}
Contact support
` // console.log("DivappendDivappend",Divappend) $('#product-append').append(Divappend); $('.loader_product').css('display','none') $('.divconatin').each(function() { let partprice = parseFloat($(this).find('a').text().replace('$', '')); // Extract the price and convert to a number // console.log("partprice>><<<", partprice); if (isNaN(partprice) || partprice <= 1.0) { // console.log("Price is NaN or Less than or equal to 1.0"); $(this).css('display', 'none'); // Hide this div $(this).next('.Cont_support').css('display', 'block'); } else { // console.log("Price Greater Than 1.0"); $(this).next('.Cont_support').css('display', 'none'); } }); // }); }); } }); // function redirecFunc(pnob) { // jQuery.ajax({ // url: `https://partstore-com.myshopify.com/products/${pnob}`, // type: 'GET', // success: function(data){ // console.log("redirect1"); // } // }); // setTimeout(function () { // console.log("redirect2"); // window.location.href = `https://partstore-com.myshopify.com/products/${pnob}`; // }, 3000) // } // console.log("Category Array:", categoryArray) // console.log("Subcat Array:", subcatArray); // console.log("Webcat Array:", webcatArray); var subcatLi = ''; var webcatLi = ''; var categoryLi = ''; const uniqueCategoryItems = new Set(); const uniqueSubcatItems = new Set(); const uniqueWebcatItems = new Set(); setTimeout(function () { $.each(subcatArray, function(index, item) { if (!uniqueSubcatItems.has(item)) { uniqueSubcatItems.add(item); subcatLi += '
'; $(".loader").hide(); } }); $('#sidebar_webcat_list_item_by_shopify').append(subcatLi); // $(document).find(".categories-filters").show(); webcatArray.sort(); $.each(webcatArray, function(index, item) { if (!uniqueWebcatItems.has(item)) { uniqueWebcatItems.add(item); webcatLi += '
'; $(".loader").hide(); } }); $('#sidebar_webcat_list_item').append(webcatLi); // $(document).find(".web-categories-filters").show() $.each(categoryArray, function(index, item) { if (item && !uniqueCategoryItems.has(item)) { uniqueCategoryItems.add(item); // console.log("item>>>", item); // var formattedItem = item.split(',').map(category => category.trim()).join(' | '); // console.log("formattedItem", formattedItem); // if (formattedItem) { // Check if formattedItem is not blank // categoryLi += '
'; // } $(".loader").hide(); } }); $('li.webcat_list_item').each(function() { // console.log("clicked li filter ") var spanText = $(this).find('span').text().trim(); // Get the text inside the span and trim any whitespace if (spanText === '') { // console.log("clicked li filter inside the if condition") $(this).hide(); // Hide the li element if the span is empty } }); $('#sidebar_webcat_list_item').append(categoryLi); }, 2000); } } getProduct_Details() } } }); $(document).on('click','.pred-list-items',function(){ var symptomid = $(this).attr("pred-id"); $(".pred-list-items").removeClass("active"); $(this).addClass("active"); jQuery(".loading").css('display','block'); var origin = window.location.origin; var explode_str = origin.split("//"); var shop = explode_str[1]; var model_apiId = 'CAR24ACA460C0030010'; var model_number = '24ACA460C0030010'; var model_variation = 'Default Title'; var model_brand = "LG"; if(model_apiId == '') { model_apiId = 'ZEN'+model_number; } //console.log("selected",model_variation); var user_id = ''; var product_handle = 'carrier-model-24aca460c0030010'; var variantCount = '1'; var ids = '8011087773854'; partpredictionapi(shop,model_number,model_variation,model_brand,symptomid) }) $(document).on("click", "#partpredmodel .view_product_details", function(){ var partnum = $(this).attr('partnum'); $('#loading').show(); jQuery.getJSON(window.Shopify.routes.root + 'products/'+partnum+'.js', function(product) { var variant_id = product.variants[0].id; //console.log(variant_id); if(variant_id){ Toaddcart(variant_id); }else{ window.location = "https://lgparts.com"; } } ); function Toaddcart(variant_id){ let formData = { 'items': [{ 'id': variant_id, 'quantity': 1 }] }; fetch(window.Shopify.routes.root + 'cart/add.js', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }) .then(response => { $("#partpredmodel").hide() $("#js_cart_popup").addClass("act_opened"); // $(".cart-block").click() //console.log(response.json()); //window.location = "https://samsungpartsusa.com/cart"; }) .catch((error) => { console.error('Error:', error); //window.location = "https://samsungpartsusa.com/"; }); } }) jQuery(document).on('click','.closed', function(){ // window.location = window.location.href; $(document).find("#partpredmodel .mdlsngle-nsec-row").remove(); $(document).find("#partpredmodel .pred-list-items").removeClass("active"); }); }); $(document).on('click',".modellistpara,.add_to_cart_encompass",function(){ // $('.loader_modelpage').addClass('loader_active'); // $('.template-product').addClass('body_blur'); handleClick(this); });
'; // console.log("cat_Html", cat_Html); $('.collection_Title').append(cat_Html); } }); } }); } getCollHandle()