Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/routes/category/components/price-filter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Form } from "react-router";

import { Button, Input } from "@/components/ui";
import { Button, Container, Input } from "@/components/ui";
import { cn } from "@/lib/utils";
import { useState } from "react";

interface PriceFilterProps {
minPrice: string;
Expand Down
36 changes: 35 additions & 1 deletion src/routes/category/components/product-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,37 @@ export function ProductCard({
"10*10": "10*10",
};

// Obtener el precio base para stickers para la variante 3*3
const getBasePrice = () => {
if (categorySlug === "stickers" && product.stickersVariants?.length) {
const baseVariant = product.stickersVariants.find(
(variant) => variant.measure === "3*3"
);
return baseVariant ? baseVariant.price : product.price;
}
return product.price;
};

// Obtener rango de precios para las variantes filtradas
const getPriceRange = () => {
if (categorySlug === "stickers" && product.stickersVariants?.length && variants.length > 0) {
const filteredVariants = product.stickersVariants.filter(variant =>
variants.includes(variant.measure)
);

if (filteredVariants.length > 0) {
const minPrice = Math.min(...filteredVariants.map(v => v.price));
const maxPrice = Math.max(...filteredVariants.map(v => v.price));

if (minPrice === maxPrice) {
return `S/${minPrice}`;
}
return `S/${minPrice} - S/${maxPrice}`;
}
}
return null;
};

if (categorySlug === "polos") {
variantTitle = "Elige la talla";
variants = ["Small", "Medium", "Large"];
Expand All @@ -49,6 +80,9 @@ export function ProductCard({
variantParamName = "measure";
}

const basePrice = getBasePrice();
const priceRange = getPriceRange();

const handleVariantClick = (
e: React.MouseEvent<HTMLButtonElement>,
variant: string
Expand Down Expand Up @@ -115,7 +149,7 @@ export function ProductCard({
<h2 className="text-sm font-medium">{product.title}</h2>
<p className="text-sm text-muted-foreground">{product.description}</p>
<p className="mt-auto text-base font-medium">
S/{hoveredPrice !== null ? hoveredPrice : product.price}
{hoveredPrice !== null ? `S/${hoveredPrice}` : (priceRange ? priceRange : `S/${basePrice}`)}
</p>
</div>
{product.isOnSale && (
Expand Down