function startDetails() { // http://127.0.0.1:5502/productdetails.html?productId=106633230000024 if (window.location.search.split('=')[0] == '') { window.location.href = "/notfound.html"; return; } let productId = window.location.hash.split('#')[1].split('=')[1]; // console.log(productId); let itemtagscombinationRes = null; let labels = {}; let isThereInLabel = {}; let currentComb = null; let colorId = null; let group = {}; let loadingActions = { addLoader() { $('.loadingCall').removeClass('d-none'); $('.mainContanierProduct').addClass('d-none'); }, removeLoader() { $('.loadingCall').addClass('d-none'); $('.mainContanierProduct').removeClass('d-none'); } } let currentClick = null; if (productId) { swapSectionsVideo(); loadingActions.addLoader(); updateProductId(productId); getProductDetails(productId); appendSpecs(productId) } else { window.location.href = "/notfound.html" } function updateProductId(val) { $('#productidtag').val(val); } function updateItemId(val) { $('#itemidtag').val(val); } let specification_wrap_action = { remove() { $('.specification-wrap').addClass('d-none'); }, add() { $('.specification-wrap').removeClass('d-none'); } } let description_action = { addVal(value) { $('.description-wrap > p').html(value); }, removeVal(value) { $('.description-wrap > p').html(''); } } function getSpecsItemHTML({ name, des, itemid, id }) { let isMobile = $(window).width()<=600 ? '' : ''; let addPaddM = $(window).width()<=600 ? 'py-2' : 'py-4'; return `
${name}
${des}
`; } // function getSpecsItemHTML({name,des,itemid,id}){ // return ` // ${name} // ${des} // `; // } async function appendSpecs(id) { let resData = await API_SERVICES_ACTIONS.getAPIService(`apis/v4/bizgaze/integrations/products/itemspecifications/itemid/${id}`, true); if (resData.isError) { $('.productdetailstabs').addClass('d-none'); $('.specContainerleft').html('') $('.specContainerRight').html('') return; } $('.productdetailstabs ').removeClass('d-none'); const res = resData.response; // console.log(JSON.parse(res.result)); const data = JSON.parse(res.result); // console.log(data); let html = ''; let leftHtml = ''; let rightHtml = ''; if (data.length == 0) { $('.productdetailstabs ').addClass('d-none'); $('.specContainerleft').html('') $('.specContainerRight').html('') return; } for (let i = 0; i < data.length; i++) { const { specificationname, specificationitemid, itemid, description } = data[i]; if ((i + 1) % 2 == 0) { rightHtml += getSpecsItemHTML({ name: specificationname, id: specificationitemid, itemid, des: description }) } else { leftHtml += getSpecsItemHTML({ name: specificationname, id: specificationitemid, itemid, des: description }); } } $('.specContainerleft').html(leftHtml) $('.specContainerRight').html(rightHtml) } function getParentHTML(name, productid, id, isMain) { return ``; } function onClickHandler(e) { $(e).parent().find('.borderselector').removeClass('borderselector'); $(e).addClass('borderselector') } function getChildHTML(tagid, name, isTrue,parentid) { let blue = '#253746'; let greenLight = '#5e7975'; let brown = '#624839'; let bgColor = ''; if(name === 'Deep Sea Blue'){ bgColor = blue; }else if(name == 'Desert Brown'){ bgColor = brown; }else if(name == 'Eucalyptus Green'){ bgColor = greenLight; } if(colorId == parentid){ return `
` } return `
${name}
` } function addeventlisteners() { $('.optiontaganwi').each(function (i, el) { $(el).click(function (e) { $('#quantity').val(1); $(e.target).parent().find('.borderselector').removeClass('borderselector'); $(e.target).addClass('borderselector'); currentClick = e.target; ; //searchComb(); // getAllCombination(); getandsetCombination(); }) }); } function getandsetCombination(){ let keyOption = $(currentClick).data('tagiditem'); $('.disabled-option-item').removeClass('disabled-option-item'); let tagsNames = []; let currOptionAvaIds = {}; $('.borderselector').each(function (i,e){ let id = $(e).data('tagiditem'); tagsNames.push(id); }); for(let i=0;i1){ arrtwo = parentArr[1]?.arr; } let currId = keyOption; let ids = []; for(let i=0;i img').attr('src', defaultImg); specification_wrap_action.remove(); $('#skudetailitem').val(-1) $('.productname').html(itemsName) $('.msgErrorDetailsItem').removeClass('d-none'); $('.des_productdes').html(''); $('.price').html(''); } initAddToCart() return; } } // return; return; let commonTags = []; // $('.optiontaganwi').addClass('disabled-option-item') for(let i=0;i${currencySymbol}${amount}${commingSoonText?'Coming Soon':''}` : 'coming soon'); $('.price').attr('data-price',obj.pricelist); appendSpecs(obj.itemid) $('#skudetailitem').val(obj.sku) $('.des_productdes').html(obj.itemdescription); $('#addtocart').attr('data-qty', obj.quantity); let defaultImg = obj.itemimageurl ? imgServerNameBuild(obj.itemimageurl) : `./dist/assets/imgs/nophoto.png`; // console.log(obj.itemimageurl, 'obj.itemimageurlobj.itemimageurlobj.itemimageurl'); debugger; let productId = window.location.hash.split('#')[1]?.split('=')[1]; let itemId = window.location.hash.split('#')[2]?.split('=')[1]; history.replaceState(undefined, undefined, `#productId=${productId}#itemid=${obj.itemid}`) $('.productDetailsMain > img').attr('src', defaultImg).attr('loading','lazy'); updateItemId(obj.itemid); //console.log(obj,'objobjobj'); if (!obj.pricelist || !obj.quantity) { $('.buynow').attr('disabled', true); $('#addtocart').attr('disabled', true); } else { $('.buynow').attr('disabled', false); $('#addtocart').attr('disabled', false); } } function searchComb() { let valuesSelected = []; $('.optiontaganwi').removeClass('disabled-option-item') $('#addtocart').removeClass('disabled'); $('.msgErrorDetailsItem').addClass('d-none'); $('.borderselector,border_selector').each(function (i, el) { // console.log($(el).html()) let val = $(el).data('tagiditem'); valuesSelected.push(val); }); let labelRecord = {}; for (let label in labels) { labelRecord[label] = false; } specification_wrap_action.add(); let unFiler = null; for (let i = 0; i < itemtagscombinationRes.length; i++) { const currItem = itemtagscombinationRes[i]; const { tagids } = currItem; let isTrue = true; let labelFilter = labelRecord; for (let i = 0; i < valuesSelected.length; i++) { if (!tagids.includes(valuesSelected[i])) { isTrue = false unFiler = labelFilter; break; } labelFilter[group[valuesSelected[i]]] = true; } if (isTrue) { // console.log(itemtagscombinationRes[i], 'itemtagscombinationRes[i]'); const { quantity } = itemtagscombinationRes[i]; if (quantity >= $('#quantity').val() && quantity >= 1) { currentComb = itemtagscombinationRes[i]; // $('.productname').html(itemtagscombinationRes[i].itemname) // $('.price').html(itemtagscombinationRes[i].pricelist); // location.hash = itemtagscombinationRes[i].itemname.trim(); // appendSpecs(itemtagscombinationRes[i].itemid) // history.replaceState(null, null, `#itemid=${itemtagscombinationRes[i].itemid}#${itemtagscombinationRes[i].itemname.trim()}`); // $('#skudetailitem').val(itemtagscombinationRes[i].sku) // $('.des_productdes').html(itemtagscombinationRes[i].itemdescription); updateDetailsByObj(itemtagscombinationRes[i]); } else { let name = itemtagscombinationRes[i].itemname.split('-')[0]; $('#addtocart').addClass('disabled'); let itemsName = name; $('.borderselector').each(function (i, e) { itemsName += ` ${$(e).html().trim()}`; }); updateItemId(null); let defaultImg = itemtagscombinationRes[i].itemimageurl ? imgServerNameBuild(itemtagscombinationRes[i].itemimageurl) : `./dist/assets/imgs/nophoto.png`; // console.log(itemtagscombinationRes[i].itemimageurl, 'obj.itemimageurlobj.itemimageurlobj.itemimageurl'); $('.productDetailsMain > img').attr('src', defaultImg); specification_wrap_action.remove(); $('#skudetailitem').val(-1) $('.productname').html(itemsName) // history.replaceState(null, null, `#`); $('.msgErrorDetailsItem').removeClass('d-none'); $('.des_productdes').html(''); $('.price').html(''); } initAddToCart() return; } } alert("j"); let name = itemtagscombinationRes[0].itemname.split('-')[0]; let itemsName = name; $('.borderselector').each(function (i, e) { itemsName += `- ${$(e).html().trim()}`; }) specification_wrap_action.remove(); $('.productname').html(itemsName) $('#skudetailitem').val(-1) $('.price').html(''); $('#addtocart').addClass('disabled'); $('.msgErrorDetailsItem').removeClass('d-none'); initAddToCart() } function getAllCombination() { debugger; const currClickAttr = $(currentClick).html().trim(); const optionId = $(currentClick).data('tagiditem'); let curr = $(currentClick).parents('.groupingitems_search').data('parentidgroup'); $('.groupingitems_search').each(function (i, e) { const id = $(e).data('parentidgroup'); if (id != curr) { $(e).find('.optiontaganwi').addClass('disabled-option-item'); $(e).find('.borderselector').removeClass('borderselector'); } }); let ansArr = []; let index = 0; let comb = null; for(let i=0;i