Fix cart page error when reading designJson

Handle designJson as either string or object, parse if needed.
Prevents TypeError when accessing front/back properties.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Andymick
2026-07-18 19:29:45 +01:00
co-authored by Claude Haiku 4.5
parent 548046d4bf
commit f72e934943
+8 -1
View File
@@ -12,7 +12,14 @@ export default function CartPage() {
const removeItem = useCart((s) => s.removeItem); const removeItem = useCart((s) => s.removeItem);
const setQuantity = useCart((s) => s.setQuantity); const setQuantity = useCart((s) => s.setQuantity);
const total = useCart((s) => s.total()); const total = useCart((s) => s.total());
const hasCustomDesign = items.some((item) => item.designJson.front.length > 0 || item.designJson.back.length > 0); const hasCustomDesign = items.some((item) => {
try {
const design = typeof item.designJson === 'string' ? JSON.parse(item.designJson) : item.designJson;
return (design.front?.length ?? 0) > 0 || (design.back?.length ?? 0) > 0;
} catch {
return false;
}
});
useEffect(() => setMounted(true), []); useEffect(() => setMounted(true), []);