Skip to content

Commit 4924548

Browse files
committed
fix: ensure variant image and attributes render with defensive field mapping and fallbacks
1 parent 718dadd commit 4924548

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

frontend/src/hooks/product_variants.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ export const useFetchVariants = (productId) => {
2020
unit_name: v.unitName,
2121
unit_value: v.unitValue,
2222
sku: v.sku,
23-
barcode: v.barcode,
23+
barcode: v.barcode || v.pluCode || '',
2424
plu_code: v.pluCode,
25-
sell_price: v.sellPrice,
26-
cost_price: v.costPrice,
27-
stock_quantity: v.stockQuantity,
28-
image_url: v.imageUrl,
29-
is_active: v.isActive,
30-
created_at: v.createdAt,
31-
attributes: v.attributes,
32-
unit_conversions: v.unitConversions || []
25+
sell_price: v.sellPrice || 0,
26+
cost_price: v.costPrice || 0,
27+
stock_quantity: v.stockQuantity || 0,
28+
image_url: v.imageUrl || v.image_url || null,
29+
is_active: v.isActive !== false,
30+
created_at: v.createdAt || v.created_at,
31+
attributes: v.attributes || {},
32+
unit_conversions: v.unitConversions || v.unit_conversions || []
3333
}));
3434
setVariants(mappedVariants);
3535
setError(null);

frontend/src/pages/Products/ProductManager/ProductDetail.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ function ProductDetail() {
546546
<TableCell className="font-semibold text-gray-400 text-center text-xs">{index + 1}</TableCell>
547547
<TableCell className="text-center">
548548
<div className="w-9 h-9 mx-auto bg-white border border-gray-200 rounded-lg flex items-center justify-center overflow-hidden">
549-
{(variant.image_url || variant.imageUrl) ? (
549+
{variant.image_url ? (
550550
<img
551-
src={variant.image_url || variant.imageUrl}
551+
src={variant.image_url}
552552
alt={variant.name}
553553
className="w-full h-full object-cover"
554554
/>

0 commit comments

Comments
 (0)