No Description
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 35KB

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