12345678910111213141516171819202122 |
- // 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
-
- return {
- id: product?.id || null,
- title: product?.title || "",
- createdAt: product?.createdAt,
- collections: product?.collections?.nodes || [],
- tags:product?.tags || [],
- images: product?.images?.nodes || [],
- selected: (product?.metafield?.key == "selected") ? product?.metafield?.value == "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:''},
- productType: product?.productType || null,
- variants: product?.variants?.nodes || []
- }
-
- }
|