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

Commit c19674d

Browse files
Merge pull request #75 from TheRefraction/feature-image-product
Feature image product
2 parents c5e010f + 019fe1f commit c19674d

16 files changed

Lines changed: 18 additions & 2 deletions

src/app/models/Product.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public function getProductById($id) {
8484
pc.name AS category_name,
8585
s.name AS supplier_name,
8686
s.email AS supplier_email,
87-
s.phone AS supplier_phone
87+
s.phone AS supplier_phone,
88+
pc.name AS category_name
8889
FROM product p
8990
LEFT JOIN supplier s ON p.supplier_id = s.id
9091
LEFT JOIN product_to_category ptc ON p.id = ptc.product_id

src/app/views/partials/product-list.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
<?php foreach ($products as $product) { ?>
2-
<?php $imagePath = !empty($product->image) ? $product->image : '/assets/images/test.jpg'; ?>
2+
<?php
3+
$name = $product->name;
4+
5+
$clearName = str_replace(['é', 'è'], ['e', 'e'], $name);
6+
7+
$clearName = strtolower($clearName);
8+
9+
$clearName = preg_replace('/[^a-z0-9]+/', '-', $clearName);
10+
11+
$clearName = trim($clearName, '-');
12+
13+
$imagePath = "/assets/images/" . $clearName . ".png";
14+
?>
15+
16+
317
<article class="product-item">
418
<a href="/product?id=<?= htmlspecialchars($product->id); ?>">
519
<img
620
src="<?= htmlspecialchars($imagePath); ?>"
721
alt="<?= htmlspecialchars($product->name); ?>"
22+
onerror="this.onerror=null; this.src='/assets/images/test.jpg';"
823
/>
924

1025
<div class="product-info">
20.4 KB
Loading

src/public/assets/images/biere.png

7.81 KB
Loading
12.6 KB
Loading

src/public/assets/images/cafe.png

15.1 KB
Loading
15 KB
Loading
17 KB
Loading
21.1 KB
Loading
8.7 KB
Loading

0 commit comments

Comments
 (0)