| 123456789101112131415161718192021222324252627282930 |
- // Cause I want to have a properly standardize product data cause I hate those "nodes" thinggy
- // and to prevent render error in case some data doesn't exist, I want a default value
-
- export const formatProductData = (product) => {
-
- if(!product) return
-
- let publishedDate = product?.metafields[0]?.value
- let selected = product?.metafields[1]?.value
-
- return {
- id: product?.id || null,
- handle: product?.handle || "",
- title: product?.title || "",
- createdAt: publishedDate || product?.createdAt,
- collections: product?.collections?.nodes || null,
- descriptionHtml: product?.descriptionHtml || "",
- tags:product?.tags || null,
- images: product?.images?.nodes || null,
- selected: (selected === "true") || false, // cause I want to have a true false value, somehow BE return text value "true", thus == used to convert it to proper boolean value
- minVariantPrice: product?.priceRange?.minVariantPrice || {amount:0 , currencyCode:''},
- maxVariantPrice: product?.priceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
- compareAtPriceRangeMinVariantPrice: product?.compareAtPriceRange?.minVariantPrice || {amount:0 , currencyCode:''},
- compareAtPriceRangeMaxVariantPrice: product?.compareAtPriceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
- productType: product?.productType || null,
- variants: product?.variants?.nodes || null,
-
- }
-
- }
|