Spaces:
Running

krish95 commited on
Commit
ef9e54e
·
verified ·
1 Parent(s): 4c31fe4

Fix the product pricing logic on the website so that the correct price is shown based on the selected validity option from the dropdown. Each product object contains Notion fields: - Price_1M - Price_3M - Price_6M Bind the selected validity from the dropdown to dynamically show the correct price. Use this logic in the code: ```js function getPriceByValidity(product, validity) { if (validity === "1 Month") return product.Price_1M; if (validity === "3 Months") return product.Price_3M; if (validity === "6 Months") return product.Price_6M; return "Not available"; } - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +25 -44
index.html CHANGED
@@ -281,9 +281,9 @@
281
  <div class="mt-6">
282
  <label for="modal-validity" class="block text-sm font-medium text-[#1F1F1F]">Select Validity</label>
283
  <select id="modal-validity" class="mt-1 block w-full px-4 py-2 rounded-2xl border border-[#9CA3AF] focus:outline-none focus:ring-2 focus:ring-[#5A96E3] focus:border-transparent">
284
- <option value="1">1 Month</option>
285
- <option value="3">3 Months</option>
286
- <option value="12">1 Year</option>
287
  </select>
288
  </div>
289
 
@@ -307,6 +307,13 @@
307
  </div>
308
 
309
  <script>
 
 
 
 
 
 
 
310
  document.addEventListener('DOMContentLoaded', function() {
311
  // Initialize Feather Icons
312
  feather.replace();
@@ -404,16 +411,16 @@
404
  <div class="mt-4">
405
  <label for="validity-${product.id}" class="block text-sm font-medium text-[#1F1F1F]">Validity</label>
406
  <select id="validity-${product.id}" class="product-validity mt-1 block w-full px-3 py-1.5 text-sm rounded-2xl border border-[#9CA3AF] focus:outline-none focus:ring-2 focus:ring-[#5A96E3] focus:border-transparent">
407
- <option value="1">1 Month</option>
408
- <option value="3">3 Months</option>
409
- <option value="12">1 Year</option>
410
  </select>
411
  </div>
412
 
413
  <div class="mt-3 flex justify-between items-center">
414
  <p class="text-sm font-medium text-[#1F1F1F]">Price:</p>
415
- <p class="product-price text-lg font-bold text-[#5A96E3]" data-price-1="${product['Price - 1 Month']}" data-price-3="${product['Price - 3 Months']}" data-price-12="${product['Price - 1 Year']}">
416
- ₹${product['Price - 1 Month']}
417
  </p>
418
  </div>
419
 
@@ -442,17 +449,11 @@
442
  const price3 = priceElement.dataset.price3;
443
  const price12 = priceElement.dataset.price12;
444
 
445
- switch(this.value) {
446
- case '1':
447
- priceElement.textContent = `₹${price1}`;
448
- break;
449
- case '3':
450
- priceElement.textContent = `₹${price3}`;
451
- break;
452
- case '12':
453
- priceElement.textContent = `₹${price12}`;
454
- break;
455
- }
456
  });
457
  });
458
 
@@ -467,20 +468,8 @@
467
  let validityText = '';
468
  let price = '';
469
 
470
- switch(validity) {
471
- case '1':
472
- validityText = '1 Month';
473
- price = product['Price - 1 Month'];
474
- break;
475
- case '3':
476
- validityText = '3 Months';
477
- price = product['Price - 3 Months'];
478
- break;
479
- case '12':
480
- validityText = '1 Year';
481
- price = product['Price - 1 Year'];
482
- break;
483
- }
484
 
485
  const message = `Hi! I want to purchase ${product.Name} with ${validityText} validity for ₹${price}. Please send more details.`;
486
  const encodedMessage = encodeURIComponent(message);
@@ -636,17 +625,9 @@
636
  const validitySelect = document.getElementById('modal-validity');
637
  validitySelect.value = '1';
638
  validitySelect.addEventListener('change', function() {
639
- switch(this.value) {
640
- case '1':
641
- modalPrice.textContent = `₹${product['Price - 1 Month']}`;
642
- break;
643
- case '3':
644
- modalPrice.textContent = `₹${product['Price - 3 Months']}`;
645
- break;
646
- case '12':
647
- modalPrice.textContent = `₹${product['Price - 1 Year']}`;
648
- break;
649
- }
650
  });
651
 
652
  // Set up buy button
 
281
  <div class="mt-6">
282
  <label for="modal-validity" class="block text-sm font-medium text-[#1F1F1F]">Select Validity</label>
283
  <select id="modal-validity" class="mt-1 block w-full px-4 py-2 rounded-2xl border border-[#9CA3AF] focus:outline-none focus:ring-2 focus:ring-[#5A96E3] focus:border-transparent">
284
+ <option value="1 Month">1 Month</option>
285
+ <option value="3 Months">3 Months</option>
286
+ <option value="6 Months">6 Months</option>
287
  </select>
288
  </div>
289
 
 
307
  </div>
308
 
309
  <script>
310
+ function getPriceByValidity(product, validity) {
311
+ if (validity === "1 Month") return product.Price_1M;
312
+ if (validity === "3 Months") return product.Price_3M;
313
+ if (validity === "6 Months") return product.Price_6M;
314
+ return "Not available";
315
+ }
316
+
317
  document.addEventListener('DOMContentLoaded', function() {
318
  // Initialize Feather Icons
319
  feather.replace();
 
411
  <div class="mt-4">
412
  <label for="validity-${product.id}" class="block text-sm font-medium text-[#1F1F1F]">Validity</label>
413
  <select id="validity-${product.id}" class="product-validity mt-1 block w-full px-3 py-1.5 text-sm rounded-2xl border border-[#9CA3AF] focus:outline-none focus:ring-2 focus:ring-[#5A96E3] focus:border-transparent">
414
+ <option value="1 Month">1 Month</option>
415
+ <option value="3 Months">3 Months</option>
416
+ <option value="6 Months">6 Months</option>
417
  </select>
418
  </div>
419
 
420
  <div class="mt-3 flex justify-between items-center">
421
  <p class="text-sm font-medium text-[#1F1F1F]">Price:</p>
422
+ <p class="product-price text-lg font-bold text-[#5A96E3]" data-price-1m="${product.Price_1M}" data-price-3m="${product.Price_3M}" data-price-6m="${product.Price_6M}">
423
+ ₹${product.Price_1M}
424
  </p>
425
  </div>
426
 
 
449
  const price3 = priceElement.dataset.price3;
450
  const price12 = priceElement.dataset.price12;
451
 
452
+ const validity = this.value;
453
+ const productId = this.id.split('-')[1];
454
+ const product = products.find(p => p.id === productId);
455
+ const price = getPriceByValidity(product, validity);
456
+ priceElement.textContent = `₹${price}`;
 
 
 
 
 
 
457
  });
458
  });
459
 
 
468
  let validityText = '';
469
  let price = '';
470
 
471
+ validityText = validity;
472
+ price = getPriceByValidity(product, validity);
 
 
 
 
 
 
 
 
 
 
 
 
473
 
474
  const message = `Hi! I want to purchase ${product.Name} with ${validityText} validity for ₹${price}. Please send more details.`;
475
  const encodedMessage = encodeURIComponent(message);
 
625
  const validitySelect = document.getElementById('modal-validity');
626
  validitySelect.value = '1';
627
  validitySelect.addEventListener('change', function() {
628
+ const validity = this.value;
629
+ const price = getPriceByValidity(product, validity);
630
+ modalPrice.textContent = `₹${price}`;
 
 
 
 
 
 
 
 
631
  });
632
 
633
  // Set up buy button