Files
devops 075f00a4ed
Deploy Canina / deploy (push) Failing after 2m7s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 10s
fix(storefront): accurately reflect out-of-stock products based on stock quantity and stockStatus
2026-10-14 15:10:59 +00:00

28 lines
1.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export const toPersian = (n: number | string | undefined | null) => {
if (n === undefined || n === null) return "";
return n.toString().replace(/\d/g, d => '۰۱۲۳۴۵۶۷۸۹'[parseInt(d)]);
};
export const toEnglishDigits = (str: string) => {
if (!str) return "";
return str.replace(/[۰-۹]/g, d => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d).toString());
};
export function cn(...classes: (string | boolean | undefined)[]) {
return classes.filter(Boolean).join(" ");
}
export function isProductOutOfStock(product?: {
stock?: number;
stockStatus?: "IN_STOCK" | "OUT_OF_STOCK" | "PRE_ORDER" | "DISCONTINUED" | string;
packageSize?: number | string;
} | null): boolean {
if (!product) return false;
if (product.stockStatus === "OUT_OF_STOCK" || product.stockStatus === "DISCONTINUED") return true;
if (typeof product.stock === "number" && product.stock <= 0) return true;
if (product.stock !== undefined && product.stock !== null && Number(product.stock) <= 0) return true;
if (product.packageSize !== undefined && product.packageSize !== null && Number(product.packageSize) <= 0) return true;
return false;
}