Amber Shopify Project created using ReactJS+React-Redux with GraphQL API integration. Storefront Shopify API: https://github.com/Shopify/shopify-app-js/tree/main/packages/api-clients/storefront-api-client#readme
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

helpers.js 1.4KB

123456789101112131415161718192021222324252627282930
  1. // Cause I want to have a properly standardize product data cause I hate those "nodes" thinggy
  2. // and to prevent render error in case some data doesn't exist, I want a default value
  3. export const formatProductData = (product) => {
  4. if(!product) return
  5. let publishedDate = product?.metafields[0]?.value
  6. let selected = product?.metafields[1]?.value
  7. return {
  8. id: product?.id || null,
  9. handle: product?.handle || "",
  10. title: product?.title || "",
  11. createdAt: publishedDate || product?.createdAt,
  12. collections: product?.collections?.nodes || null,
  13. descriptionHtml: product?.descriptionHtml || "",
  14. tags:product?.tags || null,
  15. images: product?.images?.nodes || null,
  16. 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
  17. minVariantPrice: product?.priceRange?.minVariantPrice || {amount:0 , currencyCode:''},
  18. maxVariantPrice: product?.priceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
  19. compareAtPriceRangeMinVariantPrice: product?.compareAtPriceRange?.minVariantPrice || {amount:0 , currencyCode:''},
  20. compareAtPriceRangeMaxVariantPrice: product?.compareAtPriceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
  21. productType: product?.productType || null,
  22. variants: product?.variants?.nodes || null,
  23. }
  24. }