OlToby commited on
Commit
10ed1b3
·
verified ·
1 Parent(s): bc4f086

🐳 17/04 - 12:34 - it doesnt work anymore

Browse files
Files changed (2) hide show
  1. index.html +1 -0
  2. script.js +148 -26
index.html CHANGED
@@ -8,6 +8,7 @@
8
 
9
  <!-- Tailwind CSS -->
10
  <script src="https://cdn.tailwindcss.com"></script>
 
11
 
12
  <!-- Lucide Icons -->
13
  <script src="https://unpkg.com/lucide@latest"></script>
 
8
 
9
  <!-- Tailwind CSS -->
10
  <script src="https://cdn.tailwindcss.com"></script>
11
+ <link rel="stylesheet" href="styles.css">
12
 
13
  <!-- Lucide Icons -->
14
  <script src="https://unpkg.com/lucide@latest"></script>
script.js CHANGED
@@ -12,6 +12,12 @@ const app = {
12
  productQuantity: 1,
13
  activeCategory: null,
14
  products: [],
 
 
 
 
 
 
15
 
16
  // Translations
17
  translations: {
@@ -414,6 +420,24 @@ const app = {
414
  if (preview) preview.textContent = cardNameInput.value.toUpperCase() || 'YOUR NAME';
415
  });
416
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
  },
418
 
419
  // Generate mock products
@@ -520,6 +544,15 @@ const app = {
520
 
521
  // Navigation
522
  navigate(page) {
 
 
 
 
 
 
 
 
 
523
  // Hide all pages
524
  document.querySelectorAll('[id^="page-"]').forEach(el => el.classList.add('hidden'));
525
 
@@ -769,9 +802,9 @@ const app = {
769
  },
770
 
771
  updateCartUI() {
772
- const cartCount = this.cart.reduce((sum, item) => sum + item.quantity, 0);
773
  // Prices are already inclusive of VAT, so total is just the sum
774
- const total = this.cart.reduce((sum, item) => sum + (item.price * item.quantity), 0);
775
  // Calculate VAT portion from the inclusive total: VAT = Total - (Total / 1.081)
776
  const vat = total - (total / 1.081);
777
  const subtotal = total - vat; // Price without VAT
@@ -859,10 +892,25 @@ const app = {
859
  drawer.classList.remove('pointer-events-none');
860
  panel.classList.add('open');
861
  overlay.classList.remove('opacity-0');
 
862
  } else {
863
  drawer.classList.add('pointer-events-none');
864
  panel.classList.remove('open');
865
  overlay.classList.add('opacity-0');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
866
  }
867
  },
868
 
@@ -896,9 +944,37 @@ const app = {
896
  // Checkout
897
  checkout() {
898
  if (this.cart.length === 0) return;
899
- this.toggleCart();
 
900
  this.selectedPaymentMethod = null;
901
  this.checkoutStep = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
902
  this.navigate('checkout');
903
  this.renderCheckoutSummary();
904
  this.updateCheckoutSteps();
@@ -918,17 +994,23 @@ const app = {
918
  },
919
 
920
  renderCheckoutSummary() {
921
- // Listen for shipping method changes
922
- document.querySelectorAll('input[name="shipping"]').forEach(radio => {
923
- radio.addEventListener('change', () => this.renderCheckoutSummary());
924
- });
 
 
 
925
 
926
- const total = this.cart.reduce((sum, item) => sum + (item.price * item.quantity), 0);
927
  const vat = total - (total / 1.081);
928
  const subtotal = total - vat;
929
  const shippingCost = this.getShippingCost();
930
  const grandTotal = total + shippingCost;
931
 
 
 
 
932
  // Items list
933
  const itemsEl = document.getElementById('checkout-items');
934
  if (itemsEl) {
@@ -961,13 +1043,12 @@ const app = {
961
  getShippingCost() {
962
  const shippingRadio = document.querySelector('input[name="shipping"]:checked');
963
  if (!shippingRadio) return 0;
964
- const total = this.cart.reduce((sum, item) => sum + (item.price * item.quantity), 0);
965
  if (shippingRadio.value === 'express') return 9.90;
966
  return 0; // standard & pickup are free
967
  },
968
 
969
  getGrandTotal() {
970
- const total = this.cart.reduce((sum, item) => sum + (item.price * item.quantity), 0);
971
  return total + this.getShippingCost();
972
  },
973
 
@@ -1062,6 +1143,13 @@ const app = {
1062
  this.checkoutStep = 2;
1063
  this.updateCheckoutSteps();
1064
  this.renderCheckoutSummary();
 
 
 
 
 
 
 
1065
  window.scrollTo(0, 0);
1066
  },
1067
 
@@ -1077,18 +1165,24 @@ const app = {
1077
  // Update radio UI
1078
  document.querySelectorAll('.payment-method-label').forEach(label => {
1079
  const isActive = label.dataset.method === method;
 
 
1080
  if (isActive) {
1081
  label.classList.add('border-brand-600', 'bg-brand-50', 'dark:bg-brand-900/20');
1082
  label.classList.remove('border-gray-200', 'dark:border-gray-700');
1083
- label.querySelector('.payment-dot').classList.remove('hidden');
1084
- label.querySelector('.payment-radio').classList.add('border-brand-600');
1085
- label.querySelector('.payment-radio').classList.remove('border-gray-300', 'dark:border-gray-600');
 
 
1086
  } else {
1087
  label.classList.remove('border-brand-600', 'bg-brand-50', 'dark:bg-brand-900/20');
1088
  label.classList.add('border-gray-200', 'dark:border-gray-700');
1089
- label.querySelector('.payment-dot').classList.add('hidden');
1090
- label.querySelector('.payment-radio').classList.remove('border-brand-600');
1091
- label.querySelector('.payment-radio').classList.add('border-gray-300', 'dark:border-gray-600');
 
 
1092
  }
1093
  });
1094
 
@@ -1097,9 +1191,18 @@ const app = {
1097
  const formEl = document.getElementById(`payment-${method}`);
1098
  if (formEl) formEl.classList.remove('hidden');
1099
 
1100
- // Enable pay button
1101
  const payBtn = document.getElementById('pay-now-btn');
1102
- if (payBtn) payBtn.disabled = false;
 
 
 
 
 
 
 
 
 
1103
 
1104
  lucide.createIcons();
1105
  },
@@ -1189,12 +1292,16 @@ const app = {
1189
 
1190
  // Simulate payment processing
1191
  setTimeout(() => {
 
 
 
 
1192
  this.completeOrder();
1193
  }, 2000);
1194
  },
1195
 
1196
  completeOrder() {
1197
- const grandTotal = this.getGrandTotal();
1198
  const paymentMethodNames = {
1199
  de: { twint: 'TWINT', card: 'Kreditkarte', paypal: 'PayPal', bank: 'Banküberweisung' },
1200
  fr: { twint: 'TWINT', card: 'Carte de crédit', paypal: 'PayPal', bank: 'Virement bancaire' },
@@ -1206,22 +1313,37 @@ const app = {
1206
  it: { standard: 'Posta Standard', express: 'Posta Express', pickup: 'Ritiro sul posto' }
1207
  };
1208
 
 
 
 
 
1209
  // Set confirmation details
1210
- document.getElementById('order-number').textContent = this.orderReference;
1211
- document.getElementById('confirmation-payment-method').textContent = paymentMethodNames[this.language]?.[this.selectedPaymentMethod] || this.selectedPaymentMethod;
1212
- document.getElementById('confirmation-shipping').textContent = shippingMethodNames[this.language]?.[this.shippingInfo?.method || 'standard'] || 'Standard';
1213
- document.getElementById('confirmation-total').textContent = `CHF ${grandTotal.toFixed(2)}`;
 
 
 
 
 
 
 
1214
 
1215
  // Estimated delivery
1216
  const deliveryDate = new Date();
1217
- if (this.shippingInfo?.method === 'express') {
1218
  deliveryDate.setDate(deliveryDate.getDate() + 1);
1219
- } else if (this.shippingInfo?.method === 'pickup') {
1220
  deliveryDate.setDate(deliveryDate.getDate() + 3);
1221
  } else {
1222
  deliveryDate.setDate(deliveryDate.getDate() + 3);
1223
  }
1224
- document.getElementById('confirmation-delivery').textContent = deliveryDate.toLocaleDateString(this.language === 'de' ? 'de-CH' : this.language === 'fr' ? 'fr-CH' : 'it-CH');
 
 
 
 
1225
 
1226
  // Move to confirmation step
1227
  this.checkoutStep = 3;
 
12
  productQuantity: 1,
13
  activeCategory: null,
14
  products: [],
15
+ checkoutStep: 1,
16
+ selectedPaymentMethod: null,
17
+ shippingInfo: null,
18
+ orderReference: '',
19
+ cartDrawerOpen: false,
20
+ shippingListenersAttached: false,
21
 
22
  // Translations
23
  translations: {
 
420
  if (preview) preview.textContent = cardNameInput.value.toUpperCase() || 'YOUR NAME';
421
  });
422
  }
423
+
424
+ // Live card number preview
425
+ const cardNumberInput = document.getElementById('card-number');
426
+ if (cardNumberInput) {
427
+ cardNumberInput.addEventListener('input', () => {
428
+ const preview = document.getElementById('card-preview-number');
429
+ if (preview) preview.textContent = cardNumberInput.value || '•••• •••• •••• ••••';
430
+ });
431
+ }
432
+
433
+ // Live expiry preview
434
+ const cardExpiryInput = document.getElementById('card-expiry');
435
+ if (cardExpiryInput) {
436
+ cardExpiryInput.addEventListener('input', () => {
437
+ const preview = document.getElementById('card-preview-expiry');
438
+ if (preview) preview.textContent = cardExpiryInput.value || 'MM/YY';
439
+ });
440
+ }
441
  },
442
 
443
  // Generate mock products
 
544
 
545
  // Navigation
546
  navigate(page) {
547
+ // If navigating to 'shop', go to home and scroll to products
548
+ if (page === 'shop') {
549
+ page = 'home';
550
+ setTimeout(() => {
551
+ const productsSection = document.getElementById('products-section');
552
+ if (productsSection) productsSection.scrollIntoView({ behavior: 'smooth' });
553
+ }, 100);
554
+ }
555
+
556
  // Hide all pages
557
  document.querySelectorAll('[id^="page-"]').forEach(el => el.classList.add('hidden'));
558
 
 
802
  },
803
 
804
  updateCartUI() {
805
+ const cartCount = this.cart.reduce((sum, item) => sum + (item.quantity || 0), 0);
806
  // Prices are already inclusive of VAT, so total is just the sum
807
+ const total = this.cart.reduce((sum, item) => sum + ((item.price || 0) * (item.quantity || 1)), 0);
808
  // Calculate VAT portion from the inclusive total: VAT = Total - (Total / 1.081)
809
  const vat = total - (total / 1.081);
810
  const subtotal = total - vat; // Price without VAT
 
892
  drawer.classList.remove('pointer-events-none');
893
  panel.classList.add('open');
894
  overlay.classList.remove('opacity-0');
895
+ this.cartDrawerOpen = true;
896
  } else {
897
  drawer.classList.add('pointer-events-none');
898
  panel.classList.remove('open');
899
  overlay.classList.add('opacity-0');
900
+ this.cartDrawerOpen = false;
901
+ }
902
+ },
903
+
904
+ closeCartDrawer() {
905
+ const drawer = document.getElementById('cart-drawer');
906
+ const panel = document.getElementById('cart-panel');
907
+ const overlay = document.getElementById('cart-overlay');
908
+
909
+ if (drawer && !drawer.classList.contains('pointer-events-none')) {
910
+ drawer.classList.add('pointer-events-none');
911
+ if (panel) panel.classList.remove('open');
912
+ if (overlay) overlay.classList.add('opacity-0');
913
+ this.cartDrawerOpen = false;
914
  }
915
  },
916
 
 
944
  // Checkout
945
  checkout() {
946
  if (this.cart.length === 0) return;
947
+ // Properly close the cart drawer (don't toggle - it might open it)
948
+ this.closeCartDrawer();
949
  this.selectedPaymentMethod = null;
950
  this.checkoutStep = 1;
951
+
952
+ // Reset payment method UI
953
+ document.querySelectorAll('.payment-method-label').forEach(label => {
954
+ label.classList.remove('border-brand-600', 'bg-brand-50', 'dark:bg-brand-900/20');
955
+ label.classList.add('border-gray-200', 'dark:border-gray-700');
956
+ const dot = label.querySelector('.payment-dot');
957
+ if (dot) dot.classList.add('hidden');
958
+ const radio = label.querySelector('.payment-radio');
959
+ if (radio) {
960
+ radio.classList.remove('border-brand-600');
961
+ radio.classList.add('border-gray-300', 'dark:border-gray-600');
962
+ }
963
+ });
964
+ document.querySelectorAll('.payment-form').forEach(f => f.classList.add('hidden'));
965
+ const payBtn = document.getElementById('pay-now-btn');
966
+ if (payBtn) payBtn.disabled = true;
967
+
968
+ // Reset shipping form styles
969
+ ['ship-firstname', 'ship-lastname', 'ship-email', 'ship-address', 'ship-zip', 'ship-city'].forEach(id => {
970
+ const el = document.getElementById(id);
971
+ if (el) el.classList.remove('border-red-400', 'dark:border-red-500');
972
+ });
973
+ const errorEl1 = document.getElementById('checkout-error-step1');
974
+ if (errorEl1) errorEl1.classList.add('hidden');
975
+ const errorEl2 = document.getElementById('checkout-error-step2');
976
+ if (errorEl2) errorEl2.classList.add('hidden');
977
+
978
  this.navigate('checkout');
979
  this.renderCheckoutSummary();
980
  this.updateCheckoutSteps();
 
994
  },
995
 
996
  renderCheckoutSummary() {
997
+ // Listen for shipping method changes (only once)
998
+ if (!this.shippingListenersAttached) {
999
+ document.querySelectorAll('input[name="shipping"]').forEach(radio => {
1000
+ radio.addEventListener('change', () => this.renderCheckoutSummary());
1001
+ });
1002
+ this.shippingListenersAttached = true;
1003
+ }
1004
 
1005
+ const total = this.cart.reduce((sum, item) => sum + ((item.price || 0) * (item.quantity || 1)), 0);
1006
  const vat = total - (total / 1.081);
1007
  const subtotal = total - vat;
1008
  const shippingCost = this.getShippingCost();
1009
  const grandTotal = total + shippingCost;
1010
 
1011
+ // Store grand total for later use
1012
+ this._grandTotal = grandTotal;
1013
+
1014
  // Items list
1015
  const itemsEl = document.getElementById('checkout-items');
1016
  if (itemsEl) {
 
1043
  getShippingCost() {
1044
  const shippingRadio = document.querySelector('input[name="shipping"]:checked');
1045
  if (!shippingRadio) return 0;
 
1046
  if (shippingRadio.value === 'express') return 9.90;
1047
  return 0; // standard & pickup are free
1048
  },
1049
 
1050
  getGrandTotal() {
1051
+ const total = this.cart.reduce((sum, item) => sum + ((item.price || 0) * (item.quantity || 1)), 0);
1052
  return total + this.getShippingCost();
1053
  },
1054
 
 
1143
  this.checkoutStep = 2;
1144
  this.updateCheckoutSteps();
1145
  this.renderCheckoutSummary();
1146
+
1147
+ // Reset and enable pay button for step 2
1148
+ const payBtn = document.getElementById('pay-now-btn');
1149
+ if (payBtn && this.selectedPaymentMethod) {
1150
+ payBtn.disabled = false;
1151
+ }
1152
+
1153
  window.scrollTo(0, 0);
1154
  },
1155
 
 
1165
  // Update radio UI
1166
  document.querySelectorAll('.payment-method-label').forEach(label => {
1167
  const isActive = label.dataset.method === method;
1168
+ const dot = label.querySelector('.payment-dot');
1169
+ const radio = label.querySelector('.payment-radio');
1170
  if (isActive) {
1171
  label.classList.add('border-brand-600', 'bg-brand-50', 'dark:bg-brand-900/20');
1172
  label.classList.remove('border-gray-200', 'dark:border-gray-700');
1173
+ if (dot) dot.classList.remove('hidden');
1174
+ if (radio) {
1175
+ radio.classList.add('border-brand-600');
1176
+ radio.classList.remove('border-gray-300', 'dark:border-gray-600');
1177
+ }
1178
  } else {
1179
  label.classList.remove('border-brand-600', 'bg-brand-50', 'dark:bg-brand-900/20');
1180
  label.classList.add('border-gray-200', 'dark:border-gray-700');
1181
+ if (dot) dot.classList.add('hidden');
1182
+ if (radio) {
1183
+ radio.classList.remove('border-brand-600');
1184
+ radio.classList.add('border-gray-300', 'dark:border-gray-600');
1185
+ }
1186
  }
1187
  });
1188
 
 
1191
  const formEl = document.getElementById(`payment-${method}`);
1192
  if (formEl) formEl.classList.remove('hidden');
1193
 
1194
+ // Enable and restore pay button
1195
  const payBtn = document.getElementById('pay-now-btn');
1196
+ if (payBtn) {
1197
+ payBtn.disabled = false;
1198
+ const grandTotal = this._grandTotal || this.getGrandTotal();
1199
+ const payNowText = this.translations[this.language]?.pay_now || 'Pay Now';
1200
+ payBtn.innerHTML = `
1201
+ <i data-lucide="lock" class="w-5 h-5"></i>
1202
+ <span>${payNowText}</span>
1203
+ <span id="pay-now-amount">CHF ${grandTotal.toFixed(2)}</span>
1204
+ `;
1205
+ }
1206
 
1207
  lucide.createIcons();
1208
  },
 
1292
 
1293
  // Simulate payment processing
1294
  setTimeout(() => {
1295
+ // Restore pay button state
1296
+ if (payBtn) {
1297
+ payBtn.disabled = false;
1298
+ }
1299
  this.completeOrder();
1300
  }, 2000);
1301
  },
1302
 
1303
  completeOrder() {
1304
+ const grandTotal = this._grandTotal || this.getGrandTotal();
1305
  const paymentMethodNames = {
1306
  de: { twint: 'TWINT', card: 'Kreditkarte', paypal: 'PayPal', bank: 'Banküberweisung' },
1307
  fr: { twint: 'TWINT', card: 'Carte de crédit', paypal: 'PayPal', bank: 'Virement bancaire' },
 
1313
  it: { standard: 'Posta Standard', express: 'Posta Express', pickup: 'Ritiro sul posto' }
1314
  };
1315
 
1316
+ const currentLang = this.language || 'de';
1317
+ const currentPayment = this.selectedPaymentMethod || 'twint';
1318
+ const currentShipping = (this.shippingInfo && this.shippingInfo.method) || 'standard';
1319
+
1320
  // Set confirmation details
1321
+ const orderNumEl = document.getElementById('order-number');
1322
+ if (orderNumEl) orderNumEl.textContent = this.orderReference || 'ALN-PENDING';
1323
+
1324
+ const payMethodEl = document.getElementById('confirmation-payment-method');
1325
+ if (payMethodEl) payMethodEl.textContent = (paymentMethodNames[currentLang] && paymentMethodNames[currentLang][currentPayment]) || currentPayment;
1326
+
1327
+ const shipMethodEl = document.getElementById('confirmation-shipping');
1328
+ if (shipMethodEl) shipMethodEl.textContent = (shippingMethodNames[currentLang] && shippingMethodNames[currentLang][currentShipping]) || 'Standard';
1329
+
1330
+ const totalEl = document.getElementById('confirmation-total');
1331
+ if (totalEl) totalEl.textContent = `CHF ${grandTotal.toFixed(2)}`;
1332
 
1333
  // Estimated delivery
1334
  const deliveryDate = new Date();
1335
+ if (currentShipping === 'express') {
1336
  deliveryDate.setDate(deliveryDate.getDate() + 1);
1337
+ } else if (currentShipping === 'pickup') {
1338
  deliveryDate.setDate(deliveryDate.getDate() + 3);
1339
  } else {
1340
  deliveryDate.setDate(deliveryDate.getDate() + 3);
1341
  }
1342
+ const deliveryEl = document.getElementById('confirmation-delivery');
1343
+ if (deliveryEl) {
1344
+ const locale = currentLang === 'de' ? 'de-CH' : currentLang === 'fr' ? 'fr-CH' : 'it-CH';
1345
+ deliveryEl.textContent = deliveryDate.toLocaleDateString(locale);
1346
+ }
1347
 
1348
  // Move to confirmation step
1349
  this.checkoutStep = 3;