removed getTotalVariantStock and isVariantStock, removed MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE contants
Browse files- lib/db/product-queries.ts +1 -2
- lib/variant-utils.ts +0 -28
lib/db/product-queries.ts
CHANGED
|
@@ -200,5 +200,4 @@ export async function updateVariantStock(
|
|
| 200 |
}
|
| 201 |
}
|
| 202 |
|
| 203 |
-
|
| 204 |
-
export { MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE };
|
|
|
|
| 200 |
}
|
| 201 |
}
|
| 202 |
|
| 203 |
+
|
|
|
lib/variant-utils.ts
CHANGED
|
@@ -218,34 +218,6 @@ export function hasVariants(product: { variants?: any }): boolean {
|
|
| 218 |
return false;
|
| 219 |
}
|
| 220 |
|
| 221 |
-
/**
|
| 222 |
-
* Get total stock across all variants
|
| 223 |
-
*/
|
| 224 |
-
export function getTotalVariantStock(product: {
|
| 225 |
-
variantStock?: any;
|
| 226 |
-
stock: number;
|
| 227 |
-
}): number {
|
| 228 |
-
if (!product.variantStock || typeof product.variantStock !== "object") {
|
| 229 |
-
return product.stock;
|
| 230 |
-
}
|
| 231 |
-
|
| 232 |
-
const stocks = Object.values(product.variantStock) as unknown[];
|
| 233 |
-
|
| 234 |
-
return stocks.reduce<number>(
|
| 235 |
-
(sum, stock) => sum + (typeof stock === "number" ? stock : 0),
|
| 236 |
-
0,
|
| 237 |
-
);
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
/**
|
| 241 |
-
* Check if a specific variant is in stock
|
| 242 |
-
*/
|
| 243 |
-
export function isVariantInStock(
|
| 244 |
-
product: { stock: number; variantStock?: any; variants?: any },
|
| 245 |
-
variantKey?: string,
|
| 246 |
-
): boolean {
|
| 247 |
-
return getVariantStock(product, variantKey) > 0;
|
| 248 |
-
}
|
| 249 |
|
| 250 |
/**
|
| 251 |
* Get stock status for a variant
|
|
|
|
| 218 |
return false;
|
| 219 |
}
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
/**
|
| 223 |
* Get stock status for a variant
|