123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589 |
- function startDetails(){
- // http://127.0.0.1:5502/productdetails.html?productId=106633230000024
- if(window.location.search.split('=')[0] == ''){
- window.location.href = "/notfound.html";
- return;
- }
- debugger;
- 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}){
- let isMobile = $(window).width()<=600 ? '' : '';
- let addPaddM = $(window).width()<=600 ? 'py-2' : 'py-4';
- return `<div id="${id}" data-specitemid="${itemid}" >
- <div class="row border-bottom">
- <div class="col-sm-3 ${isMobile} font-weight-600 ${addPaddM} ">
- ${name}
- </div>
- <div class="col-sm-9 py-2 d-flex align-items-center">
- ${des}
- </div>
- </div>
- </div>`;
- return ` <tr id="${id}" data-specitemid="${itemid}">
- <td style="width:200px">${name}</td>
- <td class="">${des}</td>
- </tr>`;
- }
- // function getSpecsItemHTML({name,des,itemid,id}){
- // return ` <tr id="${id}" data-specitemid="${itemid}">
- // <td style="width:200px">${name}</td>
- // <td class="">${des}</td>
- // </tr>`;
- // }
-
- 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];
- leftHtml += getSpecsItemHTML({
- name:specificationname,id:specificationitemid,itemid,des:description
- });
- // 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 `<div class="pb-2 $${name?.replace(" ",'')}-parent">
- <h5 class="py-2 smallHeadingProductDetails">${name}</h5>
- <div class="d-flex gap-2 flex-wrap ${id}container" data-tagid="${id}">
-
- </div>
- </div>`;
- }
-
- function onClickHandler(e) {
-
- $(e).parent().find('.borderselector').removeClass('borderselector');
-
- $(e).addClass('borderselector')
-
- }
-
- function getChildHTML(tagid,name,isTrue){
- return `
- <div data-type="${tagid}-${name}" data-tagiditem="${tagid}" class="specsmallcard optiontaganwi ${isTrue?'borderselector':''} card small-font cursor-pointer p-3">
- ${name}
- </div>
- `
- }
-
- 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);
- let [currencySymbol, amount] = getCurrencySymbol(obj?.pricelist||0);
- $('.price').html(obj.pricelist ?`${currencySymbol}${amount}`:'');
- $('.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');
-
- $('.productDetailsMain > img').attr('src',defaultImg);
-
- updateItemId(obj.itemid);
- debugger;
- 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 = [];
-
-
- $('#addtocart').removeClass('disabled');
- $('.msgErrorDetailsItem').addClass('d-none');
- $('.borderselector').each(function (i,el){
- 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');
- $('.buynow').attr('disabled', true);
- 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');
- $('.buynow').attr('disabled', true);
- $('.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<itemtagscombinationRes.length;i++){
-
- // }
-
- }
-
-
- async function getProductDetails(id){
-
-
-
- // let res = await getStatAPIService(`${SERVERNAME}/apis/v4/bizgaze/integrations/products/productattributelist/productid/${id}`);
-
- let resData = await API_SERVICES_ACTIONS.getAPIService(`apis/v4/bizgaze/integrations/products/productattributelist/productid/${id}`,true);
- console.log(resData,'resDataresDataresDataresDataresData');
- if(resData.isError){
- loadingActions.removeLoader();
- alert(resData.errorMsg.message);
- return;
- }
-
- let res = resData.response;
-
- res = JSON.parse(res.result);
- // console.log(res);
-
- if(!res) {
- loadingActions.removeLoader();
- return;
- };
-
-
-
-
- let html = '';
-
- for(let i=0;i<res.length;i++){
- const currItem = res[i];
- // parenttagid means under what label
- // tag id means it know unquie id
- const {parentattribute,parenttagid,tagid,attribute,productid} = currItem;
-
- if(labels[parentattribute]){
- labels[parentattribute].items.push({
- attribute,
- tagid:tagid
- });
- }else{
- labels[parentattribute] = {
- id:parenttagid,
- items:[{
- attribute,
- tagid:tagid
- }]
- };
- html += getParentHTML(parentattribute,productid,parenttagid,i==0);
- }
-
- }
- $('#spec-container-details').html(html);
-
-
- // console.log(labels,'labels');
-
- let childIds = [];
-
- for(let item in labels){
- let {id,items} = labels[item];
- // $(`[data-tagid=${id}]`)
- let html = '';
-
- for(let i=0;i<items.length;i++){
- const {attribute,tagid} = items[i]
- childIds.push(tagid);
- group[attribute] = item;
- html += getChildHTML(tagid,attribute,i==0);
- }
- $(`[data-tagid="${id}"]`).html(html);
- }
-
- // itemtagscombinationRes = await API_SERVICES_ACTIONS.getAPIService(`pis/v4/bizgaze/integrations/products/getitemwithoutbranch/productid/${id}`,true);
- itemtagscombinationRes = await API_SERVICES_ACTIONS.getAPIService(`apis/v4/bizgaze/integrations/products/itemtagscombination/productid/${id}`,true);
-
- itemtagscombinationRes = JSON.parse(itemtagscombinationRes.response.result);
- console.log(itemtagscombinationRes);
-
- let valuesSelected = [];
-
- $('.borderselector').each(function (i,el){
-
- let val = $(el).html();
- valuesSelected.push(val.trim());
- });
-
- let searchParams = window.location.search.split("&");
- let skuId = window.location.hash.split('#')[1].split('=')[1];
- // skuId = skuId.split('=')[1]
- let isGo = true;
- for(let i=0;i<itemtagscombinationRes.length;i++){
- const currItem = itemtagscombinationRes[i];
-
- const {tagnames,sku,itemid} = currItem;
-
- isThereInLabel[tagnames] = itemtagscombinationRes[i];
-
-
- let isTrue = true;
- if(isGo){
- // for(let i=0;i<valuesSelected.length;i++){
- // if(!tagnames.includes(valuesSelected[i])){
- // isTrue = false
- // }
- // }
- if(skuId != itemid){
- isTrue = false
- }
-
- if(isTrue){
-
- console.log(itemtagscombinationRes[i],'itemtagscombinationRes[i]');
-
-
- currentComb = itemtagscombinationRes[i];
- // location.hash = itemtagscombinationRes[i].itemname.trim();
-
- // $('.productname').html(itemtagscombinationRes[i].itemname);
- // $('#skudetailitem').val(itemtagscombinationRes[i].sku)
- // $('.price').html(itemtagscombinationRes[i].pricelist)
-
- // appendSpecs(itemtagscombinationRes[i].itemid);
- // $('.des_productdes').html(itemtagscombinationRes[i].itemdescription);
-
- updateDetailsByObj(itemtagscombinationRes[i]);
-
-
-
- isGo = false;
- let {tagnames,tagids,pricelist} = itemtagscombinationRes[i];
- tagids = tagids.split('|');
- tagnames = tagnames.split('|');
- $('.optiontaganwi').removeClass('borderselector');
-
- for(let i=0;i<tagids.length;i++){
-
- $(`[data-tagiditem="${tagids[i]}"]`).addClass('borderselector');
- }
- // tagiditem
- }
- }
- }
-
-
- if(isGo){
- if(itemtagscombinationRes.length === 0){
- loadingActions.removeLoader();
- toasterHelper("error","Something went wrong!",`toast-top-right`)
- return;
- }
- console.log(itemtagscombinationRes[0]);
- let {tagnames,tagids,pricelist} = itemtagscombinationRes[0];
- tagids = tagids.split('|');
- tagnames = tagnames.split('|');
- $('.optiontaganwi').removeClass('borderselector');
- currentComb = itemtagscombinationRes[0];
- // updateItemId(itemtagscombinationRes[0].itemid);
-
- for(let i=0;i<tagids.length;i++){
-
- $(`[data-type="${tagids[i]}-${tagnames[i]}"]`).addClass('borderselector');
- }
-
- // $('.price').html(pricelist);
- // $('.des_productdes').html(itemtagscombinationRes[0].itemdescription);
- // appendSpecs(itemtagscombinationRes[0].itemid);
-
- updateDetailsByObj(itemtagscombinationRes[0]);
- //console.log(childIds);
- //
-
- }
-
- //getAllCombination(valuesSelected)
-
-
-
- // for(let i=0;i<itemtagscombinationRes.length;i++){
- // const {tagnames} = itemtagscombinationRes[i];
-
- // }
-
- $('#spec-container-details').children().find('.specsmallcard').removeClass('specsmallcard');
-
- addeventlisteners();
- loadingActions.removeLoader();
- return;
- // let resTwo = await postStatAPIService(`${SERVERNAME}/apis/v4/bizgaze/integrations/products/itemtagscombination/productid/${id}`);
-
-
- //let html = '';
- let attributesObj = {};
- for(let i=0;i<res.length;i++){
- const {parentattribute,tagid,productid} = res[i];
- // let attributes = await postStatAPIService(`${SERVERNAME}/apis/v4/bizgaze/integrations/products/productattributelist/parenttagid/${tagid}`);
- // attributesObj[tagid] = JSON.parse(attributes.data.result);
- // console.log(attributes.data.result,tagid);
- html += getParentHTML(parentattribute,productid,tagid,i==0);
- }
-
- $('#spec-container-details').html(html);
-
-
- // let attributes = await postStatAPIService(`${SERVERNAME}/apis/v4/bizgaze/integrations/products/productattributelist/parenttagid/${tagid}`);
- return;
- for(let attr in attributesObj){
- const arr = attributesObj[attr];
-
- let html = '';
- for(let i=0;i<arr.length;i++){
- const {attribute,tagid} = arr[i];
- html += getChildHTML(tagid,attribute,i==0);
- }
-
-
- $(`[data-tagid="${attr}"]`).html(html);
-
-
- }
-
- let defaultValues = await postStatAPIService(`${SERVERNAME}/apis/v4/bizgaze/integrations/products/sellableitemlist/productid/${id}`);
- defaultValues = JSON.parse(defaultValues.data.result);
- let {itemname,price} = defaultValues[0];
- $('.productname').html(itemname);
- $('.price').html(price)
-
- $('#spec-container-details').children().slice(1).find('.specsmallcard').removeClass('specsmallcard');
-
-
-
-
- // getQuantityById(id)
-
-
-
- }
-
-
- }
-
- startDetails();
|