diff --git a/frontend/application/components/ArchivePage.tsx b/frontend/application/components/ArchivePage.tsx
index aeab7871..bcbe0924 100644
--- a/frontend/application/components/ArchivePage.tsx
+++ b/frontend/application/components/ArchivePage.tsx
@@ -1,6 +1,6 @@
"use client";
import React, { useState, useMemo, useEffect, useCallback } from "react";
-import { toPersian } from "../lib/utils";
+import { toPersian, isProductOutOfStock } from "../lib/utils";
import { Product, PetType } from "../lib/data/products";
import { usePetStore } from "../lib/store/usePetStore";
import { productService } from "../lib/services/productService";
@@ -205,7 +205,7 @@ export const ArchiveProductCard: React.FC<{ product: Product }> = ({ product })
- {(product.packageSize !== undefined && product.packageSize !== null ? Number(product.packageSize) : 100) <= 0 ? (
+ {isProductOutOfStock(product) ? (
ناموجود
@@ -294,7 +294,7 @@ const ArchiveProductListItem: React.FC<{ product: Product }> = ({ product }) =>
return null;
}, [product, activePet]);
- const isOutOfStock = (product.packageSize !== undefined && product.packageSize !== null ? Number(product.packageSize) : 100) <= 0;
+ const isOutOfStock = isProductOutOfStock(product);
const { showPrices, allowCart, showPreorderBtn } = useCatalogMode();
return (
diff --git a/frontend/application/components/FeaturedProducts.tsx b/frontend/application/components/FeaturedProducts.tsx
index ee9b7418..e3ab0e28 100644
--- a/frontend/application/components/FeaturedProducts.tsx
+++ b/frontend/application/components/FeaturedProducts.tsx
@@ -14,6 +14,7 @@ import { useCartStore } from "../lib/store/cartStore";
import { toast } from "sonner";
import { useCatalogMode } from "../lib/useCatalogMode";
+import { isProductOutOfStock } from "../lib/utils";
import { isSuitableForDog, isSuitableForCat, isSuitableForBoth, isSpeciesCompatible, matchesMedicalSymptom } from "../lib/petCompatibility";
export function ProductCard({ product, priority = false }: { product: Product; priority?: boolean }) {
@@ -116,7 +117,7 @@ export function ProductCard({ product, priority = false }: { product: Product; p
>
- {allowCart && (product.packageSize !== undefined && product.packageSize !== null ? Number(product.packageSize) : 100) > 0 && (
+ {allowCart && !isProductOutOfStock(product) && (
{
e.stopPropagation();
diff --git a/frontend/application/components/ProductPage.tsx b/frontend/application/components/ProductPage.tsx
index 30206997..c6f27db1 100644
--- a/frontend/application/components/ProductPage.tsx
+++ b/frontend/application/components/ProductPage.tsx
@@ -47,7 +47,7 @@ const ICON_MAP: Record
> = {
Zap,
Star
};
-import { toPersian } from "../lib/utils";
+import { toPersian, isProductOutOfStock } from "../lib/utils";
import { Product } from "../lib/data/products";
import { productService } from "../lib/services/productService";
import { SCIENTIFIC_TERMS } from "../lib/data/scientificTerms";
@@ -402,7 +402,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
);
if (!product || !fullProduct || !calculation) return محصول یافت نشد
;
- const isOutOfStock = (product.packageSize !== undefined && product.packageSize !== null ? Number(product.packageSize) : 100) <= 0;
+ const isOutOfStock = isProductOutOfStock(fullProduct || product);
return (
@@ -1420,7 +1420,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
{((product as unknown as { preorderDeposit?: number }).preorderDeposit || 0) > 0 ? `پیشخرید (بیعانه: ${((product as unknown as { preorderDeposit?: number }).preorderDeposit || 0).toLocaleString('fa-IR')} تومان)` : 'ثبت پیشخرید (رایگان)'}
- ) : (product.packageSize || 0) <= 0 ? (
+ ) : isOutOfStock ? (