暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

laptopd.js 31KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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. let itemtagscombinationRes = null;
  9. let labels = {};
  10. let isThereInLabel = {};
  11. let currentComb = null;
  12. let colorId = null;
  13. let group = {};
  14. let loadingActions = {
  15. addLoader() {
  16. $(".loadingCall").removeClass("d-none");
  17. $(".mainContanierProduct").addClass("d-none");
  18. },
  19. removeLoader() {
  20. $(".loadingCall").addClass("d-none");
  21. $(".mainContanierProduct").removeClass("d-none");
  22. },
  23. };
  24. let currentClick = null;
  25. if (productId) {
  26. swapSectionsVideo();
  27. loadingActions.addLoader();
  28. updateProductId(productId);
  29. getProductDetails(productId);
  30. appendSpecs(productId);
  31. } else {
  32. window.location.href = "/notfound.html";
  33. }
  34. function updateProductId(val) {
  35. $("#productidtag").val(val);
  36. }
  37. function updateItemId(val) {
  38. $("#itemidtag").val(val);
  39. }
  40. let specification_wrap_action = {
  41. remove() {
  42. $(".specification-wrap").addClass("d-none");
  43. },
  44. add() {
  45. $(".specification-wrap").removeClass("d-none");
  46. },
  47. };
  48. let description_action = {
  49. addVal(value) {
  50. $(".description-wrap > p").html(value);
  51. },
  52. removeVal(value) {
  53. $(".description-wrap > p").html("");
  54. },
  55. };
  56. function getSpecsItemHTML({ name, des, itemid, id }) {
  57. return `<div id="${id}" data-specitemid="${itemid}" class="">
  58. <div class="row border-bottom">
  59. <div class="col-sm-6 bg-gray-3 py-2">
  60. ${name}
  61. </div>
  62. <div class="col-sm-6 py-2">
  63. ${des}
  64. </div>
  65. </div>
  66. </div>`;
  67. }
  68. // function getSpecsItemHTML({name,des,itemid,id}){
  69. // return ` <tr id="${id}" data-specitemid="${itemid}">
  70. // <td style="width:200px">${name}</td>
  71. // <td class="">${des}</td>
  72. // </tr>`;
  73. // }
  74. async function appendSpecs(id) {
  75. let resData = await API_SERVICES_ACTIONS.getAPIService(
  76. `apis/v4/bizgaze/integrations/products/itemspecifications/itemid/${id}`,
  77. true
  78. );
  79. if (resData.isError) {
  80. $(".productdetailstabs").addClass("d-none");
  81. // $('.specContainerleft').html('')
  82. $(".specContainerRight").html("");
  83. $(".specContainerleft").find("#faqAccordion").html("");
  84. return;
  85. }
  86. $(".productdetailstabs ").removeClass("d-none");
  87. const res = resData.response;
  88. const data = JSON.parse(res.result);
  89. let html = "";
  90. let leftHtml = "";
  91. let rightHtml = "";
  92. if (data.length == 0) {
  93. $(".productdetailstabs ").addClass("d-none");
  94. $(".specContainerleft").find("#faqAccordion").html("");
  95. $(".specContainerRight").html("");
  96. return;
  97. }
  98. // for (let i = 0; i < data.length; i++) {
  99. // const { specificationname, specificationitemid, itemid, description } = data[i];
  100. // if ((i + 1) % 2 == 0) {
  101. // rightHtml += getSpecsItemHTML({
  102. // name: specificationname, id: specificationitemid, itemid, des: description
  103. // })
  104. // } else {
  105. // leftHtml += getSpecsItemHTML({
  106. // name: specificationname, id: specificationitemid, itemid, des: description
  107. // });
  108. // }
  109. // }
  110. // $('.specContainerleft').html(leftHtml)
  111. // $('.specContainerRight').html(rightHtml)
  112. let fullHtml = "";
  113. for (let i = 0; i < data.length; i++) {
  114. // const { specificationname, specificationitemid, itemid, description } = data[i];
  115. const {
  116. "Specification Name": specificationname,
  117. itemid: itemid,
  118. specificationitemid: specificationitemid,
  119. Description: description,
  120. } = data[i];
  121. fullHtml += getSpecAccordionHTML(
  122. `acc_specs_${specificationitemid}`,
  123. specificationname,
  124. description,
  125. specificationitemid,
  126. itemid
  127. );
  128. }
  129. $(".specContainerleft").find("#faqAccordion").html(fullHtml);
  130. }
  131. function getSpecAccordionHTML(id, name, body, itemid, mainid) {
  132. let lis = '<ul class="mb-0 lh-2r">';
  133. if (body.includes("•")) {
  134. let lisArr = body.split("•");
  135. for (let i = 1; i < lisArr.length; i++) {
  136. lis += `<li>${lisArr[i]}</li>`;
  137. }
  138. lis += "</ul>";
  139. } else {
  140. lis = body;
  141. }
  142. if ($(window).width() <= 768) {
  143. return ` <div class="accordion-item border-0 py-2">
  144. <h2 class="accordion-header" id="${mainid}">
  145. <button class=" accordion-button bg-white text-dark " type="button" >
  146. <span class="font-weight-600 fs-5 text-dark acc-specs-name"> ${name}</span>
  147. </button>
  148. </h2>
  149. <div>
  150. <div id="${id}_child" class=" w-100 show" aria-labelledby="${mainid}">
  151. <div class="accordion-body ${
  152. body.includes("•") ? "px-1" : ""
  153. } d-flex justify-content-right">
  154. <div class="text-secondary">${lis}</div>
  155. </div>
  156. </div>
  157. </div>
  158. </div>`;
  159. } else {
  160. return ` <div class="accordion-item border-x-none">
  161. <h2 class="accordion-header" id="${mainid}">
  162. <button class="py-md-5 accordion-button bg-white text-dark " type="button" >
  163. <span class="font-weight-600 fs-5 text-dark acc-specs-name"> ${name}</span>
  164. <div id="${id}_child" class="show w-100 " aria-labelledby="${mainid}">
  165. <div class="accordion-body d-flex justify-content-right">
  166. <div>${lis}</div>
  167. </div>
  168. </div>
  169. </button>
  170. </h2>
  171. </div>`;
  172. }
  173. return `<div id="${mainid}" data-specitemid="${id}" class="accordion-item custom-accordion-item border-x-none">
  174. <h2 class="accordion-header custom-accordion-header" id="${id}">
  175. <button class="py-5 accordion-button bg-white text-dark custom-accordion-button" type="button"
  176. data-bs-toggle="collapse" data-bs-target="#${id}_child" aria-expanded="true"
  177. aria-controls="${id}_child">
  178. <span class="font-weight-600 font-1-5 text-dark"> ${name}</span>
  179. <div id="${id}_child" class="accordion-collapse collapse show custom-accordion-content"
  180. aria-labelledby="${mainid}" data-bs-parent="#faqAccordion">
  181. <div class="accordion-body custom-accordion-body font-weight-600">
  182. ${body}
  183. </div>
  184. </div>
  185. </button>
  186. </h2>
  187. </div>`;
  188. }
  189. function getParentHTML(name, productid, id, isMain) {
  190. return `<div data-parentidgroup="${name?.replace(
  191. " ",
  192. ""
  193. )}-parent" class="pb-2 groupingitems_search ${name?.replace(
  194. " ",
  195. ""
  196. )}-parent">
  197. <h5 class="py-2 smallHeadingProductDetails">${name}</h5>
  198. <div class="d-flex gap-2 flex-lg-row flex-wrap ${id}container" data-tagid="${id}">
  199. </div>
  200. </div>`;
  201. }
  202. function onClickHandler(e) {
  203. $(e).parent().find(".borderselector").removeClass("borderselector");
  204. $(e).addClass("borderselector");
  205. }
  206. function getChildHTML(tagid, name, isTrue, parentid) {
  207. let blue = "#253746";
  208. let greenLight = "#5e7975";
  209. let brown = "#624839";
  210. let bgColor = "";
  211. if (name === "Deep Sea Blue") {
  212. bgColor = blue;
  213. } else if (name == "Desert Brown") {
  214. bgColor = brown;
  215. } else if (name == "Eucalyptus Green") {
  216. bgColor = greenLight;
  217. }
  218. if (colorId == parentid) {
  219. return `
  220. <div data-type="${tagid}-${name}" data-tagiditem="${tagid}" class="specsmallcard optiontaganwi ${
  221. isTrue ? "borderselector" : ""
  222. } colorselector card text-center small-font cursor-pointer ">
  223. <span style="
  224. height: 25px;
  225. border-radius: 5px;
  226. width:25px;
  227. background: ${bgColor} !important;
  228. pointer-events:none;
  229. "></span>
  230. </div> `;
  231. }
  232. return `
  233. <div data-type="${tagid}-${name}" data-tagiditem="${tagid}" class="specsmallcard optiontaganwi ${
  234. isTrue ? "borderselector" : ""
  235. } card text-center small-font cursor-pointer p-3">
  236. ${name}
  237. </div> `;
  238. }
  239. function addeventlisteners() {
  240. $(".optiontaganwi").each(function (i, el) {
  241. $(el).click(function (e) {
  242. $("#quantity").val(1);
  243. $(e.target)
  244. .parent()
  245. .find(".borderselector")
  246. .removeClass("borderselector");
  247. $(e.target).addClass("borderselector");
  248. currentClick = e.target;
  249. //searchComb();
  250. // getAllCombination();
  251. getandsetCombination();
  252. });
  253. });
  254. }
  255. function getandsetCombination() {
  256. let keyOption = $(currentClick).data("tagiditem");
  257. $(".disabled-option-item").removeClass("disabled-option-item");
  258. let tagsNames = [];
  259. let currOptionAvaIds = {};
  260. $(".borderselector").each(function (i, e) {
  261. let id = $(e).data("tagiditem");
  262. tagsNames.push(id);
  263. });
  264. for (let i = 0; i < itemtagscombinationRes.length; i++) {
  265. let tagItems = itemtagscombinationRes[i].tagids;
  266. if (tagItems.includes(keyOption)) {
  267. let splitArr = tagItems.split("|");
  268. for (let j = 0; j < splitArr.length; j++) {
  269. if (keyOption) {
  270. currOptionAvaIds[splitArr[j]] = splitArr[j];
  271. }
  272. }
  273. }
  274. }
  275. let parentsArr = [];
  276. $(".optiontaganwi").each(function (i, e) {
  277. let currParent = $(e).parents(".groupingitems_search");
  278. if (currParent.find(`[data-tagiditem="${keyOption}"]`).length == 0) {
  279. let currId = $(e).data("tagiditem");
  280. if (!currOptionAvaIds[currId]) {
  281. if ($(e).hasClass("borderselector")) {
  282. parentsArr.push(currParent);
  283. $(e).removeClass("borderselector");
  284. }
  285. $(e).addClass("disabled-option-item");
  286. }
  287. }
  288. });
  289. for (let i = 0; i < parentsArr.length; i++) {
  290. let currParent = parentsArr[i];
  291. currParent.find(".optiontaganwi").each(function (j, e) {
  292. let isTrue = $(e).hasClass("disabled-option-item");
  293. if (!isTrue) {
  294. $(e).addClass("borderselector");
  295. return false;
  296. }
  297. });
  298. }
  299. // $('.optiontaganwi').addClass('disabled-option-item');
  300. let parentId = $(currentClick).parents(".groupingitems_search");
  301. let parentData = $(parentId).data("parentidgroup");
  302. let parentArr = [];
  303. $(".groupingitems_search").each(function (i, e) {
  304. const curParentId = $(e).data("parentidgroup");
  305. if (parentData != curParentId) {
  306. let obj = {
  307. name: $(e).find(".smallHeadingProductDetails").html(),
  308. arr: [],
  309. };
  310. $(e)
  311. .find(".optiontaganwi")
  312. .each(function (j, evt) {
  313. let id = $(evt).data("tagiditem");
  314. obj.arr.push(id);
  315. });
  316. parentArr.push(obj);
  317. }
  318. });
  319. let arrone = parentArr[0].arr;
  320. let arrtwo = [];
  321. if (parentArr.length > 1) {
  322. arrtwo = parentArr[1]?.arr;
  323. }
  324. let currId = keyOption;
  325. let ids = [];
  326. for (let i = 0; i < arrone.length; i++) {
  327. //let currEl = [currId,arrone[i]];
  328. let currEl = ``;
  329. for (let j = 0; j < arrtwo.length; j++) {
  330. currEl = `${currId}|${arrone[i]}|${arrtwo[j]}`;
  331. ids.push(currEl);
  332. currEl = "";
  333. }
  334. }
  335. let findObj = [];
  336. for (let i = 0; i < ids.length; i++) {
  337. let curId = ids[i];
  338. for (let j = 0; j < itemtagscombinationRes.length; j++) {
  339. const currItem = itemtagscombinationRes[j].tagids.split("|");
  340. let isTrue = true;
  341. for (let k = 0; k < currItem.length; k++) {
  342. if (!curId.includes(currItem[k])) {
  343. isTrue = false;
  344. break;
  345. }
  346. }
  347. if (isTrue) {
  348. findObj.push(itemtagscombinationRes[j]);
  349. }
  350. }
  351. }
  352. $(".optiontaganwi").addClass("disabled-option-item");
  353. for (let i = 0; i < findObj.length; i++) {
  354. let item = findObj[i].tagids.split("|");
  355. for (let j = 0; j < item.length; j++) {
  356. $(`[data-tagiditem=${item[j]}]`).removeClass("disabled-option-item");
  357. }
  358. }
  359. $(parentId)
  360. .find(".optiontaganwi")
  361. .each(function (i, e) {
  362. $(e).removeClass("disabled-option-item");
  363. });
  364. for (let i = 0; i < itemtagscombinationRes.length; i++) {
  365. let currIds = itemtagscombinationRes[i].tagids;
  366. let isTrue = true;
  367. let isPro = false;
  368. for (let j = 0; j < tagsNames.length; j++) {
  369. if (
  370. tagsNames.join().includes("106631360000128") &&
  371. (tagsNames.join().includes("106631360000132") ||
  372. tagsNames.join().includes("106631360000133"))
  373. ) {
  374. isPro = true;
  375. }
  376. if (!currIds.includes(tagsNames[j])) {
  377. isTrue = false;
  378. }
  379. }
  380. if (isTrue) {
  381. const { quantity } = itemtagscombinationRes[i];
  382. if (true) {
  383. currentComb = itemtagscombinationRes[i];
  384. updateDetailsByObj(itemtagscombinationRes[i]);
  385. if (isPro) {
  386. $(`[data-tagiditem="106631360000089"]`).addClass(
  387. " disabled-option-item"
  388. );
  389. $(`[data-tagiditem="106631360000088"]`).addClass(
  390. " disabled-option-item"
  391. );
  392. }
  393. } else {
  394. let name = itemtagscombinationRes[i].itemname.split("-")[0];
  395. $("#addtocart").addClass("disabled");
  396. let itemsName = name;
  397. $(".borderselector").each(function (i, e) {
  398. itemsName += ` ${$(e).html().trim()}`;
  399. });
  400. updateItemId(null);
  401. let defaultImg = itemtagscombinationRes[i].itemimageurl
  402. ? imgServerNameBuild(itemtagscombinationRes[i].itemimageurl)
  403. : `./dist/assets/imgs/nophoto.png`;
  404. debugger;
  405. $(".productDetailsMain > img").attr("src", defaultImg);
  406. alert("updated1");
  407. specification_wrap_action.remove();
  408. $("#skudetailitem").val(-1);
  409. $(".productname").html(itemsName);
  410. $(".msgErrorDetailsItem").removeClass("d-none");
  411. $(".des_productdes").html("");
  412. $(".price").html("");
  413. }
  414. initAddToCart();
  415. return;
  416. }
  417. }
  418. // return;
  419. return;
  420. let commonTags = [];
  421. // $('.optiontaganwi').addClass('disabled-option-item')
  422. for (let i = 0; i < tagsNames.length; i++) {
  423. let currtagName = tagsNames[i];
  424. let arr = currtagItemCom(currtagName);
  425. commonTags.push(arr);
  426. }
  427. // for(let i=0;i<commonTags.length;i++){
  428. // let currObj = commonTags[i];
  429. // for(let item in currObj){
  430. //
  431. // $(`[data-tagiditem="${item}"]`).removeClass('disabled-option-item')
  432. // }
  433. // }
  434. let finalAns = {};
  435. let arra = [];
  436. for (let i = 0; i < commonTags.length; i++) {
  437. let currObj = commonTags[i];
  438. for (let item in currObj) {
  439. let isTrue = true;
  440. for (let j = 0; j < commonTags.length; j++) {
  441. if (j != i) {
  442. let currComb = commonTags[j];
  443. if (!currComb[item]) {
  444. isTrue = false;
  445. }
  446. }
  447. }
  448. if (isTrue) {
  449. arra.push(currObj[item]);
  450. finalAns[currObj[item]] = currObj[item];
  451. $(`[data-tagiditem="${item}"]`).removeClass("disabled-option-item");
  452. }
  453. }
  454. }
  455. // for(let i=0;i<itemtagscombinationRes.length;i++){
  456. // let tagItems = itemtagscombinationRes[i].tagids;;
  457. // if(tagItems.includes(keyOption)){
  458. // let splitArr = tagItems.split('|');
  459. // for(let j=0;j<splitArr.length;j++){
  460. // commonTags[splitArr[j]] = splitArr[j];
  461. // }
  462. // }
  463. // }
  464. // for(let i=0;i<currOptionAvaIds.length;i++){
  465. // let currId = currOptionAvaIds[i];
  466. // if(parentId.find(currId).length === 0){
  467. //
  468. // }
  469. // }
  470. }
  471. function currtagItemCom(keyOption) {
  472. let arr = [];
  473. let commonTags = {};
  474. for (let i = 0; i < itemtagscombinationRes.length; i++) {
  475. let tagItems = itemtagscombinationRes[i].tagids;
  476. if (tagItems.includes(keyOption)) {
  477. let splitArr = tagItems.split("|");
  478. for (let j = 0; j < splitArr.length; j++) {
  479. if (!commonTags[splitArr[j]]) {
  480. commonTags[splitArr[j]] = {
  481. keyOption,
  482. data: itemtagscombinationRes[i],
  483. };
  484. arr.push(splitArr[j]);
  485. }
  486. }
  487. }
  488. }
  489. return commonTags;
  490. }
  491. function updateDetailsByObj(obj) {
  492. $(".productname").html(obj.itemname);
  493. $(".titleproductnav").html(obj.itemname);
  494. let [currencySymbol, amount] = getCurrencySymbol(obj?.pricelist || 0);
  495. let commingSoonText =
  496. window.location.href.toLowerCase().includes("zeno") ||
  497. window.location.href.includes("fyro");
  498. $(".price").html(
  499. obj.pricelist
  500. ? `<span class="font-w600">${currencySymbol}${amount}</span>${
  501. commingSoonText
  502. ? '<span class="mx-1 badge d-md-none bg-gradient-violet text-a-color">Pre Order Now!</span>'
  503. : ""
  504. }`
  505. : "pre order now"
  506. );
  507. appendSpecs(obj.itemid);
  508. $("#skudetailitem").val(obj.sku);
  509. $(".des_productdes").html(obj.itemdescription);
  510. $("#addtocart").attr("data-qty", obj.quantity);
  511. let defaultImg = obj.itemimageurl
  512. ? imgServerNameBuild(obj.itemimageurl)
  513. : `./dist/assets/imgs/nophoto.png`;
  514. let productId = window.location.hash.split("#")[1]?.split("=")[1];
  515. let itemId = window.location.hash.split("#")[2]?.split("=")[1];
  516. history.replaceState(
  517. undefined,
  518. undefined,
  519. `#productId=${productId}#itemid=${obj.itemid}`
  520. );
  521. $(".productDetailsMain > img")
  522. .attr("src", defaultImg)
  523. .attr("loading", "lazy");
  524. magnify("main_show_img", 1.2, defaultImg);
  525. updateItemId(obj.itemid);
  526. if (!obj.pricelist || !obj.quantity) {
  527. $(".buynow").attr("disabled", true);
  528. $("#addtocart").attr("disabled", true);
  529. } else {
  530. $(".buynow").attr("disabled", false);
  531. $("#addtocart").attr("disabled", false);
  532. }
  533. }
  534. function searchComb() {
  535. let valuesSelected = [];
  536. $(".optiontaganwi").removeClass("disabled-option-item");
  537. $("#addtocart").removeClass("disabled");
  538. $(".msgErrorDetailsItem").addClass("d-none");
  539. $(".borderselector,border_selector").each(function (i, el) {
  540. let val = $(el).data("tagiditem");
  541. valuesSelected.push(val);
  542. });
  543. let labelRecord = {};
  544. for (let label in labels) {
  545. labelRecord[label] = false;
  546. }
  547. specification_wrap_action.add();
  548. let unFiler = null;
  549. for (let i = 0; i < itemtagscombinationRes.length; i++) {
  550. const currItem = itemtagscombinationRes[i];
  551. const { tagids } = currItem;
  552. let isTrue = true;
  553. let labelFilter = labelRecord;
  554. for (let i = 0; i < valuesSelected.length; i++) {
  555. if (!tagids.includes(valuesSelected[i])) {
  556. isTrue = false;
  557. unFiler = labelFilter;
  558. break;
  559. }
  560. labelFilter[group[valuesSelected[i]]] = true;
  561. }
  562. if (isTrue) {
  563. const { quantity } = itemtagscombinationRes[i];
  564. if (quantity >= $("#quantity").val() && quantity >= 1) {
  565. currentComb = itemtagscombinationRes[i];
  566. // $('.productname').html(itemtagscombinationRes[i].itemname)
  567. // $('.price').html(itemtagscombinationRes[i].pricelist);
  568. // location.hash = itemtagscombinationRes[i].itemname.trim();
  569. // appendSpecs(itemtagscombinationRes[i].itemid)
  570. // history.replaceState(null, null, `#itemid=${itemtagscombinationRes[i].itemid}#${itemtagscombinationRes[i].itemname.trim()}`);
  571. // $('#skudetailitem').val(itemtagscombinationRes[i].sku)
  572. // $('.des_productdes').html(itemtagscombinationRes[i].itemdescription);
  573. updateDetailsByObj(itemtagscombinationRes[i]);
  574. } else {
  575. let name = itemtagscombinationRes[i].itemname.split("-")[0];
  576. $("#addtocart").addClass("disabled");
  577. let itemsName = name;
  578. $(".borderselector").each(function (i, e) {
  579. itemsName += ` ${$(e).html().trim()}`;
  580. });
  581. updateItemId(null);
  582. let defaultImg = itemtagscombinationRes[i].itemimageurl
  583. ? imgServerNameBuild(itemtagscombinationRes[i].itemimageurl)
  584. : `./dist/assets/imgs/nophoto.png`;
  585. $(".productDetailsMain > img").attr("src", defaultImg);
  586. specification_wrap_action.remove();
  587. $("#skudetailitem").val(-1);
  588. $(".productname").html(itemsName);
  589. // history.replaceState(null, null, `#`);
  590. $(".msgErrorDetailsItem").removeClass("d-none");
  591. $(".des_productdes").html("");
  592. $(".price").html("");
  593. }
  594. initAddToCart();
  595. return;
  596. }
  597. }
  598. let name = itemtagscombinationRes[0].itemname.split("-")[0];
  599. let itemsName = name;
  600. $(".borderselector").each(function (i, e) {
  601. itemsName += `- ${$(e).html().trim()}`;
  602. });
  603. specification_wrap_action.remove();
  604. $(".productname").html(itemsName);
  605. $("#skudetailitem").val(-1);
  606. $(".price").html("");
  607. $("#addtocart").addClass("disabled");
  608. $(".msgErrorDetailsItem").removeClass("d-none");
  609. initAddToCart();
  610. }
  611. function getAllCombination() {
  612. const currClickAttr = $(currentClick).html().trim();
  613. const optionId = $(currentClick).data("tagiditem");
  614. let curr = $(currentClick)
  615. .parents(".groupingitems_search")
  616. .data("parentidgroup");
  617. $(".groupingitems_search").each(function (i, e) {
  618. const id = $(e).data("parentidgroup");
  619. if (id != curr) {
  620. $(e).find(".optiontaganwi").addClass("disabled-option-item");
  621. $(e).find(".borderselector").removeClass("borderselector");
  622. }
  623. });
  624. let ansArr = [];
  625. let index = 0;
  626. let comb = null;
  627. for (let i = 0; i < itemtagscombinationRes.length; i++) {
  628. let currIds = itemtagscombinationRes[i].tagids;
  629. if (currIds.includes(optionId)) {
  630. currIds = currIds.split("|");
  631. for (let j = 0; j < currIds.length; j++) {
  632. if (index == 0 && optionId != currIds[j]) {
  633. $(`[data-tagiditem="${currIds[j]}"]`).addClass("borderselector");
  634. comb = itemtagscombinationRes[i];
  635. index++;
  636. }
  637. $(`[data-tagiditem="${currIds[j]}"]`).removeClass(
  638. "disabled-option-item"
  639. );
  640. // $().parents('[data-tagid]').find()
  641. }
  642. }
  643. }
  644. updateDetailsByObj(comb);
  645. let currentItem = comb.tagids.split("|");
  646. for (let i = 0; i < currentItem.length; i++) {
  647. $(`[data-tagiditem="${currentItem[i]}"]`)
  648. .removeClass("disabled-option-item")
  649. .addClass("borderselector");
  650. }
  651. // history.replaceState(null, null, `#${comb.itemname}`);
  652. // window.location.href = `#${comb.itemname}`
  653. return;
  654. }
  655. async function getProductDetails(id) {
  656. let resData = await API_SERVICES_ACTIONS.getAPIService(
  657. `apis/v4/bizgaze/integrations/products/productattributelist/productid/${id}`,
  658. true
  659. );
  660. if (resData.isError) {
  661. loadingActions.removeLoader();
  662. alert(resData.errorMsg.message);
  663. return;
  664. }
  665. if (resData.response.result == "[]" || !resData.response.result) {
  666. $(".barbgnav").removeClass("d-none");
  667. loadingActions.removeLoader();
  668. toasterHelper("Something Went Wrong");
  669. return;
  670. }
  671. let res = resData.response;
  672. res = JSON.parse(res.result);
  673. if (!res) {
  674. loadingActions.removeLoader();
  675. return;
  676. }
  677. let html = "";
  678. for (let i = 0; i < res.length; i++) {
  679. const currItem = res[i];
  680. // parenttagid means under what label
  681. // tag id means it know unquie id
  682. const {
  683. parentattribute,
  684. parenttagid,
  685. tagid,
  686. attribute,
  687. productid,
  688. } = currItem;
  689. if (labels[parentattribute]) {
  690. labels[parentattribute].items.push({
  691. attribute,
  692. tagid: tagid,
  693. });
  694. } else {
  695. labels[parentattribute] = {
  696. id: parenttagid,
  697. items: [
  698. {
  699. attribute,
  700. tagid: tagid,
  701. },
  702. ],
  703. };
  704. if (parentattribute.toLowerCase() === "colour") {
  705. colorId = parenttagid;
  706. }
  707. html += getParentHTML(parentattribute, productid, parenttagid, i == 0);
  708. }
  709. }
  710. $("#spec-container-details").html(html);
  711. let childIds = [];
  712. for (let item in labels) {
  713. let { id, items } = labels[item];
  714. // $(`[data-tagid=${id}]`)
  715. let html = "";
  716. for (let i = 0; i < items.length; i++) {
  717. const { attribute, tagid } = items[i];
  718. childIds.push(tagid);
  719. group[attribute] = item;
  720. html += getChildHTML(tagid, attribute, i == 0, id);
  721. }
  722. $(`[data-tagid="${id}"]`).html(html);
  723. }
  724. itemtagscombinationRes = await API_SERVICES_ACTIONS.getAPIService(
  725. `apis/v4/bizgaze/integrations/products/getitemwithoutbranch/productid/${id}`,
  726. true
  727. );
  728. itemtagscombinationRes = JSON.parse(itemtagscombinationRes.response.result);
  729. let itemidSearch = window.location.hash.split("#")[2]?.split("=")[1];
  730. if (!itemidSearch) {
  731. itemidSearch = itemtagscombinationRes[0].itemid;
  732. }
  733. let valuesSelected = [];
  734. $(".borderselector").each(function (i, el) {
  735. let val = $(el).html();
  736. valuesSelected.push(val.trim());
  737. });
  738. // let searchParams = window.location.search.split("&");
  739. // let skuId = window.location.hash.split('#')[2].split('=')[1];
  740. // skuId = skuId.split('=')[1]
  741. let isGo = true;
  742. for (let i = 0; i < itemtagscombinationRes.length; i++) {
  743. const currItem = itemtagscombinationRes[i];
  744. const { tagnames, sku, itemid } = currItem;
  745. isThereInLabel[tagnames] = itemtagscombinationRes[i];
  746. let isTrue = true;
  747. if (isGo) {
  748. // for(let i=0;i<valuesSelected.length;i++){
  749. // if(!tagnames.includes(valuesSelected[i])){
  750. // isTrue = false
  751. // }
  752. // }
  753. if (itemidSearch != itemid) {
  754. isTrue = false;
  755. }
  756. // if (i != 0) {
  757. // isTrue = false
  758. // }
  759. if (isTrue) {
  760. currentComb = itemtagscombinationRes[i];
  761. updateDetailsByObj(itemtagscombinationRes[i]);
  762. isGo = false;
  763. let { tagnames, tagids, pricelist } = itemtagscombinationRes[i];
  764. tagids = tagids.split("|");
  765. tagnames = tagnames.split("|");
  766. $(".optiontaganwi").removeClass("borderselector");
  767. for (let i = 0; i < tagids.length; i++) {
  768. $(`[data-tagiditem="${tagids[i]}"]`).addClass("borderselector");
  769. }
  770. break;
  771. // tagiditem
  772. }
  773. }
  774. }
  775. if (isGo && itemtagscombinationRes.length != 0) {
  776. let { tagnames, tagids, pricelist } = itemtagscombinationRes[0];
  777. tagids = tagids.split("|");
  778. tagnames = tagnames.split("|");
  779. $(".optiontaganwi").removeClass("borderselector");
  780. currentComb = itemtagscombinationRes[0];
  781. // updateItemId(itemtagscombinationRes[0].itemid);
  782. for (let i = 0; i < tagids.length; i++) {
  783. $(`[data-type="${tagids[i]}-${tagnames[i]}"]`).addClass(
  784. "borderselector"
  785. );
  786. // $(`[data-type="${tagids[i]}-Eucalyptus Green"]`).removeClass('borderselector');
  787. // $(`[data-type="${tagids[i]}-Desert Brown"]`).removeClass('borderselector');
  788. // $(`[data-type="${tagids[i]}-Deep Sea Blue"]`).removeClass('borderselector');
  789. }
  790. // $('.price').html(pricelist);
  791. // $('.des_productdes').html(itemtagscombinationRes[0].itemdescription);
  792. // appendSpecs(itemtagscombinationRes[0].itemid);
  793. updateDetailsByObj(itemtagscombinationRes[0]);
  794. }
  795. //getAllCombination()
  796. // for(let i=0;i<itemtagscombinationRes.length;i++){
  797. // const {tagnames} = itemtagscombinationRes[i];
  798. // }
  799. $("#spec-container-details")
  800. .children()
  801. .find(".specsmallcard")
  802. .removeClass("specsmallcard");
  803. //getting the first borderselector in first $('.groupingitems_search')[0]
  804. let firstParentGroup = $(".groupingitems_search")[0];
  805. let optionId = $(firstParentGroup)
  806. .find(".borderselector")
  807. .data("tagiditem");
  808. currentClick = $(firstParentGroup).find(".borderselector");
  809. getandsetCombination();
  810. addeventlisteners();
  811. loadingActions.removeLoader();
  812. return;
  813. }
  814. function magnify(imgID, zoom, defaultImg) {
  815. let width = $(window).width();
  816. if (width >= 576) {
  817. var img, glass, w, h, bw;
  818. img = document.getElementById(imgID);
  819. /* Create magnifier glass: */
  820. glass = document.createElement("DIV");
  821. glass.setAttribute("class", "img-magnifier-glass d-none");
  822. /* Insert magnifier glass: */
  823. img.parentElement.insertBefore(glass, img);
  824. /* Set background properties for the magnifier glass: */
  825. glass.style.backgroundImage = "url('" + defaultImg + "')";
  826. glass.style.backgroundRepeat = "no-repeat";
  827. if (img.width <= 400 && img.width <= 400) {
  828. glass.style.backgroundSize = 650 * zoom + "px " + 650 * zoom + "px";
  829. } else {
  830. glass.style.backgroundSize =
  831. img.width * zoom + "px " + img.height * zoom + "px";
  832. }
  833. bw = 3;
  834. w = glass.offsetWidth / 2;
  835. h = glass.offsetHeight / 2;
  836. /* Execute a function when someone moves the magnifier glass over the image: */
  837. glass.addEventListener("mousemove", moveMagnifier);
  838. img.addEventListener("mousemove", moveMagnifier);
  839. /*and also for touch screens:*/
  840. glass.addEventListener("touchmove", moveMagnifier);
  841. img.addEventListener("touchmove", moveMagnifier);
  842. function moveMagnifier(e) {
  843. var pos, x, y;
  844. /* Prevent any other actions that may occur when moving over the image */
  845. e.preventDefault();
  846. /* Get the cursor's x and y positions: */
  847. pos = getCursorPos(e);
  848. x = pos.x;
  849. y = pos.y;
  850. /* Prevent the magnifier glass from being positioned outside the image: */
  851. if (x > img.width - w / zoom) {
  852. x = img.width - w / zoom;
  853. }
  854. if (x < w / zoom) {
  855. x = w / zoom;
  856. }
  857. if (y > img.height - h / zoom) {
  858. y = img.height - h / zoom;
  859. }
  860. if (y < h / zoom) {
  861. y = h / zoom;
  862. }
  863. /* Set the position of the magnifier glass: */
  864. glass.style.left = x - w + "px";
  865. glass.style.top = y - h + "px";
  866. /* Display what the magnifier glass "sees": */
  867. glass.style.backgroundPosition =
  868. "-" + (x * zoom - w + bw) + "px -" + (y * zoom - h + bw) + "px";
  869. }
  870. function getCursorPos(e) {
  871. var a,
  872. x = 0,
  873. y = 0;
  874. e = e || window.event;
  875. /* Get the x and y positions of the image: */
  876. a = img.getBoundingClientRect();
  877. /* Calculate the cursor's x and y coordinates, relative to the image: */
  878. x = e.pageX - a.left;
  879. y = e.pageY - a.top;
  880. /* Consider any page scrolling: */
  881. x = x - window.pageXOffset;
  882. y = y - window.pageYOffset;
  883. return { x: x, y: y };
  884. }
  885. }
  886. }
  887. }
  888. startDetails();