fix: product detail view for parapharmacy products
- Updated ProductView to use correct endpoint for parapharmacy - Updated getProduct service to handle parapharmacy products - Shows price, category, brand, source for parapharmacy products - Updated labels from 'OFF' to 'Parafarmacia'
This commit is contained in:
@@ -17,13 +17,18 @@ export default function ProductView({ source, id, onBack }) {
|
||||
setError(null);
|
||||
setPharmacies([]);
|
||||
try {
|
||||
const response = await fetch(`/api/products/${source}/${id}`);
|
||||
// Use different endpoint for parapharmacy products
|
||||
const apiUrl = source === 'parapharmacy'
|
||||
? `/api/products/parapharmacy/${id}`
|
||||
: `/api/products/${source}/${id}`;
|
||||
|
||||
const response = await fetch(apiUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error('Producto no encontrado');
|
||||
}
|
||||
const data = await response.json();
|
||||
setProduct(data);
|
||||
loadPharmacies(source, data.id);
|
||||
loadPharmacies(source, data.id || data._id);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
@@ -71,8 +76,9 @@ export default function ProductView({ source, id, onBack }) {
|
||||
if (!product) return null;
|
||||
|
||||
const isCima = product.source === 'cima';
|
||||
const isParapharmacy = product.source !== 'cima';
|
||||
const sourceColor = isCima ? '#2563eb' : '#16a34a';
|
||||
const sourceLabel = isCima ? 'CIMA' : 'Open Food Facts';
|
||||
const sourceLabel = isCima ? 'CIMA' : 'Parafarmacia';
|
||||
|
||||
return (
|
||||
<div className="product-view">
|
||||
@@ -116,17 +122,20 @@ export default function ProductView({ source, id, onBack }) {
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{product.nutriscore && product.nutriscore !== 'not-applicable' && product.nutriscore !== 'unknown' && (
|
||||
<DetailRow label="Nutri-Score" value={product.nutriscore.toUpperCase()} />
|
||||
{product.price && (
|
||||
<DetailRow label="Precio" value={`${product.price} €`} />
|
||||
)}
|
||||
{product.nova_group && (
|
||||
<DetailRow label="NOVA" value={`Grupo ${product.nova_group}`} />
|
||||
{product.original_price && product.original_price > product.price && (
|
||||
<DetailRow label="Precio anterior" value={`${product.original_price} €`} />
|
||||
)}
|
||||
{product.eco_score && product.eco_score !== 'unknown' && (
|
||||
<DetailRow label="Eco-Score" value={product.eco_score.toUpperCase()} />
|
||||
{product.category && (
|
||||
<DetailRow label="Categoría" value={product.category} />
|
||||
)}
|
||||
{product.ingredients && (
|
||||
<DetailRow label="Ingredientes" value={product.ingredients} />
|
||||
{product.brand && (
|
||||
<DetailRow label="Marca" value={product.brand} />
|
||||
)}
|
||||
{product.source_url && (
|
||||
<DetailRow label="Fuente" value={product.source} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user