Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.

Commit a9f8409

Browse files
authored
Merge branch 'dev' into fix-checkout
2 parents 016fed4 + c5e010f commit a9f8409

3 files changed

Lines changed: 207 additions & 87 deletions

File tree

src/app/views/cart.php

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,52 @@
11
<?php include 'partials/header.php'; ?>
22

33
<h1>Your Cart</h1>
4-
<h2>Total: <?= htmlspecialchars((string) $total) ?> €</h2>
4+
<h2 class="total">Total: <?= htmlspecialchars((string) $total) ?> €</h2>
55

66
<?php $products = $cart['products'] ?? []; ?>
7-
<!-- <?php $menus = $cart['menus'] ?? []; ?> -->
7+
<?php $menus = $cart['menus'] ?? []; ?>
88

99
<?php if (empty($products) && empty($menus)) { ?>
1010
<p>Your cart is empty.</p>
1111
<?php } else { ?>
12-
<ul>
13-
<!-- Display Products -->
12+
<ul class="cart-list">
1413
<?php foreach ($products as $lineKey => $item): ?>
15-
<li>
16-
<strong><?= htmlspecialchars($item['name'] ?? '') ?></strong>
17-
x <?= (int) ($item['quantity'] ?? 0) ?>,
18-
<?= htmlspecialchars((string) ($item['price'] ?? 0)) ?>
19-
<br>
14+
<li class="cart-item">
15+
<span class="cart-item-name"><?= htmlspecialchars($item['name'] ?? '') ?></span>
16+
<span class="cart-item-info">x <?= (int)($item['quantity'] ?? 0) ?><?= htmlspecialchars((string)($item['price'] ?? 0)) ?> €</span>
2017

2118
<?php if (!empty($item['options']) && is_array($item['options'])): ?>
2219
<?php foreach ($item['options'] as $slot): ?>
23-
<div>
24-
<?= htmlspecialchars($slot['categoryName'] ?? '') ?>:
25-
<ul>
26-
<?php foreach ($slot['choices'] ?? [] as $choice): ?>
27-
<li>
28-
<?= htmlspecialchars($choice['name'] ?? '') ?>
29-
<?php if (isset($choice['priceDelta']) && (float) $choice['priceDelta'] !== 0.0): ?>
30-
(<?= htmlspecialchars((string) $choice['priceDelta']) ?> €)
31-
<?php endif; ?>
32-
</li>
33-
<?php endforeach; ?>
34-
</ul>
35-
</div>
20+
<div class="slot-label"><?= htmlspecialchars($slot['categoryName'] ?? '') ?>:</div>
21+
<ul class="slot-choices">
22+
<?php foreach ($slot['choices'] ?? [] as $choice): ?>
23+
<li>
24+
<?= htmlspecialchars($choice['name'] ?? '') ?>
25+
<?php if (isset($choice['priceDelta']) && (float)$choice['priceDelta'] !== 0.0): ?>
26+
(+<?= htmlspecialchars((string)$choice['priceDelta']) ?> €)
27+
<?php endif; ?>
28+
</li>
29+
<?php endforeach; ?>
30+
</ul>
3631
<?php endforeach; ?>
3732
<?php endif; ?>
3833

39-
<form method="POST" action="/cart">
40-
<input type="hidden" name="product_id" value="<?= (int) ($item['product_id'] ?? 0) ?>">
34+
<form method="POST" action="/cart" class="cart-form">
35+
<input type="hidden" name="product_id" value="<?= (int)($item['product_id'] ?? 0) ?>">
4136
<input type="hidden" name="product_name" value="<?= htmlspecialchars($item['name'] ?? '', ENT_QUOTES) ?>">
42-
<input type="hidden" name="product_price" value="<?= htmlspecialchars((string) ($item['price'] ?? 0), ENT_QUOTES) ?>">
37+
<input type="hidden" name="product_price" value="<?= htmlspecialchars((string)($item['price'] ?? 0), ENT_QUOTES) ?>">
4338
<input type="hidden" name="customization" value="<?= htmlspecialchars(json_encode($item['options'] ?? []), ENT_QUOTES) ?>">
44-
<input type="hidden" name="line_key" value="<?= htmlspecialchars((string) ($item['line_key'] ?? $lineKey), ENT_QUOTES) ?>">
39+
<input type="hidden" name="line_key" value="<?= htmlspecialchars((string)($item['line_key'] ?? $lineKey), ENT_QUOTES) ?>">
4540
<input type="hidden" name="is_from_cart" value="True">
46-
47-
<button type="submit" name="action" value="add">Add one</button>
48-
<button type="submit" name="action" value="remove">Remove one</button>
41+
<button type="submit" name="action" value="add" class="btn btn-pourpre">+ Add one</button>
42+
<button type="submit" name="action" value="remove" class="btn btn-pourpre">− Remove one</button>
4943
</form>
5044
</li>
5145
<?php endforeach; ?>
5246

5347
<a href="/checkout">Checkout</a>
5448
<!-- TODO: Display Menus -->
49+
</ul>
5550
<?php } ?>
5651

5752
<?php include 'partials/footer.php'; ?>

src/app/views/product.php

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,68 @@
11
<?php include 'partials/header.php'; ?>
22

33
<main>
4-
<h1><?= htmlspecialchars($product->name) ?></h1>
5-
<p>Prix: <?= htmlspecialchars($product->price) ?> €</p>
6-
<p>Description: <?= htmlspecialchars($product->description) ?></p>
7-
<p>Catégorie(s):
8-
<?php if (!empty($product->category_name)) { ?>
9-
<?php if (is_array($product->category_name)) { ?>
10-
<?= htmlspecialchars(implode(', ', $product->category_name)) ?>
11-
<?php } else { ?>
12-
<?= htmlspecialchars($product->category_name) ?>
13-
<?php } ?>
14-
<?php } else { ?>
15-
Aucune catégorie trouvée
16-
<?php } ?>
17-
</p>
4+
<div class="product-page">
5+
<h1><?= htmlspecialchars($product->name) ?></h1>
186

19-
<?php if ($product->supplier_name && $product->supplier_phone && $product->supplier_email) { ?>
20-
<p>Fournisseur: <?= htmlspecialchars($product->supplier_name) ?>
21-
- <?= htmlspecialchars($product->supplier_email) ?>
22-
- <?= htmlspecialchars($product->supplier_phone) ?>
23-
</p>
24-
<?php } ?>
7+
<div class="product-info">
8+
<span class="label">Prix</span> <span><?= htmlspecialchars($product->price) ?> €</span>
9+
<span class="label">Description</span><span><?= htmlspecialchars($product->description) ?></span>
10+
<span class="label">Catégorie(s)</span><span>
11+
<?php if (!empty($product->category_name)): ?>
12+
<?= htmlspecialchars(is_array($product->category_name) ? implode(', ', $product->category_name) : $product->category_name) ?>
13+
<?php else: ?>
14+
Aucune catégorie trouvée
15+
<?php endif; ?>
16+
</span>
17+
<?php if ($product->supplier_name && $product->supplier_phone && $product->supplier_email): ?>
18+
<span class="label">Fournisseur</span>
19+
<span>
20+
<?= htmlspecialchars($product->supplier_name) ?>
21+
<?= htmlspecialchars($product->supplier_email) ?>
22+
<?= htmlspecialchars($product->supplier_phone) ?>
23+
</span>
24+
<?php endif; ?>
25+
</div>
2526

26-
<?php if ($inCartQuantity > 0) { ?>
27-
<p style="color: green; font-weight: bold;">
28-
This product is already in your cart. (<?= (int) $inCartQuantity ?> total in cart)
29-
</p>
30-
<?php } ?>
27+
<?php if ($inCartQuantity > 0): ?>
28+
<p class="in-cart-notice">Already in your cart (<?= (int)$inCartQuantity ?> total)</p>
29+
<?php endif; ?>
3130

32-
<form method="POST" action="/cart">
33-
<input type="hidden" name="product_id" value="<?= (int) $product->id ?>">
34-
<input type="hidden" name="product_name" value="<?= htmlspecialchars($product->name, ENT_QUOTES) ?>">
35-
<input type="hidden" name="product_price" value="<?= htmlspecialchars($product->price, ENT_QUOTES) ?>">
36-
<input type="hidden" name="is_from_cart" value="False">
31+
<form method="POST" action="/cart">
32+
<input type="hidden" name="product_id" value="<?= (int)$product->id ?>">
33+
<input type="hidden" name="product_name" value="<?= htmlspecialchars($product->name, ENT_QUOTES) ?>">
34+
<input type="hidden" name="product_price" value="<?= htmlspecialchars($product->price, ENT_QUOTES) ?>">
35+
<input type="hidden" name="is_from_cart" value="False">
3736

38-
<?php if ($userId) { ?>
39-
<?php if (!empty($slots)) { ?>
40-
<h3>Personnalisez votre produit</h3>
41-
42-
<?php foreach ($slots as $slot): ?>
43-
<fieldset style="margin-bottom: 1rem; padding: 1rem; border: 1px solid #ddd; border-radius: 8px;">
44-
<legend>
45-
<?= htmlspecialchars($slot->category_name) ?>
46-
(<?= (int) $slot->min_select ?> à <?= (int) $slot->max_select ?>)
47-
</legend>
48-
49-
<?php for ($row = 0; $row < (int) $slot->max_select; $row++): ?>
50-
<div style="margin-bottom: 0.75rem;">
51-
<select name="customization[<?= (int) $slot->id ?>][]" <?= $row < (int) $slot->min_select ? 'required' : '' ?>>
37+
<?php if ($userId): ?>
38+
<?php if (!empty($slots)): ?>
39+
<h3>Personnalisez votre produit</h3>
40+
<?php foreach ($slots as $slot): ?>
41+
<fieldset class="slot">
42+
<legend>
43+
<?= htmlspecialchars($slot->category_name) ?>
44+
(<?= (int)$slot->min_select ?> à <?= (int)$slot->max_select ?>)
45+
</legend>
46+
<?php for ($row = 0; $row < (int)$slot->max_select; $row++): ?>
47+
<select name="customization[<?= (int)$slot->id ?>][]" <?= $row < (int)$slot->min_select ? 'required' : '' ?>>
5248
<option value="">-- Select an option --</option>
5349
<?php foreach ($slot->options as $option): ?>
54-
<option value="<?= (int) $option->option_product_id ?>" <?= $row === 0 && !empty($option->is_default) ? 'selected' : '' ?>>
50+
<option value="<?= (int)$option->option_product_id ?>" <?= $row === 0 && !empty($option->is_default) ? 'selected' : '' ?>>
5551
<?= htmlspecialchars($option->option_product_name) ?>
56-
<?= ((float) $option->price_delta !== 0.0) ? ' (' . htmlspecialchars((string) $option->price_delta) . ' €)' : ' (free)' ?>
52+
<?= ((float)$option->price_delta !== 0.0) ? ' (' . htmlspecialchars((string)$option->price_delta) . ' €)' : ' (free)' ?>
5753
</option>
5854
<?php endforeach; ?>
5955
</select>
60-
</div>
61-
<?php endfor; ?>
62-
</fieldset>
63-
<?php endforeach; ?>
64-
<?php } ?>
65-
66-
<button type="submit" name="action" value="add">Add to Cart</button>
67-
<?php } else { ?>
68-
<p style="color: red; font-weight: bold;">Please sign in to add this product to your cart.</p>
69-
<?php } ?>
70-
</form>
56+
<?php endfor; ?>
57+
</fieldset>
58+
<?php endforeach; ?>
59+
<?php endif; ?>
60+
<button type="submit" name="action" value="add" class="btn btn-pourpre">Add to Cart</button>
61+
<?php else: ?>
62+
<p>Please sign in to add this product to your cart.</p>
63+
<?php endif; ?>
64+
</form>
65+
</div>
7166
</main>
7267

7368
<?php include 'partials/footer.php'; ?>

src/public/assets/css/style.css

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,134 @@ h1 {
8282
.menu-card h3 {
8383
margin-top: 0;
8484
color: #333;
85-
}
85+
}
86+
87+
.cart-list {
88+
list-style: none;
89+
padding: 0;
90+
margin: 0;
91+
display: flex;
92+
flex-direction: column;
93+
gap: 10px;
94+
}
95+
96+
.cart-item {
97+
border: 2px solid #ddd;
98+
border-radius: 10px;
99+
margin-left: 10px;
100+
padding: 1rem;
101+
}
102+
103+
.cart-item-name {
104+
font-size: 19px;
105+
font-weight: 500;
106+
margin: 0 0 4px;
107+
}
108+
109+
.cart-item-info {
110+
font-size: 14px;
111+
color: slategray;
112+
margin: 0 0 10px;
113+
}
114+
115+
.cart-form {
116+
display:flex;
117+
gap:8px;
118+
margin-top:10px;
119+
}
120+
121+
.slot-label {
122+
font-size: 15px;
123+
color: slategray;
124+
margin: 6px 0 2px;
125+
}
126+
127+
.slot-choices {
128+
list-style: none;
129+
padding: 0;
130+
margin: 0 0 10px;
131+
display: flex;
132+
gap: 6px;
133+
flex-wrap: wrap;
134+
}
135+
136+
.slot-choices li {
137+
font-size: 13px;
138+
padding: 2px 10px;
139+
border: 1px solid #ddd;
140+
border-radius: 99px;
141+
}
142+
143+
.btn {
144+
font-size: 13px;
145+
padding: 5px 12px;
146+
border-radius: 8px;
147+
border: 1px solid #ccc;
148+
background: transparent;
149+
cursor: pointer;
150+
}
151+
152+
.btn:hover {
153+
transform: scale(1.05);
154+
}
155+
156+
.total {
157+
font-weight: 500;
158+
font-size: 20px;
159+
margin-left: 10px;
160+
margin-top: 30px;
161+
}
162+
163+
.product-page {
164+
max-width: 600px;
165+
margin: 2rem auto;
166+
padding: 0 1rem;
167+
}
168+
169+
.product-info {
170+
display: grid;
171+
grid-template-columns: auto 1fr;
172+
gap: 6px 16px;
173+
margin-bottom: 1.5rem;
174+
}
175+
176+
.product-info .label {
177+
color: gray;
178+
font-size: 14px;
179+
}
180+
181+
.in-cart-notice {
182+
font-size: 14px;
183+
color: green;
184+
font-weight: 500;
185+
margin-bottom: 1rem;
186+
}
187+
188+
.slot { border: 0.5px solid #ddd;
189+
border-radius: 10px;
190+
padding: 1rem;
191+
margin-bottom: 10px;
192+
}
193+
194+
.slot legend {
195+
font-weight: 500;
196+
font-size: 14px;
197+
padding: 0 6px;
198+
}
199+
.slot select {
200+
width: 100%;
201+
padding: 6px 8px;
202+
border: 1px solid #ddd;
203+
border-radius: 8px;
204+
font-size: 14px;
205+
margin-bottom: 8px;
206+
}
207+
208+
.btn {
209+
font-size: 13px;
210+
padding: 5px 12px;
211+
border-radius: 8px;
212+
border: 1px solid #ccc;
213+
background: transparent;
214+
cursor: pointer;
215+
}

0 commit comments

Comments
 (0)