Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

laptopd.js 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. function startDetails() {
  2. // http://127.0.0.1:5502/productdetails.html?productId=106633230000024
  3. if (window.location.search.split('=')[0] == '') {
  4. window.location.href = "/notfound.html";
  5. return;
  6. }
  7. let productId = window.location.hash.split('#')[1].split('=')[1];
  8. console.log(productId);
  9. let itemtagscombinationRes = null;
  10. let labels = {};
  11. let isThereInLabel = {};
  12. let currentComb = null;
  13. let colorId = null;
  14. let group = {};
  15. let loadingActions = {
  16. addLoader() {
  17. $('.loadingCall').removeClass('d-none');
  18. $('.mainContanierProduct').addClass('d-none');
  19. },
  20. removeLoader() {
  21. $('.loadingCall').addClass('d-none');
  22. $('.mainContanierProduct').removeClass('d-none');
  23. }
  24. }
  25. let currentClick = null;
  26. if (productId) {
  27. swapSectionsVideo();
  28. loadingActions.addLoader();
  29. updateProductId(productId);
  30. getProductDetails(productId);
  31. appendSpecs(productId)
  32. } else {
  33. window.location.href = "/notfound.html"
  34. }
  35. function updateProductId(val) {
  36. $('#productidtag').val(val);
  37. }
  38. function updateItemId(val) {
  39. $('#itemidtag').val(val);
  40. }
  41. let specification_wrap_action = {
  42. remove() {
  43. $('.specification-wrap').addClass('d-none');
  44. },
  45. add() {
  46. $('.specification-wrap').removeClass('d-none');
  47. }
  48. }
  49. let description_action = {
  50. addVal(value) {
  51. $('.description-wrap > p').html(value);
  52. },
  53. removeVal(value) {
  54. $('.description-wrap > p').html('');
  55. }
  56. }
  57. function getSpecsItemHTML({ name, des, itemid, id }) {
  58. return `<div id="${id}" data-specitemid="${itemid}" class="">
  59. <div class="row border-bottom">
  60. <div class="col-sm-6 bg-gray-3 py-2">
  61. ${name}
  62. </div>
  63. <div class="col-sm-6 py-2">
  64. ${des}
  65. </div>
  66. </div>
  67. </div>`;
  68. }
  69. // function getSpecsItemHTML({name,des,itemid,id}){
  70. // return ` <tr id="${id}" data-specitemid="${itemid}">
  71. // <td style="width:200px">${name}</td>
  72. // <td class="">${des}</td>
  73. // </tr>`;
  74. // }
  75. async function appendSpecs(id) {
  76. let resData = await API_SERVICES_ACTIONS.getAPIService(`apis/v4/bizgaze/integrations/products/itemspecifications/itemid/${id}`, true);
  77. if (resData.isError) {
  78. $('.productdetailstabs').addClass('d-none');
  79. $('.specContainerleft').html('')
  80. $('.specContainerRight').html('')
  81. return;
  82. }
  83. $('.productdetailstabs ').removeClass('d-none');
  84. const res = resData.response;
  85. // console.log(JSON.parse(res.result));
  86. const data = JSON.parse(res.result);
  87. // console.log(data);
  88. let html = '';
  89. let leftHtml = '';
  90. let rightHtml = '';
  91. if (data.length == 0) {
  92. $('.productdetailstabs ').addClass('d-none');
  93. $('.specContainerleft').html('')
  94. $('.specContainerRight').html('')
  95. return;
  96. }
  97. for (let i = 0; i < data.length; i++) {
  98. const { specificationname, specificationitemid, itemid, description } = data[i];
  99. if ((i + 1) % 2 == 0) {
  100. rightHtml += getSpecsItemHTML({
  101. name: specificationname, id: specificationitemid, itemid, des: description
  102. })
  103. } else {
  104. leftHtml += getSpecsItemHTML({
  105. name: specificationname, id: specificationitemid, itemid, des: description
  106. });
  107. }
  108. }
  109. $('.specContainerleft').html(leftHtml)
  110. $('.specContainerRight').html(rightHtml)
  111. }
  112. function getParentHTML(name, productid, id, isMain) {
  113. return `<div data-parentidgroup="${name?.replace(" ", '')}-parent" class="pb-2 groupingitems_search ${name?.replace(" ", '')}-parent">
  114. <h5 class="py-2 smallHeadingProductDetails">${name}</h5>
  115. <div class="d-flex gap-2 flex-lg-row flex-wrap ${id}container" data-tagid="${id}">
  116. </div>
  117. </div>`;
  118. }
  119. function onClickHandler(e) {
  120. $(e).parent().find('.borderselector').removeClass('borderselector');
  121. $(e).addClass('borderselector')
  122. }
  123. function getChildHTML(tagid, name, isTrue,parentid) {
  124. let blue = '#253746';
  125. let greenLight = '#5e7975';
  126. let brown = '#624839';
  127. let bgColor = '';
  128. if(name === 'Deep Sea Blue'){
  129. bgColor = blue;
  130. }else if(name == 'Desert Brown'){
  131. bgColor = brown;
  132. }else if(name == 'Eucalyptus Green'){
  133. bgColor = greenLight;
  134. }
  135. if(colorId == parentid){
  136. return `
  137. <div data-type="${tagid}-${name}" data-tagiditem="${tagid}" class="specsmallcard optiontaganwi ${isTrue ? 'borderselector' : ''} colorselector card text-center small-font cursor-pointer ">
  138. <span style="
  139. height: 25px;
  140. border-radius: 5px;
  141. width:25px;
  142. background: ${bgColor} !important;
  143. pointer-events:none;
  144. "></span>
  145. </div> `
  146. }
  147. return `
  148. <div data-type="${tagid}-${name}" data-tagiditem="${tagid}" class="specsmallcard optiontaganwi ${isTrue ? 'borderselector' : ''} card text-center small-font cursor-pointer p-3">
  149. ${name}
  150. </div> `
  151. }
  152. function addeventlisteners() {
  153. $('.optiontaganwi').each(function (i, el) {
  154. $(el).click(function (e) {
  155. $('#quantity').val(1);
  156. $(e.target).parent().find('.borderselector').removeClass('borderselector');
  157. $(e.target).addClass('borderselector');
  158. currentClick = e.target;
  159. ;
  160. //searchComb();
  161. // getAllCombination();
  162. getandsetCombination();
  163. })
  164. });
  165. }
  166. function getandsetCombination(){
  167. let keyOption = $(currentClick).data('tagiditem');
  168. $('.disabled-option-item').removeClass('disabled-option-item');
  169. let tagsNames = [];
  170. let currOptionAvaIds = {};
  171. $('.borderselector').each(function (i,e){
  172. let id = $(e).data('tagiditem');
  173. tagsNames.push(id);
  174. });
  175. for(let i=0;i<itemtagscombinationRes.length;i++){
  176. let tagItems = itemtagscombinationRes[i].tagids;;
  177. if(tagItems.includes(keyOption)){
  178. let splitArr = tagItems.split('|');
  179. for(let j=0;j<splitArr.length;j++){
  180. if(keyOption){
  181. currOptionAvaIds[splitArr[j]] = splitArr[j];
  182. }
  183. }
  184. }
  185. }
  186. console.log(currOptionAvaIds);
  187. console.log(itemtagscombinationRes);
  188. let parentsArr = [];
  189. $('.optiontaganwi').each(function (i,e){
  190. let currParent = $(e).parents('.groupingitems_search');
  191. if(currParent.find(`[data-tagiditem="${keyOption}"]`).length==0){
  192. let currId = $(e).data('tagiditem');
  193. if(!currOptionAvaIds[currId]){
  194. if($(e).hasClass('borderselector')){
  195. parentsArr.push(currParent);
  196. $(e).removeClass('borderselector');
  197. }
  198. $(e).addClass('disabled-option-item');
  199. }
  200. }
  201. });
  202. for(let i=0;i<parentsArr.length;i++){
  203. let currParent = parentsArr[i];
  204. currParent.find('.optiontaganwi').each(function (j,e){
  205. let isTrue = $(e).hasClass('disabled-option-item');
  206. if(!isTrue){
  207. $(e).addClass('borderselector');
  208. return false;
  209. }
  210. });
  211. }
  212. // $('.optiontaganwi').addClass('disabled-option-item');
  213. let parentId = $(currentClick).parents('.groupingitems_search');
  214. let parentData = $(parentId).data('parentidgroup');
  215. let parentArr = [];
  216. $('.groupingitems_search').each(function (i,e){
  217. const curParentId = $(e).data('parentidgroup');
  218. if(parentData != curParentId){
  219. let obj = {
  220. name:$(e).find('.smallHeadingProductDetails').html(),
  221. arr:[]
  222. }
  223. $(e).find('.optiontaganwi').each(function (j,evt){
  224. let id = $(evt).data('tagiditem');
  225. obj.arr.push(id);
  226. });
  227. parentArr.push(obj);
  228. }
  229. })
  230. console.log(parentArr);
  231. let arrone = parentArr[0].arr;
  232. let arrtwo = [];
  233. if(parentArr.length>1){
  234. arrtwo = parentArr[1]?.arr;
  235. }
  236. let currId = keyOption;
  237. let ids = [];
  238. for(let i=0;i<arrone.length;i++){
  239. //let currEl = [currId,arrone[i]];
  240. let currEl = ``
  241. for(let j=0;j<arrtwo.length;j++){
  242. currEl = `${currId}|${arrone[i]}|${arrtwo[j]}`;
  243. ids.push(currEl);
  244. currEl = '';
  245. }
  246. }
  247. console.log(ids,'ids');
  248. let findObj = [];
  249. debugger
  250. for(let i=0;i<ids.length;i++){
  251. let curId = ids[i]
  252. for(let j=0;j<itemtagscombinationRes.length;j++){
  253. const currItem = itemtagscombinationRes[j].tagids.split('|');
  254. let isTrue = true;
  255. for(let k=0;k<currItem.length;k++){
  256. if(!curId.includes(currItem[k])){
  257. isTrue = false;
  258. break;
  259. }
  260. }
  261. if(isTrue){
  262. findObj.push(itemtagscombinationRes[j]);
  263. }
  264. }
  265. }
  266. console.log(findObj);
  267. $('.optiontaganwi').addClass('disabled-option-item');
  268. debugger;
  269. for(let i=0;i<findObj.length;i++){
  270. let item = findObj[i].tagids.split('|');
  271. for(let j=0;j<item.length;j++){
  272. $(`[data-tagiditem=${item[j]}]`).removeClass('disabled-option-item');
  273. }
  274. }
  275. $(parentId).find('.optiontaganwi').each(function (i,e){
  276. $(e).removeClass('disabled-option-item')
  277. });
  278. for(let i=0;i<itemtagscombinationRes.length;i++){
  279. let currIds = itemtagscombinationRes[i].tagids;
  280. let isTrue = true;
  281. let isPro = false;
  282. for(let j=0;j<tagsNames.length;j++){
  283. if(tagsNames.join().includes('106631360000128')&&(tagsNames.join().includes('106631360000132')||tagsNames.join().includes('106631360000133'))){
  284. isPro = true;
  285. }
  286. if(!currIds.includes(tagsNames[j])){
  287. isTrue = false;
  288. }
  289. }
  290. if(isTrue){
  291. const { quantity } = itemtagscombinationRes[i];
  292. if (true) {
  293. currentComb = itemtagscombinationRes[i];
  294. updateDetailsByObj(itemtagscombinationRes[i]);
  295. if(isPro){
  296. $(`[data-tagiditem="106631360000089"]`).addClass(' disabled-option-item')
  297. $(`[data-tagiditem="106631360000088"]`).addClass(' disabled-option-item')
  298. }
  299. } else {
  300. let name = itemtagscombinationRes[i].itemname.split('-')[0];
  301. $('#addtocart').addClass('disabled');
  302. let itemsName = name;
  303. $('.borderselector').each(function (i, e) {
  304. itemsName += ` ${$(e).html().trim()}`;
  305. });
  306. updateItemId(null);
  307. let defaultImg = itemtagscombinationRes[i].itemimageurl ? imgServerNameBuild(itemtagscombinationRes[i].itemimageurl) : `./dist/assets/imgs/nophoto.png`;
  308. $('.productDetailsMain > img').attr('src', defaultImg);
  309. specification_wrap_action.remove();
  310. $('#skudetailitem').val(-1)
  311. $('.productname').html(itemsName)
  312. $('.msgErrorDetailsItem').removeClass('d-none');
  313. $('.des_productdes').html('');
  314. $('.price').html('');
  315. }
  316. initAddToCart()
  317. return;
  318. }
  319. }
  320. // return;
  321. return;
  322. let commonTags = [];
  323. // $('.optiontaganwi').addClass('disabled-option-item')
  324. for(let i=0;i<tagsNames.length;i++){
  325. let currtagName = tagsNames[i];
  326. let arr = currtagItemCom(currtagName);
  327. commonTags.push(arr);
  328. }
  329. console.log(commonTags);
  330. // for(let i=0;i<commonTags.length;i++){
  331. // let currObj = commonTags[i];
  332. // for(let item in currObj){
  333. // console.log($(`[data-tagiditem="${item}"]`));
  334. // $(`[data-tagiditem="${item}"]`).removeClass('disabled-option-item')
  335. // }
  336. // }
  337. let finalAns = {};
  338. let arra = [];
  339. for(let i=0;i<commonTags.length;i++){
  340. let currObj = commonTags[i];
  341. for(let item in currObj){
  342. let isTrue = true;
  343. for(let j=0;j<commonTags.length;j++){
  344. if(j!=i){
  345. let currComb = commonTags[j];
  346. if(!currComb[item]){
  347. isTrue = false;
  348. }
  349. }
  350. }
  351. if(isTrue){
  352. arra.push(currObj[item])
  353. finalAns[currObj[item]] = currObj[item];
  354. $(`[data-tagiditem="${item}"]`).removeClass('disabled-option-item')
  355. }
  356. }
  357. }
  358. // console.log(arra);
  359. // for(let i=0;i<itemtagscombinationRes.length;i++){
  360. // let tagItems = itemtagscombinationRes[i].tagids;;
  361. // if(tagItems.includes(keyOption)){
  362. // let splitArr = tagItems.split('|');
  363. // for(let j=0;j<splitArr.length;j++){
  364. // commonTags[splitArr[j]] = splitArr[j];
  365. // }
  366. // }
  367. // }
  368. // for(let i=0;i<currOptionAvaIds.length;i++){
  369. // let currId = currOptionAvaIds[i];
  370. // if(parentId.find(currId).length === 0){
  371. // console.log(currId);
  372. // }
  373. // }
  374. }
  375. function currtagItemCom(keyOption){
  376. debugger;
  377. let arr = [];
  378. let commonTags = {};
  379. for(let i=0;i<itemtagscombinationRes.length;i++){
  380. let tagItems = itemtagscombinationRes[i].tagids;;
  381. if(tagItems.includes(keyOption)){
  382. let splitArr = tagItems.split('|');
  383. for(let j=0;j<splitArr.length;j++){
  384. if(!commonTags[splitArr[j]]){
  385. commonTags[splitArr[j]] = {
  386. keyOption,
  387. data:itemtagscombinationRes[i]
  388. };
  389. arr.push(splitArr[j]);
  390. }
  391. }
  392. }
  393. }
  394. return commonTags;
  395. }
  396. function updateDetailsByObj(obj) {
  397. $('.productname').html(obj.itemname);
  398. $('.titleproductnav').html(obj.itemname);
  399. let [currencySymbol, amount] = getCurrencySymbol(obj?.pricelist||0);
  400. let commingSoonText = window.location.href.toLowerCase().includes('zeno')||window.location.href.includes('fyro')
  401. $('.price').html(obj.pricelist ? `<span class="font-w600">${currencySymbol}${amount}</span>${commingSoonText?'<span class="mx-1 badge d-md-none bg-gradient-violet text-a-color">Pre Order Now!</span>':''}` : 'pre order now');
  402. appendSpecs(obj.itemid)
  403. $('#skudetailitem').val(obj.sku)
  404. $('.des_productdes').html(obj.itemdescription);
  405. $('#addtocart').attr('data-qty', obj.quantity);
  406. let defaultImg = obj.itemimageurl ? imgServerNameBuild(obj.itemimageurl) : `./dist/assets/imgs/nophoto.png`;
  407. // console.log(obj.itemimageurl, 'obj.itemimageurlobj.itemimageurlobj.itemimageurl');
  408. debugger;
  409. let productId = window.location.hash.split('#')[1]?.split('=')[1];
  410. let itemId = window.location.hash.split('#')[2]?.split('=')[1];
  411. history.replaceState(undefined, undefined, `#productId=${productId}#itemid=${obj.itemid}`)
  412. $('.productDetailsMain > img').attr('src', defaultImg).attr('loading','lazy');
  413. updateItemId(obj.itemid);
  414. console.log(obj,'objobjobj');
  415. debugger;
  416. if (!obj.pricelist || !obj.quantity) {
  417. $('.buynow').attr('disabled', true);
  418. $('#addtocart').attr('disabled', true);
  419. } else {
  420. $('.buynow').attr('disabled', false);
  421. $('#addtocart').attr('disabled', false);
  422. }
  423. }
  424. function searchComb() {
  425. let valuesSelected = [];
  426. $('.optiontaganwi').removeClass('disabled-option-item')
  427. $('#addtocart').removeClass('disabled');
  428. $('.msgErrorDetailsItem').addClass('d-none');
  429. $('.borderselector,border_selector').each(function (i, el) {
  430. console.log($(el).html())
  431. let val = $(el).data('tagiditem');
  432. valuesSelected.push(val);
  433. });
  434. let labelRecord = {};
  435. for (let label in labels) {
  436. labelRecord[label] = false;
  437. }
  438. console.log(labelRecord);
  439. specification_wrap_action.add();
  440. console.log(group);
  441. let unFiler = null;
  442. for (let i = 0; i < itemtagscombinationRes.length; i++) {
  443. const currItem = itemtagscombinationRes[i];
  444. const { tagids } = currItem;
  445. let isTrue = true;
  446. let labelFilter = labelRecord;
  447. for (let i = 0; i < valuesSelected.length; i++) {
  448. if (!tagids.includes(valuesSelected[i])) {
  449. isTrue = false
  450. unFiler = labelFilter;
  451. break;
  452. }
  453. labelFilter[group[valuesSelected[i]]] = true;
  454. }
  455. if (isTrue) {
  456. // console.log(itemtagscombinationRes[i], 'itemtagscombinationRes[i]');
  457. const { quantity } = itemtagscombinationRes[i];
  458. if (quantity >= $('#quantity').val() && quantity >= 1) {
  459. currentComb = itemtagscombinationRes[i];
  460. // $('.productname').html(itemtagscombinationRes[i].itemname)
  461. // $('.price').html(itemtagscombinationRes[i].pricelist);
  462. // location.hash = itemtagscombinationRes[i].itemname.trim();
  463. // appendSpecs(itemtagscombinationRes[i].itemid)
  464. // history.replaceState(null, null, `#itemid=${itemtagscombinationRes[i].itemid}#${itemtagscombinationRes[i].itemname.trim()}`);
  465. // $('#skudetailitem').val(itemtagscombinationRes[i].sku)
  466. // $('.des_productdes').html(itemtagscombinationRes[i].itemdescription);
  467. updateDetailsByObj(itemtagscombinationRes[i]);
  468. } else {
  469. let name = itemtagscombinationRes[i].itemname.split('-')[0];
  470. $('#addtocart').addClass('disabled');
  471. let itemsName = name;
  472. $('.borderselector').each(function (i, e) {
  473. itemsName += ` ${$(e).html().trim()}`;
  474. });
  475. updateItemId(null);
  476. let defaultImg = itemtagscombinationRes[i].itemimageurl ? imgServerNameBuild(itemtagscombinationRes[i].itemimageurl) : `./dist/assets/imgs/nophoto.png`;
  477. // console.log(itemtagscombinationRes[i].itemimageurl, 'obj.itemimageurlobj.itemimageurlobj.itemimageurl');
  478. $('.productDetailsMain > img').attr('src', defaultImg);
  479. specification_wrap_action.remove();
  480. $('#skudetailitem').val(-1)
  481. $('.productname').html(itemsName)
  482. // history.replaceState(null, null, `#`);
  483. $('.msgErrorDetailsItem').removeClass('d-none');
  484. $('.des_productdes').html('');
  485. $('.price').html('');
  486. }
  487. initAddToCart()
  488. return;
  489. }
  490. }
  491. // alert("j");
  492. let name = itemtagscombinationRes[0].itemname.split('-')[0];
  493. let itemsName = name;
  494. $('.borderselector').each(function (i, e) {
  495. itemsName += `- ${$(e).html().trim()}`;
  496. })
  497. specification_wrap_action.remove();
  498. $('.productname').html(itemsName)
  499. $('#skudetailitem').val(-1)
  500. $('.price').html('');
  501. $('#addtocart').addClass('disabled');
  502. $('.msgErrorDetailsItem').removeClass('d-none');
  503. initAddToCart()
  504. }
  505. function getAllCombination() {
  506. debugger;
  507. const currClickAttr = $(currentClick).html().trim();
  508. const optionId = $(currentClick).data('tagiditem');
  509. let curr = $(currentClick).parents('.groupingitems_search').data('parentidgroup');
  510. $('.groupingitems_search').each(function (i, e) {
  511. const id = $(e).data('parentidgroup');
  512. if (id != curr) {
  513. $(e).find('.optiontaganwi').addClass('disabled-option-item');
  514. $(e).find('.borderselector').removeClass('borderselector');
  515. }
  516. });
  517. let ansArr = [];
  518. let index = 0;
  519. let comb = null;
  520. for(let i=0;i<itemtagscombinationRes.length;i++){
  521. let currIds = itemtagscombinationRes[i].tagids;
  522. if(currIds.includes(optionId)){
  523. currIds = currIds.split('|');
  524. for(let j=0;j<currIds.length;j++){
  525. debugger;
  526. if(index==0 &&optionId != currIds[j] ) {
  527. $(`[data-tagiditem="${currIds[j]}"]`).addClass('borderselector')
  528. comb = itemtagscombinationRes[i];
  529. index++;
  530. }
  531. $(`[data-tagiditem="${currIds[j]}"]`).removeClass('disabled-option-item');
  532. // $().parents('[data-tagid]').find()
  533. }
  534. }
  535. }
  536. // console.log(comb,'comb tag');
  537. updateDetailsByObj(comb);
  538. let currentItem = comb.tagids.split('|');
  539. for(let i=0;i<currentItem.length;i++){
  540. $(`[data-tagiditem="${currentItem[i]}"]`).removeClass('disabled-option-item').addClass('borderselector');
  541. }
  542. // history.replaceState(null, null, `#${comb.itemname}`);
  543. // window.location.href = `#${comb.itemname}`
  544. console.log(itemtagscombinationRes,'gobal');
  545. return;
  546. };
  547. async function getProductDetails(id) {
  548. debugger;
  549. let resData = await API_SERVICES_ACTIONS.getAPIService(`apis/v4/bizgaze/integrations/products/productattributelist/productid/${id}`, true);
  550. if (resData.isError) {
  551. loadingActions.removeLoader();
  552. alert(resData.errorMsg.message);
  553. return;
  554. }
  555. if(resData.response.result == '[]' || !resData.response.result){
  556. $('.barbgnav').removeClass('d-none')
  557. loadingActions.removeLoader();
  558. toasterHelper("Something Went Wrong")
  559. return;
  560. }
  561. let res = resData.response;
  562. res = JSON.parse(res.result);
  563. // console.log(res, 'productattributelist');
  564. if (!res) {
  565. loadingActions.removeLoader();
  566. return;
  567. };
  568. let html = '';
  569. for (let i = 0; i < res.length; i++) {
  570. const currItem = res[i];
  571. // parenttagid means under what label
  572. // tag id means it know unquie id
  573. const { parentattribute, parenttagid, tagid, attribute, productid } = currItem;
  574. if (labels[parentattribute]) {
  575. labels[parentattribute].items.push({
  576. attribute,
  577. tagid: tagid
  578. });
  579. } else {
  580. labels[parentattribute] = {
  581. id: parenttagid,
  582. items: [{
  583. attribute,
  584. tagid: tagid
  585. }]
  586. };
  587. if(parentattribute.toLowerCase() === 'colour'){
  588. colorId = parenttagid;
  589. }
  590. html += getParentHTML(parentattribute, productid, parenttagid, i == 0);
  591. }
  592. }
  593. $('#spec-container-details').html(html);
  594. console.log(labels,'labels');
  595. let childIds = [];
  596. for (let item in labels) {
  597. let { id, items } = labels[item];
  598. // $(`[data-tagid=${id}]`)
  599. let html = '';
  600. for (let i = 0; i < items.length; i++) {
  601. const { attribute, tagid } = items[i]
  602. childIds.push(tagid);
  603. group[attribute] = item;
  604. console.log(attribute,colorId,"s");
  605. html += getChildHTML(tagid, attribute, i == 0,id);
  606. console.log(attribute,"attributeattributeattributeattribute");
  607. }
  608. debugger;
  609. $(`[data-tagid="${id}"]`).html(html);
  610. }
  611. itemtagscombinationRes = await API_SERVICES_ACTIONS.getAPIService(`apis/v4/bizgaze/integrations/products/getitemwithoutbranch/productid/${id}`, true);
  612. itemtagscombinationRes = JSON.parse(itemtagscombinationRes.response.result);
  613. console.log(itemtagscombinationRes, "conductt");
  614. let itemidSearch = window.location.hash.split('#')[2]?.split('=')[1];
  615. if(!itemidSearch){
  616. itemidSearch = itemtagscombinationRes[0].itemid
  617. }
  618. let valuesSelected = [];
  619. $('.borderselector').each(function (i, el) {
  620. let val = $(el).html();
  621. valuesSelected.push(val.trim());
  622. });
  623. debugger;
  624. // let searchParams = window.location.search.split("&");
  625. // let skuId = window.location.hash.split('#')[2].split('=')[1];
  626. // skuId = skuId.split('=')[1]
  627. let isGo = true;
  628. for (let i = 0; i < itemtagscombinationRes.length; i++) {
  629. const currItem = itemtagscombinationRes[i];
  630. const { tagnames, sku, itemid } = currItem;
  631. isThereInLabel[tagnames] = itemtagscombinationRes[i];
  632. let isTrue = true;
  633. if (isGo) {
  634. // for(let i=0;i<valuesSelected.length;i++){
  635. // if(!tagnames.includes(valuesSelected[i])){
  636. // isTrue = false
  637. // }
  638. // }
  639. if (itemidSearch != itemid) {
  640. isTrue = false
  641. }
  642. // if (i != 0) {
  643. // isTrue = false
  644. // }
  645. if (isTrue) {
  646. // console.log(itemtagscombinationRes[i], 'itemtagscombinationRes[i]');
  647. currentComb = itemtagscombinationRes[i];
  648. updateDetailsByObj(itemtagscombinationRes[i]);
  649. isGo = false;
  650. let { tagnames, tagids, pricelist } = itemtagscombinationRes[i];
  651. tagids = tagids.split('|');
  652. tagnames = tagnames.split('|');
  653. $('.optiontaganwi').removeClass('borderselector');
  654. for (let i = 0; i < tagids.length; i++) {
  655. $(`[data-tagiditem="${tagids[i]}"]`).addClass('borderselector');
  656. }
  657. break;
  658. // tagiditem
  659. }
  660. }
  661. }
  662. if (isGo && itemtagscombinationRes.length != 0) {
  663. // console.log(itemtagscombinationRes[0]);
  664. let { tagnames, tagids, pricelist } = itemtagscombinationRes[0];
  665. tagids = tagids.split('|');
  666. tagnames = tagnames.split('|');
  667. $('.optiontaganwi').removeClass('borderselector');
  668. currentComb = itemtagscombinationRes[0];
  669. // updateItemId(itemtagscombinationRes[0].itemid);
  670. for (let i = 0; i < tagids.length; i++) {
  671. $(`[data-type="${tagids[i]}-${tagnames[i]}"]`).addClass('borderselector');
  672. // $(`[data-type="${tagids[i]}-Eucalyptus Green"]`).removeClass('borderselector');
  673. // $(`[data-type="${tagids[i]}-Desert Brown"]`).removeClass('borderselector');
  674. // $(`[data-type="${tagids[i]}-Deep Sea Blue"]`).removeClass('borderselector');
  675. }
  676. // $('.price').html(pricelist);
  677. // $('.des_productdes').html(itemtagscombinationRes[0].itemdescription);
  678. // appendSpecs(itemtagscombinationRes[0].itemid);
  679. updateDetailsByObj(itemtagscombinationRes[0]);
  680. //console.log(childIds);
  681. //
  682. }
  683. //getAllCombination()
  684. // for(let i=0;i<itemtagscombinationRes.length;i++){
  685. // const {tagnames} = itemtagscombinationRes[i];
  686. // }
  687. $('#spec-container-details').children().find('.specsmallcard').removeClass('specsmallcard');
  688. //getting the first borderselector in first $('.groupingitems_search')[0]
  689. let firstParentGroup = $('.groupingitems_search')[0];
  690. debugger;
  691. let optionId = $(firstParentGroup).find('.borderselector').data('tagiditem');
  692. currentClick = $(firstParentGroup).find('.borderselector')
  693. getandsetCombination();
  694. addeventlisteners();
  695. loadingActions.removeLoader();
  696. return;
  697. }
  698. }
  699. startDetails();