-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabschluss.php
118 lines (100 loc) · 4.26 KB
/
abschluss.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
session_start();
require('core/conn.php');
$produkte = require('core/produkte.php');
$einstellungen = require('core/einstellungen.php');
if (!isset($_SESSION['warenkorb'])) {
$_SESSION['warenkorb'] = [];
header('Location: shop.php');
} else {
if (count($_SESSION['warenkorb']) <= 0) {
$_SESSION['warenkorb'] = [];
header('Location: shop.php');
}
}
if (!isset($_SESSION['user'])) {
header('Location: login.php?to=abschluss.php');
}
try {
$user = $_SESSION['user'];
// SQL Abfrage erstellen
$sql = "INSERT INTO Bestellungen (kunde,";
foreach ($_SESSION['warenkorb'] as $id => $anzahl) {
$sql .= strtolower($produkte[$id]['name']) . ', ';
}
$sql = substr($sql, 0, -2) . ') VALUES (' . $user['id'] . ', ';
foreach ($_SESSION['warenkorb'] as $anzahl) {
$sql .= "$anzahl, ";
}
$sql = substr($sql, 0, -2) . ')';
// Ausführen
$conn = getDatenbank();
$conn->exec($sql);
$bestellnummer = $conn->lastInsertId();
$_SESSION['letzteBestellung'] = $_SESSION['warenkorb'];
$_SESSION['warenkorb'] = [];
} catch (PDOException $e) {
$errors = [$e->getMessage()];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $einstellungen['firma'] ?> Bestellbestätigung</title>
<?php include('includes/head.inc.php') ?>
</head>
<body class="font-mono">
<?php include('includes/header.inc.php') ?>
<main class="flex flex-col gap-8 py-16 mx-auto max-w-7xl">
<!-- Fehlermeldungen -->
<?php if (isset($errors)) echo Komponente::alert(true, $errors); ?>
<section>
<h1 class="text-4xl">Vielen Dank für deine Bestellung <?= $_SESSION['user']['vorname'] ?>!</h1>
<p>Wir bei <?= $einstellungen['firma'] ?> sind dir sehr dankbar dass du uns hilfst ökologisch wertvolle Arbeit mit Bienen zu betreiben! Bitte beehren Sie uns als bald wieder.</p>
</section>
<section class="p-6 bg-gray-200">
<h3 class="text-2xl">Deine Bestellung: (Bestellnummer: <?= $bestellnummer ?>)</h3>
<?php foreach ($_SESSION['letzteBestellung'] as $sorte => $anzahl) : ?>
<div class="flex items-center gap-3 px-3 py-3 my-3 bg-gray-200">
<img src="images/<?= $sorte ?>.png" class="w-24 h-24" alt="">
<div class="w-full">
<h2 class="mb-3 text-xl"><?= $anzahl ?>x <?= $produkte[$sorte]['name'] ?></h2>
<span class="flex flex-col items-center justify-between w-full gap-3 sm:flex-row">
<div class="flex items-center justify-end grow">
<p class="px-3 py-2 text-xl bg-white">CHF <?= sprintf('%.2f', $produkte[$sorte]['preis'] * $anzahl) ?></p>
</div>
</span>
</div>
</div>
<?php endforeach; ?>
</section>
<div class="flex flex-col items-center gap-3 px-3 py-3 my-3 bg-gray-200">
<div class="flex flex-col items-stretch w-full gap-2 mb-3">
<div class="border-t-2 border-black"></div>
<div class="border-t-2 border-black"></div>
</div>
<div class="flex items-center justify-between w-full">
<div class="flex gap-4 items-center">
<?= Komponente::link('Weiter einkaufen', 'shop.php') ?>
<?= Komponente::link('Ausloggen', 'logout.php', 'red') ?>
</div>
<div class="flex items-center justify-end grow">
<?php
$gesamt = 0;
foreach ($_SESSION['letzteBestellung'] as $sorte => $anzahl) {
$gesamt += $produkte[$sorte]['preis'] * $anzahl;
}
?>
<span class="flex items-center gap-2">
<p class="text-xl">Gesamt:</p>
<p class="px-3 py-2 text-xl bg-white">CHF <?= sprintf('%.2f', $gesamt) ?></p>
</span>
</div>
</div>
</div>
</main>
</body>
</html>