diff --git a/database/db_scripts/webshop_test-data.sql b/database/db_scripts/webshop_test-data.sql index 2e4bd83..d94c6b2 100644 --- a/database/db_scripts/webshop_test-data.sql +++ b/database/db_scripts/webshop_test-data.sql @@ -2,15 +2,15 @@ USE webshop; -- Product Categories INSERT INTO product_category (id, name) -VALUES (1, 'Electronics'); +VALUES (1, 'Motorräder'); INSERT INTO product_category (id, name) -VALUES (2, 'Home Appliances'); +VALUES (2, 'Oldtimer'); INSERT INTO product_category (id, name) -VALUES (3, 'Clothing'); +VALUES (3, 'Sportwägen'); INSERT INTO product_category (id, name) -VALUES (4, 'Sports'); +VALUES (4, 'LKWs'); INSERT INTO product_category (id, name) -VALUES (5, 'Books'); +VALUES (5, 'Kleinwägen'); -- Discounts INSERT INTO discount (id, name, description, discount_percent, active) diff --git a/package-lock.json b/package-lock.json index d926216..b3c988d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "sniper", + "name": "webshop", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "sniper", + "name": "webshop", "version": "1.0.0", "license": "ISC", "dependencies": { @@ -15,7 +15,9 @@ "express-session": "^1.18.1", "mysql": "^2.18.1", "mysql2": "^3.12.0", - "path": "^0.12.7" + "node": "^22.15.0", + "path": "^0.12.7", + "server.js": "^1.0.0" } }, "node_modules/accepts": { @@ -674,6 +676,28 @@ "node": ">= 0.6" } }, + "node_modules/node": { + "version": "22.15.0", + "resolved": "https://registry.npmjs.org/node/-/node-22.15.0.tgz", + "integrity": "sha512-qrOEL83lNt+Jbh9pekl5xQrZK+QRJz51m2IGGCu2NENgbG6Go0D1QUBvjbejP8jB2eokQpX1AorDLbKQ/FxuYA==", + "hasInstallScript": true, + "license": "ISC", + "dependencies": { + "node-bin-setup": "^1.0.0" + }, + "bin": { + "node": "bin/node" + }, + "engines": { + "npm": ">=5.0.0" + } + }, + "node_modules/node-bin-setup": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/node-bin-setup/-/node-bin-setup-1.1.3.tgz", + "integrity": "sha512-opgw9iSCAzT2+6wJOETCpeRYAQxSopqQ2z+N6BXwIMsQQ7Zj5M8MaafQY8JMlolRR6R1UXg2WmhKp0p9lSOivg==", + "license": "ISC" + }, "node_modules/object-inspect": { "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", @@ -894,6 +918,12 @@ "node": ">= 0.8.0" } }, + "node_modules/server.js": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/server.js/-/server.js-1.0.0.tgz", + "integrity": "sha512-fO4IvzkZ09bBB++XU/gWGuzxJs0OpghSd/34mlW8coMoakLzj/+W5d1pHX+I+7H52GkBKu96UQU0K5vptNjaqg==", + "license": "ISC" + }, "node_modules/set-function-length": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", diff --git a/package.json b/package.json index a95f1e3..f34f8f5 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { - "name": "sniper", + "name": "webshop", "version": "1.0.0", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "node server.js" + "start": "npm install && node server.js" }, "keywords": [], "author": "", @@ -12,13 +12,13 @@ "description": "Webshop Autohändler", "dependencies": { "app-root-path": "^3.1.0", - "dotenv": "^16.4.5", - "express": "^4.21.1", "dotenv": "^16.4.7", "express": "^4.21.2", "express-session": "^1.18.1", "mysql": "^2.18.1", "mysql2": "^3.12.0", - "path": "^0.12.7" + "node": "^22.15.0", + "path": "^0.12.7", + "server.js": "^1.0.0" } } diff --git a/public/404.html b/public/404.html index 4b776da..69a558c 100644 --- a/public/404.html +++ b/public/404.html @@ -1,27 +1,38 @@ + + - - - Seite nicht gefunden - - - + + + Seite nicht gefunden + + + + + + -
+
-
+ +
-

🚧 Seite nicht gefunden 🚧

-

Diese Seite existiert nicht oder befindet sich noch in Arbeit.

- Zur Startseite +

🚧 Seite nicht gefunden 🚧

+

Diese Seite existiert nicht oder befindet sich noch in Arbeit.

+ + Zur Startseite
-
+
\ No newline at end of file diff --git a/public/Warenkorb/warenkorb.html b/public/Warenkorb/warenkorb.html index 762972d..011faa7 100644 --- a/public/Warenkorb/warenkorb.html +++ b/public/Warenkorb/warenkorb.html @@ -11,28 +11,144 @@
-

🛒 Dein Warenkorb

- -
-
- Produkt 1 - -
- -
- -
-
- Produkt 2 -
- -
- -
-
- +
+

Dein Warenkorb

+
+
+ +
+ + diff --git a/public/bestellformular/bestellformular.html b/public/bestellformular/bestellformular.html index 4c81016..999319a 100644 --- a/public/bestellformular/bestellformular.html +++ b/public/bestellformular/bestellformular.html @@ -6,26 +6,27 @@ Bestellformular +
-
+
-
+

Bestellformular

- + - + - + @@ -37,48 +38,273 @@ - +
+ + + +
+
- Bestellung absenden + + Bestellung absenden
+ const payload = { + user_id: parseInt(userData.kundenNr, 10), + produkte: produkte + }; + + try { + const response = await fetch('/api/bestellung', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(payload) + }); + + const result = await response.json(); + + if (response.ok) { + // Bestellung erfolgreich -> Weiterleitung + window.location.href = "/bestellung"; + } else { + alert('Fehler: ' + result.message); + } + + } catch (error) { + console.error('Fehler beim Abschicken der Bestellung:', error); + alert('Serverfehler beim Abschicken der Bestellung.'); + } + }); + + // Artikelnummer prüfen bei Eingabe + formular.addEventListener('input', async function (event) { + if (event.target.classList.contains('ArtikelNrText')) { + if (event.target.value.trim() !== '') { + await pruefeVerfuegbarkeit(event.target); + fuegeNeuesArtikelFeldHinzu(); + } + } + }); + }); + + // Funktion: Verfügbarkeit prüfen + async function pruefeVerfuegbarkeit(inputFeld) { + const artikelnummer = inputFeld.value.trim(); + const verfuegbarkeitDiv = inputFeld.parentElement.querySelector('.verfuegbarkeit'); + const sendButton = document.getElementById('sendOrder'); + + if (artikelnummer.length === 0) { + verfuegbarkeitDiv.textContent = ""; + return; + } + + try { + const response = await fetch(`/api/pruefe-artikel?nummer=${encodeURIComponent(artikelnummer)}`); + const data = await response.json(); + + const artikelDivs = document.querySelectorAll('.Artikel'); + artikelVerfuegbarkeiten = []; + + artikelDivs.forEach(div => { + const artikelNrInput = div.querySelector('.ArtikelNrText'); + const verfDiv = div.querySelector('.verfuegbarkeit'); + + if (artikelNrInput.value.trim() !== '') { + if (artikelNrInput === inputFeld) { + if (data.verfuegbar) { + verfDiv.textContent = "Artikel verfügbar."; + verfDiv.style.color = "green"; + artikelVerfuegbarkeiten.push(true); + } else { + verfDiv.textContent = "Artikel nicht verfügbar!"; + verfDiv.style.color = "red"; + artikelVerfuegbarkeiten.push(false); + } + } else { + // Für andere Felder bisherige Anzeige berücksichtigen + if (verfDiv.textContent.includes("nicht verfügbar")) { + artikelVerfuegbarkeiten.push(false); + } else { + artikelVerfuegbarkeiten.push(true); + } + } + } + }); + + // Button sperren/freigeben + if (artikelVerfuegbarkeiten.every(status => status === true)) { + sendButton.disabled = false; + } else { + sendButton.disabled = true; + } + + } catch (error) { + console.error('Fehler bei der Artikelsuche:', error); + verfuegbarkeitDiv.textContent = "Fehler bei der Prüfung."; + verfuegbarkeitDiv.style.color = "orange"; + sendButton.disabled = true; + } + } + + // Funktion: Neues Artikelfeld hinzufügen + function fuegeNeuesArtikelFeldHinzu() { + const formular = document.getElementById('bestellform'); + const artikelnummerFelder = formular.querySelectorAll('.ArtikelNrText'); + const letztesFeld = artikelnummerFelder[artikelnummerFelder.length - 1]; + + if (letztesFeld && letztesFeld.value.trim() !== '') { + const neueArtikelDiv = document.createElement('div'); + neueArtikelDiv.className = 'Artikel'; + neueArtikelDiv.innerHTML = ` + + + +
+ `; + + const sendButton = document.getElementById('sendOrder'); + formular.insertBefore(neueArtikelDiv, sendButton); + } + } + + // Funktion: Artikel löschen + function loescheArtikel(button) { + const artikelDiv = button.parentElement; + artikelDiv.remove(); + } + + function ladeWarenkorb() { + // RICHTIG lesen: aus localStorage (nicht sessionStorage!) + const warenkorb = JSON.parse(localStorage.getItem('warenkorb')) || []; + + const formular = document.getElementById('bestellform'); + const sendButton = document.getElementById('sendOrder'); + + if (warenkorb.length === 0) { + console.log('Kein Warenkorb gefunden oder Warenkorb ist leer.'); + return; + } + + warenkorb.forEach(produkt => { + const artikelDiv = document.createElement('div'); + artikelDiv.className = 'Artikel'; + artikelDiv.innerHTML = ` + + + +
+ `; + formular.insertBefore(artikelDiv, sendButton); + }); + } + +
diff --git a/public/bestellung/bestellung.html b/public/bestellung/bestellung.html index 9edc202..0827942 100644 --- a/public/bestellung/bestellung.html +++ b/public/bestellung/bestellung.html @@ -1,65 +1,103 @@ - - - Ihre Bestellung - - - + + + Ihre Bestellung + + +
-
+

Ihre Bestellung:

- -
-

Kundennummer:

-

Produkt-ID:

-

Produktname:

-

Preis:

-
+ +
+

Kundennummer:

+

Produkt-ID:

+

Produktname:

+

Preis:

+
-
+
- + + window.addEventListener('DOMContentLoaded', ladeBestellung); + + diff --git a/public/header_footer/footer.html b/public/header_footer/footer.html index 8178fca..521d90b 100644 --- a/public/header_footer/footer.html +++ b/public/header_footer/footer.html @@ -1,8 +1,14 @@ - + + diff --git a/public/header_footer/header.html b/public/header_footer/header.html index 9c19192..dd4c9c6 100644 --- a/public/header_footer/header.html +++ b/public/header_footer/header.html @@ -1,35 +1,60 @@ - +
-
- Modellauto-Shop Logo -

Modellauto - Shop

-
-
- -
+ diff --git a/public/login/login.html b/public/login/login.html index 52d9e7a..6276142 100644 --- a/public/login/login.html +++ b/public/login/login.html @@ -1,31 +1,51 @@ + + + Login + + + + Login -
+
- +

Login

+ +