From e20f3e1ddf23aeb6626d84355f4ebb818b530756 Mon Sep 17 00:00:00 2001 From: Cristian Felipe Cruz Buitron Date: Tue, 25 Aug 2026 14:29:50 -0500 Subject: [PATCH] feat(ecommerce): selector de variante inline en tarjeta de producto Reutiliza Product.variants[].{name,value,available}, ya expuesto por el provider de Medusa (variant.options[0]), para swatches clicables en la tarjeta del catalogo/home -- no solo en la ficha de producto. Solo se muestra cuando el producto tiene mas de una variante; la variante seleccionada se usa al agregar al carrito. ADR 0005 seccion 3 (patron eBay), cero cambio de modelo de datos. --- .../components/product/product-card.tsx | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/workloads/ecommerce/components/product/product-card.tsx b/workloads/ecommerce/components/product/product-card.tsx index dce0e7a..d7de6d4 100644 --- a/workloads/ecommerce/components/product/product-card.tsx +++ b/workloads/ecommerce/components/product/product-card.tsx @@ -3,6 +3,7 @@ import Image from "next/image"; import Link from "next/link"; import { Heart, ShoppingBag, Sparkles } from "lucide-react"; +import { useState } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import type { Product } from "@/lib/headless/types"; @@ -21,6 +22,8 @@ export function ProductCard({ product, priority = false }: { product: Product; p ? Math.round((1 - product.price / product.compareAtPrice) * 100) : null; + const [selectedVariantId, setSelectedVariantId] = useState(product.variants[0]?.id); + return (
@@ -32,12 +35,33 @@ export function ProductCard({ product, priority = false }: { product: Product; p
{product.category}{product.collection}

{product.name}

{product.shortDescription}

+ {product.variants.length > 1 && ( +
+ {product.variants.map((variant) => ( + + ))} +
+ )}
{product.compareAtPrice && {formatMoney(product.compareAtPrice, product.currency)}} {formatMoney(product.price, product.currency)}
- +