This repository was archived by the owner on Jul 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart.php
More file actions
57 lines (49 loc) · 2.76 KB
/
Copy pathcart.php
File metadata and controls
57 lines (49 loc) · 2.76 KB
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
<?php include 'partials/header.php'; ?>
<h1>Your Cart</h1>
<h2>Total: <?= htmlspecialchars((string) $total) ?> €</h2>
<?php $products = $cart['products'] ?? []; ?>
<?php $menus = $cart['menus'] ?? []; ?>
<?php if (empty($products) && empty($menus)) { ?>
<p>Your cart is empty.</p>
<?php } else { ?>
<ul>
<!-- Display Products -->
<?php foreach ($products as $lineKey => $item): ?>
<li>
<strong><?= htmlspecialchars($item['name'] ?? '') ?></strong>
x <?= (int) ($item['quantity'] ?? 0) ?>,
<?= htmlspecialchars((string) ($item['price'] ?? 0)) ?> €
<br>
<?php if (!empty($item['options']) && is_array($item['options'])): ?>
<?php foreach ($item['options'] as $slot): ?>
<div>
<?= htmlspecialchars($slot['categoryName'] ?? '') ?>:
<ul>
<?php foreach ($slot['choices'] ?? [] as $choice): ?>
<li>
<?= htmlspecialchars($choice['name'] ?? '') ?>
<?php if (isset($choice['priceDelta']) && (float) $choice['priceDelta'] !== 0.0): ?>
(<?= htmlspecialchars((string) $choice['priceDelta']) ?> €)
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>
<?php endif; ?>
<form method="POST" action="/cart">
<input type="hidden" name="product_id" value="<?= (int) ($item['product_id'] ?? 0) ?>">
<input type="hidden" name="product_name" value="<?= htmlspecialchars($item['name'] ?? '', ENT_QUOTES) ?>">
<input type="hidden" name="product_price" value="<?= htmlspecialchars((string) ($item['price'] ?? 0), ENT_QUOTES) ?>">
<input type="hidden" name="customization" value="<?= htmlspecialchars(json_encode($item['options'] ?? []), ENT_QUOTES) ?>">
<input type="hidden" name="line_key" value="<?= htmlspecialchars((string) ($item['line_key'] ?? $lineKey), ENT_QUOTES) ?>">
<input type="hidden" name="is_from_cart" value="True">
<button type="submit" name="action" value="add">Add one</button>
<button type="submit" name="action" value="remove">Remove one</button>
</form>
</li>
<?php endforeach; ?>
<!-- TODO: Display Menus -->
</ul>
<?php } ?>
<?php include 'partials/footer.php'; ?>