mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-06-30 17:50:32 -05:00
Add product count column to product types admin page
Shows how many active products are linked to each type, linked to the filtered products list. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+14
-2
@@ -38,7 +38,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
}
|
||||
|
||||
$types = db()->fetchAll("SELECT * FROM product_types ORDER BY name ASC");
|
||||
$types = db()->fetchAll(
|
||||
"SELECT pt.*, COUNT(p.product_id) AS product_count
|
||||
FROM product_types pt
|
||||
LEFT JOIN products p ON p.product_type_id = pt.type_id AND p.is_active = 1
|
||||
GROUP BY pt.type_id
|
||||
ORDER BY pt.name ASC"
|
||||
);
|
||||
?>
|
||||
|
||||
<div class="page-header">
|
||||
@@ -63,19 +69,25 @@ $types = db()->fetchAll("SELECT * FROM product_types ORDER BY name ASC");
|
||||
<th>Name</th>
|
||||
<th>Slug</th>
|
||||
<th>Description</th>
|
||||
<th>Products</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($types)): ?>
|
||||
<tr><td colspan="5" class="text-muted" style="text-align:center;padding:2rem">No product types yet. Create one above.</td></tr>
|
||||
<tr><td colspan="6" class="text-muted" style="text-align:center;padding:2rem">No product types yet. Create one above.</td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($types as $t): ?>
|
||||
<tr>
|
||||
<td><strong><?= htmlspecialchars($t['name']) ?></strong></td>
|
||||
<td class="text-muted"><?= htmlspecialchars($t['slug']) ?></td>
|
||||
<td class="text-muted"><?= htmlspecialchars(substr($t['description'] ?? '', 0, 60)) ?></td>
|
||||
<td>
|
||||
<a href="/admin/products.php?type=<?= urlencode($t['type_id']) ?>" style="font-weight: 600;">
|
||||
<?= (int)$t['product_count'] ?>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($t['is_active']): ?>
|
||||
<span class="badge badge-success">Active</span>
|
||||
|
||||
Reference in New Issue
Block a user