Skip to content

Commit 59d6a55

Browse files
author
Kellyarias02
committed
Fix: Display the dynamic prices on the sticker category
1 parent 2af8106 commit 59d6a55

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/routes/category/components/price-filter/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Form } from "react-router";
22

3-
import { Button, Input } from "@/components/ui";
3+
import { Button, Container, Input } from "@/components/ui";
44
import { cn } from "@/lib/utils";
5+
import { useState } from "react";
56

67
interface PriceFilterProps {
78
minPrice: string;

src/routes/category/components/product-card/index.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,37 @@ export function ProductCard({
2929
"10*10": "10*10",
3030
};
3131

32+
// Obtener el precio base para stickers para la variante 3*3
33+
const getBasePrice = () => {
34+
if (categorySlug === "stickers" && product.stickersVariants?.length) {
35+
const baseVariant = product.stickersVariants.find(
36+
(variant) => variant.measure === "3*3"
37+
);
38+
return baseVariant ? baseVariant.price : product.price;
39+
}
40+
return product.price;
41+
};
42+
43+
// Obtener rango de precios para las variantes filtradas
44+
const getPriceRange = () => {
45+
if (categorySlug === "stickers" && product.stickersVariants?.length && variants.length > 0) {
46+
const filteredVariants = product.stickersVariants.filter(variant =>
47+
variants.includes(variant.measure)
48+
);
49+
50+
if (filteredVariants.length > 0) {
51+
const minPrice = Math.min(...filteredVariants.map(v => v.price));
52+
const maxPrice = Math.max(...filteredVariants.map(v => v.price));
53+
54+
if (minPrice === maxPrice) {
55+
return `S/${minPrice}`;
56+
}
57+
return `S/${minPrice} - S/${maxPrice}`;
58+
}
59+
}
60+
return null;
61+
};
62+
3263
if (categorySlug === "polos") {
3364
variantTitle = "Elige la talla";
3465
variants = ["Small", "Medium", "Large"];
@@ -49,6 +80,9 @@ export function ProductCard({
4980
variantParamName = "measure";
5081
}
5182

83+
const basePrice = getBasePrice();
84+
const priceRange = getPriceRange();
85+
5286
const handleVariantClick = (
5387
e: React.MouseEvent<HTMLButtonElement>,
5488
variant: string
@@ -115,7 +149,7 @@ export function ProductCard({
115149
<h2 className="text-sm font-medium">{product.title}</h2>
116150
<p className="text-sm text-muted-foreground">{product.description}</p>
117151
<p className="mt-auto text-base font-medium">
118-
S/{hoveredPrice !== null ? hoveredPrice : product.price}
152+
{hoveredPrice !== null ? `S/${hoveredPrice}` : (priceRange ? priceRange : `S/${basePrice}`)}
119153
</p>
120154
</div>
121155
{product.isOnSale && (

0 commit comments

Comments
 (0)