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.href.split('=')[1].split('&')[0].split('#')[0];
console.log(productId);
let itemtagscombinationRes = null;
let labels = {};
let isThereInLabel = {};
let currentComb = 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) {
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 }) {
return `
`;
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) {
let item_color_1 = `#5e7975`;
let item_color_2 = `#624839`;
let item_color_3 = `#253746`;
if(name == "Eucalyptus Green"){
return `${name}
`;
}else if(name == "Desert Brown"){
return `${name}
`;
}else if(name == "Deep Sea Blue"){
return `${name}
`;
}
else{
return `
${name}
`
}
}
function addeventlisteners() {
$('.optiontaganwi').each(function (i, el) {
$(el).click(function (e) {
$('#quantity').val(1);
debugger;
let ele_col = $(e.target).hasClass("color");
let ele_col1 = $(e.target).hasClass("optiontaganwi_color");
if(ele_col === true){
$(e.target).parent().find("span.color").removeClass('border-bottom');
$(e.target).parent().addClass("border_selector");
$(e.target).addClass("border-bottom");
$(e.target).parent().find("span.border-bottom").removeClass("border-bottom text-dark");
$(e.target).addClass("border_selector");
$(e.target).find("span.color").addClass("border-bottom text-dark");
$(e.target).parent().find('.borderselector').removeClass('borderselector');
// $(e.target).addClass('borderselector');
searchComb();
currentClick = e.target;
}else if(ele_col1 === true){
$(e.target).parent().find("span.text-dark").removeClass("text-dark border-bottom");
$(e.target).addClass("border_selector");
$(e.target).find("span.color").addClass("text-dark");
$(e.target).parent().find('.borderselector').removeClass('borderselector');
$(e.target).addClass('borderselector');
searchComb();
currentClick = e.target;
}else{
$(e.target).parent().find('.borderselector').removeClass('borderselector');
$(e.target).addClass('borderselector');
searchComb();
currentClick = e.target;
}
searchComb();
currentClick = e.target;
// getAllCombination();
})
});
// $('.optiontaganwi_color span.color').each(function (i, el) {
// $(el).click(function (e) {
// $('#quantity').val(1);
// $(e.target).parent().find("span.border-bottom").removeClass("border-bottom");
// $(e.target).addClass("border-bottom");
// searchComb();
// currentClick = e.target;
// // getAllCombination();
// })
// });
}
// function getChildHTML(tagid,name,isTrue){
// 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')
// searchComb();
// currentClick = e.target;
// // getAllCombination();
// })
// });
// }
function updateDetailsByObj(obj) {
$('.productname').html(obj.itemname)
$('.price').html(obj.pricelist?obj.pricelist:'coming soon');
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');
$('.productDetailsMain > img').attr('src', defaultImg);
updateItemId(obj.itemid);
if(!obj.pricelist){
$('.buynow').attr('disabled',true);
$('#addtocart').attr('disabled',true);
}else{
$('.buynow').attr('disabled',false);
$('#addtocart').attr('disabled',false);
}
}
function searchComb() {
let valuesSelected = [];
$('#addtocart').removeClass('disabled');
$('.msgErrorDetailsItem').addClass('d-none');
$('.borderselector,border_selector').each(function (i, el) {
console.log($(el).html())
let val = $(el).html();
valuesSelected.push(val.trim());
});
let labelRecord = {};
for (let label in labels) {
labelRecord[label] = false;
}
console.log(labelRecord);
specification_wrap_action.add();
console.log(group);
let unFiler = null;
for (let i = 0; i < itemtagscombinationRes.length; i++) {
const currItem = itemtagscombinationRes[i];
const { tagnames } = currItem;
let isTrue = true;
let labelFilter = labelRecord;
for (let i = 0; i < valuesSelected.length; i++) {
if (!tagnames.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);
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;
}
}
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() {
const currClickAttr = $(currentClick).html().trim();
let isThere = [];
for (let item in isThereInLabel) {
let { tagnames } = isThereInLabel[item];
if (tagnames.includes(currClickAttr)) {
isThere.push(isThereInLabel[item])
}
}
let selected = [];
$('.borderselector').each(function (i, e) {
selected.push($(e).html().trim())
});
// console.log(selected);
// console.log(isThere);
let ishashObj = {};
for (let i = 0; i < isThere.length; i++) {
let { tagnames, tagids } = isThere[i];
tagnames = tagnames.split('|');
tagids = tagids.split('|');
for (let j = 0; j < tagnames.length; j++) {
if (!ishashObj[tagnames[j]]) {
ishashObj[tagnames[j]] = tagids[j];
}
}
}
// console.log(ishashObj);
// for(let i=0;i