Нема описа
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. $(function () {
  2. // configuration js
  3. let m2DriveMaxQty = 4;
  4. let m2DriveSelectedQty = 0;
  5. // configuration items
  6. localStorage.setItem("currency", "INR");
  7. const configCatgories = [
  8. {
  9. id: 1,
  10. title: "barebone",
  11. maxQty: 1,
  12. },
  13. {
  14. id: 2,
  15. title: "processor",
  16. maxQty: 3,
  17. },
  18. {
  19. id: 3,
  20. title: "memory",
  21. maxQty: 1,
  22. },
  23. {
  24. id: 4,
  25. title: "m.2 drive",
  26. maxQty: 4,
  27. },
  28. ];
  29. const bareboneProducts = [
  30. {
  31. id: 1,
  32. title: `Intel<sup>®</sup> C252 Chipset - 1U - 2x SATA - 1x M.2 - Dual Intel<sup>®</sup> 1-Gigabit Ethernet (RJ45) - 350W Power Supply`,
  33. qty: 3,
  34. price: 99,
  35. },
  36. ];
  37. const processorProducts = [
  38. {
  39. productcatid: 1,
  40. productcattitle: `Intel<sup>®</sup> Xeon<sup>®</sup> E-2300 Processor Series`,
  41. products: [
  42. {
  43. id: 1,
  44. title: `Quad-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2314 Processor 2.8GHz 8MB
  45. Cache (65W)`,
  46. qty: 3,
  47. price: 99,
  48. },
  49. {
  50. id: 2,
  51. title: `Quad-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2334 Processor 3.4GHz 8MB Cache (65W)`,
  52. qty: 3,
  53. price: 99,
  54. },
  55. {
  56. id: 3,
  57. title: `Eight-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2378 Processor 2.6GHz 16MB Cache (65W)`,
  58. qty: 3,
  59. price: 99,
  60. },
  61. ],
  62. },
  63. {
  64. productcatid: 2,
  65. productcattitle: `Intel<sup>®</sup> Xeon<sup>®</sup> E-2300 Processor Series with Intel<sup>®</sup> UHD P750 Graphics`,
  66. products: [
  67. {
  68. id: 1,
  69. title: `Quad-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2324G Processor 3.1GHz
  70. 8MB Cache (65W)`,
  71. qty: 3,
  72. price: 99,
  73. },
  74. {
  75. id: 2,
  76. title: `Quad-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2374G Processor 3.7GHz 8MB Cache (80W)`,
  77. qty: 2,
  78. price: 99,
  79. },
  80. {
  81. id: 3,
  82. title: `Six-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2356G Processor 3.2GHz 12MB Cache (80W)`,
  83. qty: 1,
  84. price: 99,
  85. },
  86. {
  87. id: 4,
  88. title: `Six-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2386G Processor 3.5GHz 12MB Cache (95W)`,
  89. qty: 1,
  90. price: 99,
  91. },
  92. ],
  93. },
  94. ];
  95. const memoryProducts = [
  96. {
  97. id: 1,
  98. title: `16GB PC4-25600 3200MHz DDR4 ECC UDIMM`,
  99. qty: 2,
  100. price: 99,
  101. },
  102. {
  103. id: 2,
  104. title: `32GB PC4-25600 3200MHz DDR4 ECC UDIMM`,
  105. qty: 2,
  106. price: 220,
  107. },
  108. ];
  109. const m2driveProducts = [
  110. {
  111. productcatid: 1,
  112. productcattitle: `Kioxia XG6 M.2 PCIe 3.1 x4 NVMe Solid State Drives`,
  113. products: [
  114. {
  115. id: 1,
  116. title: `256GB Kioxia XG6 M.2 PCIe 3.1 x4 NVMe Solid State
  117. Drive`,
  118. qty: 4,
  119. price: 99,
  120. },
  121. {
  122. id: 2,
  123. title: `512GB Kioxia XG6 M.2 PCIe 3.1 x4 NVMe Solid State Drive`,
  124. qty: 4,
  125. price: 149,
  126. },
  127. {
  128. id: 3,
  129. title: `1.0TB Kioxia XG6 M.2 PCIe 3.1 x4 NVMe Solid State Drive`,
  130. qty: 4,
  131. price: 269,
  132. },
  133. ],
  134. },
  135. {
  136. productcatid: 2,
  137. productcattitle: `Intel<sup>®</sup> DC P4801X M.2 PCIe 3.0 x4 NVMe Solid State Drives`,
  138. products: [
  139. {
  140. id: 1,
  141. title: `100GB Intel<sup>®</sup> Optane™ SSD DC P4801X Series M.2 PCIe 3.0 x4 NVMe
  142. Solid State Drive`,
  143. qty: 4,
  144. price: 99,
  145. },
  146. {
  147. id: 2,
  148. title: `200GB Intel<sup>®</sup> Optane™ SSD DC P4801X Series M.2 PCIe
  149. 3.0 x4 NVMe Solid State Drive`,
  150. qty: 4,
  151. price: 149,
  152. },
  153. {
  154. id: 3,
  155. title: `1.0TB Kioxia XG6 M.2 PCIe 3.1 x4 NVMe Solid State Drive`,
  156. qty: 4,
  157. price: 269,
  158. },
  159. ],
  160. },
  161. {
  162. productcatid: 3,
  163. productcattitle: `Micron 7400 PRO M.2 PCIe 4.0 x4 NVMe Solid State Drives`,
  164. products: [
  165. {
  166. id: 1,
  167. title: `480GB Micron 7400 PRO Series M.2 22x80 PCIe 4.0 x4 NVMe Solid
  168. State Drive`,
  169. qty: 4,
  170. price: 99,
  171. },
  172. {
  173. id: 2,
  174. title: `960GB Micron 7400 PRO Series M.2 22x80 PCIe 4.0 x4
  175. NVMe Solid State Drive`,
  176. qty: 4,
  177. price: 149,
  178. },
  179. {
  180. id: 3,
  181. title: `1.92TB Micron 7400 PRO Series M.2 22x110 PCIe 4.0 x4 NVMe Solid
  182. State Drive`,
  183. qty: 4,
  184. price: 269,
  185. },
  186. ],
  187. },
  188. ];
  189. //Bind Config Categories
  190. bindConfigurations();
  191. updateItemsCount();
  192. // max quantity-progress-bar
  193. function bindConfigurations() {
  194. let configCatHtml = "";
  195. $.each(configCatgories, function (i, cat) {
  196. const id = cat.id;
  197. let title = cat.title;
  198. let qty = cat.maxQty;
  199. let maxQtyHtml = "";
  200. if (title == "m.2 drive") {
  201. title = "m2-drive";
  202. }
  203. if (title == "m2-drive" || title == "processor") {
  204. let quantityHtml = "";
  205. if (title == "m2-drive") {
  206. let qtyProgressBarHtml = "";
  207. for (let i = 0; i < qty; i++) {
  208. qtyProgressBarHtml += `<span class="sms progress-bar progress-bar-${i}"></span>`;
  209. }
  210. quantityHtml = `<span>Quantity:</span><div class="max-qty-wrap ml-15"><div class="d-flex justify-content-between align-items-center"><div class="d-flex flex-column"><div class="qty-progress-bars d-flex align-items-center">${qtyProgressBarHtml}</div><div class="d-flex justify-content-between flex-wrap align-items-center mt-1"><span class="small">Max Quantity: ${qty}</span><div class="small"><span class="selected-qty">0</span>/<span class="max-qty-span">${qty}</span></div></div></div></div></div>`;
  211. }
  212. maxQtyHtml = `<div class="text-white p-3 border-radius-custom flex-wrap float-lg-end d-flex align-items-center config-max-quantity">${quantityHtml}</div>`;
  213. }
  214. configCatHtml += `<div class="product-config-selector accordion mb-20" id="config-${title}" data-maxqty='${qty}'>
  215. <div class="config-heading d-flex justify-content-between flex-wrap align-items-center">
  216. <h5 class="text-white p-3 border-radius-custom text-uppercase">${title}
  217. </h5>
  218. ${maxQtyHtml}
  219. </div>
  220. <div class="config-content p-0"></div>
  221. </div>`;
  222. });
  223. $("#block-content-main").html(configCatHtml);
  224. bindAllConfigProducts();
  225. }
  226. // appending-html
  227. function bindAllConfigProducts() {
  228. bindBareboneAndMemoryProducts("barebone");
  229. bindBareboneAndMemoryProducts("memory");
  230. bindProcessorAndM2DriveProducts("processor");
  231. bindProcessorAndM2DriveProducts("m2-drive");
  232. bindEventListeners();
  233. }
  234. function bindBareboneAndMemoryProducts(cat) {
  235. let productHtml = "";
  236. let productsArr = bareboneProducts;
  237. if (cat == "memory") {
  238. productsArr = memoryProducts;
  239. }
  240. $.each(productsArr, function (i, product) {
  241. productHtml += `<p class="provide-content product-item">
  242. <div
  243. class="name-of-config card-body row justify-content-between py-1 align-items-center config-product-item" data-id='${product.id}' data-cat='${cat}' data-price='${product.price}'>
  244. <div class="form-check mt-2 col-lg-7" id="form-check">
  245. <input class="form-check-input product-radio-btn" id="${cat}-radio-btn-${product.id}" type="radio" name="radio-btns"
  246. value="${product.title}">
  247. <label class="form-check-label" for="${cat}-radio-btn-${product.id}">
  248. <strong>${product.title}</strong>
  249. </label>
  250. </div>
  251. <div class="btn-group config-quantity-btn text-black col-lg-2">
  252. <select class="form-select fw-bold qty-selector">`;
  253. for (let i = 0; i <= product.qty; i++) {
  254. productHtml += `<option value="${i}">Qty: ${i}</option>`;
  255. }
  256. productHtml += `</select>
  257. </div>
  258. <div class="config-pricing col-lg-2">
  259. <span class="config-price-span p-2 border-radius-custom"><span>+</span><span class="total-price-amount price-wrap d-flex align-items-center"><span class="currency-symbol">&#8377;</span><span class="product-price">${product.price}</span></span></span>
  260. </div>
  261. </div>
  262. </p>`;
  263. });
  264. $(`#config-${cat} .config-content`).html(productHtml);
  265. $('.qty-selector option[value="0"]').text("Select");
  266. }
  267. function bindProcessorAndM2DriveProducts(cat) {
  268. let productCatHtml = "";
  269. let productsArr = processorProducts;
  270. let accordion = "processorProductAccordion";
  271. let collapse = "processorProductcollapse";
  272. let lastSelectDataAttr = "";
  273. if (cat == "m2-drive") {
  274. productsArr = m2driveProducts;
  275. accordion = "m2DriveProductAccordion";
  276. collapse = "m2DriveProductcollapse";
  277. lastSelectDataAttr = 'data-lastval="1"';
  278. }
  279. $.each(productsArr, function (i, productcat) {
  280. const productcatid = productcat.productcatid;
  281. const productcattitle = productcat.productcattitle;
  282. productCatHtml += `<div class="accordion mt-4 border-radius-custom" id="${accordion}-${productcatid}">
  283. <div class="accordion-item">
  284. <h2 class="accordion-header">
  285. <button class="accordion-button" style="color:#4e4c7d; background-color: #e7e9f4;"
  286. type="button" data-bs-toggle="collapse" data-bs-target="#${collapse}-${productcatid}"
  287. aria-expanded="true" aria-controls="${collapse}-${productcatid}">
  288. <strong>${productcattitle}</strong>
  289. </button>
  290. </h2>
  291. <div id="${collapse}-${productcatid}" class="accordion-collapse collapse show" data-bs-parent="#${accordion}-${productcatid}">
  292. <div class="accordion-body">`;
  293. let productHtml = "";
  294. $.each(productcat.products, function (i, product) {
  295. productHtml += `
  296. <div class="name-of-config row justify-content-between py-1 align-items-center config-product-item" data-id='${
  297. product.id
  298. }' data-cat='${cat}' data-price='${
  299. product.price
  300. }' data-productcatid='${productcatid}'>
  301. <div class="form-check mt-2 col-lg-7" id="form-check">
  302. ${appendProcessorAndM2DriveInput(
  303. cat,
  304. product.id,
  305. product.title,
  306. productcatid
  307. )}
  308. </div>
  309. <div class="btn-group config-quantity-btn text-black col-lg-2">
  310. <select class="form-select fw-bold qty-selector" ${lastSelectDataAttr}><option value="0">Select</option>`;
  311. for (let i = 1; i <= product.qty; i++) {
  312. productHtml += `<option value="${i}">Qty: ${i}</option>`;
  313. }
  314. productHtml += `</select>
  315. </div>
  316. <div class="config-pricing col-lg-2">
  317. <span class="config-price-span p-2 border-radius-custom"><span>+</span><span class="processor-total-price total-price-amount price-wrap d-flex align-items-center"><span class="currency-symbol">&#8377;</span><span class="product-price">${product.price}</span></span> </span>
  318. </div>
  319. </div>`;
  320. });
  321. productCatHtml += productHtml;
  322. productCatHtml += `</div>
  323. </div>
  324. </div>
  325. </div>`;
  326. });
  327. $(`#config-${cat} .config-content`).html(productCatHtml);
  328. //$('.qty-selector option[value="0"]').text('Select')
  329. }
  330. function appendProcessorAndM2DriveInput(cat, id, title, productcatid = 0) {
  331. if (cat == "m2-drive") {
  332. return `<input class="form-check-input product-check-btn" type="checkbox" name="m2Drive-check-btns"
  333. id="${cat}-check-btn-${productcatid}-${id}" value="${title}" >
  334. <label class="form-check-label" for="${cat}-check-btn-${productcatid}-${id}">
  335. <strong>${title}</strong>
  336. </label>`;
  337. } else {
  338. return `<input class="form-check-input product-radio-btn" type="radio" name="processor-radio-btns"
  339. id="${cat}-radio-btn-${productcatid}-${id}" value="${title}" >
  340. <label class="form-check-label" for="${cat}-radio-btn-${productcatid}-${id}">
  341. <strong>${title}</strong>
  342. </label>`;
  343. }
  344. }
  345. // select and radio-check-btn-section
  346. function bindEventListeners() {
  347. var alertBox = `<div class="alert alert-warning alert-dismissible fade show" role="alert">
  348. <strong>Holy guacamole!</strong> You should check in on some of those fields below.
  349. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  350. </div>`;
  351. $(".product-radio-btn").click(function (e) {
  352. const radioEl = $(this);
  353. const accordionID = $(this).parents(".accordion").attr("id");
  354. const parentEl = radioEl.parents(".config-product-item");
  355. const val = radioEl.val();
  356. const productCatId = parentEl.attr("data-id");
  357. const cat = parentEl.attr("data-cat");
  358. const qty = parseInt(parentEl.find(".qty-selector").val("1"));
  359. const price = qty * parseInt(parentEl.attr("data-price"));
  360. const id = parentEl.attr("data-id");
  361. $(`#config-${cat}`).find(".config-price-span").removeClass("active");
  362. parentEl.find(".config-price-span").addClass("active");
  363. bindSelectedProduct(cat, val, qty, price, id, productCatId, accordionID);
  364. updateItemsCount();
  365. updateTotalCartPrice();
  366. });
  367. $(".qty-selector").change(function () {
  368. const selectEl = $(this);
  369. const accordionId = $(this).parents(".accordion").attr("id");
  370. const parentEl = selectEl.parents(".config-product-item");
  371. const val = parseInt(selectEl.val());
  372. const lastSelectedVal = parseInt(selectEl.attr("data-lastval"));
  373. const price = val * parseFloat(parentEl.attr("data-price")).toFixed(2);
  374. const cat = parentEl.attr("data-cat");
  375. const id = parentEl.attr("data-id");
  376. if (!parentEl.find("input").is(":checked")) {
  377. parentEl.find("input").trigger("click");
  378. parentEl.find(".config-price-span").addClass("active");
  379. }
  380. const selectedQty = val - lastSelectedVal;
  381. if (cat == "m2-drive") {
  382. if (m2DriveMaxQty >= m2DriveSelectedQty + selectedQty) {
  383. m2DriveSelectedQty += selectedQty;
  384. selectEl.attr("data-lastval", val);
  385. m2DriveProgress();
  386. parentEl.find(".product-price").text(price);
  387. const selecedSummaryProduct = $(
  388. `.${cat}-cart-product-${id}[data-accordionid="${accordionId}"]`
  389. );
  390. selecedSummaryProduct.find(".summary-total-qty .qty-span").text(val);
  391. selecedSummaryProduct.find(".product-price").text(price);
  392. updateTotalCartPrice();
  393. } else {
  394. alert("Quantity Max limit reached");
  395. selectEl.val(lastSelectedVal);
  396. parentEl.find("input").trigger("click");
  397. return false;
  398. }
  399. } else {
  400. parentEl.find(".product-price").text(price);
  401. const selecedSummaryProduct = $(
  402. `.${cat}-cart-product-${id}[data-accordionid="${accordionId}"]`
  403. );
  404. selecedSummaryProduct.find(".summary-total-qty .qty-span").text(val);
  405. selecedSummaryProduct.find(".product-price").text(price);
  406. updateTotalCartPrice();
  407. }
  408. });
  409. $(".product-check-btn").click(function () {
  410. const checkEl = $(this);
  411. const ElementId = $(this).parents(".accordion").attr("id");
  412. const parentEl = checkEl.parents(".config-product-item");
  413. const val = checkEl.val();
  414. const productCatId = parentEl.attr("data-productcatid");
  415. const cat = parentEl.attr("data-cat");
  416. const qtySelectEl = parentEl.find(".qty-selector");
  417. const qty = parseInt(qtySelectEl.val("1"));
  418. const price = parentEl.attr("data-price");
  419. const totalPrice = qty * parseFloat(price).toFixed(2);
  420. const id = parentEl.attr("data-id");
  421. if (checkEl.is(":checked")) {
  422. m2DriveSelectedQty++;
  423. parentEl.addClass("selected");
  424. } else {
  425. m2DriveSelectedQty -= qty;
  426. qtySelectEl.val("1").attr("data-lastval", "1").trigger("change");
  427. parentEl.removeClass("selected").find(".product-price").text(price);
  428. }
  429. if (m2DriveSelectedQty > m2DriveMaxQty) {
  430. alert("Quantity Max limit reached");
  431. return false;
  432. } else {
  433. parentEl.find(".config-price-span").toggleClass("active");
  434. bindSelectedProduct(
  435. cat,
  436. val,
  437. qty,
  438. totalPrice,
  439. id,
  440. productCatId,
  441. ElementId
  442. );
  443. updateItemsCount();
  444. updateTotalCartPrice();
  445. m2DriveProgress();
  446. }
  447. });
  448. // $('.product-check-btn ,.product-radio-btn').click(function() {
  449. // qtySelectEl.val('1').attr('data-lastval', '1').trigger('change');;
  450. // });
  451. }
  452. function m2DriveProgress() {
  453. if (m2DriveSelectedQty <= m2DriveMaxQty) {
  454. $(".qty-progress-bars .progress-bar").removeClass("active");
  455. for (let i = 0; i < m2DriveSelectedQty; i++) {
  456. $(".qty-progress-bars .progress-bar").eq(i).addClass("active");
  457. }
  458. $("#config-m2-drive .max-qty-wrap")
  459. .find(".selected-qty")
  460. .text(m2DriveSelectedQty);
  461. }
  462. if (m2DriveSelectedQty == m2DriveMaxQty) {
  463. disableM2DriveOptions();
  464. } else {
  465. enableM2DriveOptions();
  466. }
  467. }
  468. function enableM2DriveOptions() {
  469. $(".product-check-btn").prop("disabled", false);
  470. $("#config-m2-drive .qty-selector").prop("disabled", false);
  471. }
  472. function disableM2DriveOptions() {
  473. $(".product-check-btn").not(":checked").prop("disabled", true);
  474. $("#config-m2-drive .config-product-item")
  475. .not(".selected")
  476. .find(".qty-selector")
  477. .prop("disabled", true);
  478. }
  479. // summary section
  480. function bindSelectedProduct(
  481. cat,
  482. val,
  483. qty,
  484. price,
  485. id,
  486. productCatId = "",
  487. ElementId
  488. ) {
  489. const summaryProductHtml = `<li class="w-100 my-1 d-flex align-items-center cart-product-item ${cat}-cart-product-${id}" data-accordionid="${ElementId}" data-productcatid='${productCatId}'><span class="summary-total-qty"><span class="qty-span">${qty}</span><i class="fa fa-times"></i></span>
  490. <div class="flex-grow-1 d-flex align-items-center justify-content-between"><span class="summary-product-val mr-2">${val}</span>
  491. <span class="price-wrap d-flex align-items-center"><span class="summary-plus-sign">+</span><span class="currency-symbol" id="summary-currency-symbol">&#8377;</span><span class="order-price price-span product-price ml-auto">${price}</span></span>
  492. </div>
  493. </li>`;
  494. if (cat == "m2-drive") {
  495. if (
  496. $(
  497. `.m2-drive-cart-product-${id}[data-productcatid = "${productCatId}"] `
  498. ).length
  499. ) {
  500. $(
  501. `.m2-drive-cart-product-${id}[data-productcatid = "${productCatId}"]`
  502. ).remove();
  503. } else {
  504. $(`#${cat}-summary .summary-list`).append(summaryProductHtml);
  505. }
  506. } else {
  507. $(`#${cat}-summary .summary-list`).html(summaryProductHtml);
  508. }
  509. if ($(`#${cat}-summary .summary-list li`).length) {
  510. $(`#${cat}-summary`).removeClass("d-none");
  511. } else {
  512. $(`#${cat}-summary`).addClass("d-none");
  513. }
  514. }
  515. // items-count
  516. function updateItemsCount() {
  517. const cartProductCount = $(
  518. "#productOrderSummary .cart-product-item"
  519. ).length;
  520. $(".summary-head #items-count").text(cartProductCount);
  521. if (cartProductCount >= 1) {
  522. $(".your-order-wrap").show();
  523. $(".your-order-wrap-empty").hide();
  524. } else {
  525. $(".your-order-wrap").hide();
  526. $(".your-order-wrap-empty").show();
  527. }
  528. }
  529. // total-cart-price
  530. function updateTotalCartPrice() {
  531. let totalPrice = 0;
  532. $("#productOrderSummary .cart-product-item")
  533. .find(".price-span")
  534. .each(function (i, e) {
  535. totalPrice += Number($(e).text().trim());
  536. });
  537. $("#productOrderSummary #total-amount").text(totalPrice);
  538. }
  539. //currency-converter:
  540. var rates = {
  541. INR: {
  542. value: 1,
  543. symbol: "₹",
  544. USD: 0.01311,
  545. INR: 1,
  546. GBP: 0.01,
  547. },
  548. USD: {
  549. value: 75,
  550. symbol: "$",
  551. USD: 1,
  552. INR: 76.32,
  553. GBP: 0.76,
  554. },
  555. GBP: {
  556. value: 100,
  557. symbol: "£",
  558. USD: 1.31,
  559. INR: 100,
  560. GBP: 1,
  561. },
  562. };
  563. let usercurency;
  564. if (localStorage.getItem("currency")) {
  565. usercurency = localStorage.getItem("currency");
  566. } else {
  567. usercurency = "INR";
  568. }
  569. $("#custom-selects").val(usercurency.toLowerCase());
  570. function updatePrices(previousCurrency, currentCurrency) {
  571. $(".product-price").each(function (i, el) {
  572. console.log(currentCurrency);
  573. let val = parseFloat($(el).text());
  574. let con = val * rates[previousCurrency][currentCurrency],
  575. _con;
  576. if (currentCurrency == "INR") {
  577. _con = Math.round(con);
  578. } else {
  579. _con = con;
  580. }
  581. let curentSymbol = rates[currentCurrency];
  582. $(el).text(_con.toFixed(2));
  583. $(el).siblings(".currency-symbol").text(curentSymbol.symbol);
  584. });
  585. $("[data-price]").each(function (i, e) {
  586. let val = parseFloat($(this).attr("data-price"));
  587. let con = val * rates[previousCurrency][currentCurrency],
  588. _con;
  589. if (currentCurrency == "INR") {
  590. _con = Math.round(con);
  591. } else {
  592. _con = parseInt(con);
  593. }
  594. $(this).attr("data-price", con);
  595. });
  596. let amount = parseFloat($("#total-amount").text()).toFixed(2);
  597. let curentSymbol = rates[currentCurrency];
  598. let conVal = amount * rates[previousCurrency][currentCurrency],
  599. _con;
  600. if (currentCurrency == "INR") {
  601. _con = Math.round(conVal);
  602. } else {
  603. _con = conVal;
  604. }
  605. $("#total-amount").text(parseFloat(_con).toFixed(2));
  606. $(".currency-symbol").text(curentSymbol.symbol);
  607. }
  608. $("#custom-selects").on("change", function (e) {
  609. let previousCurrency = localStorage.getItem("currency");
  610. localStorage.setItem("currency", e.target.value.toUpperCase());
  611. updatePrices(previousCurrency, e.target.value.toUpperCase());
  612. });
  613. updatePrices(rates[usercurency]);
  614. });