Просмотр исходного кода

feat module 6, 7 : include additional metafield in product service and helper

master
nadia 13 часов назад
Родитель
Сommit
b70a8704ba
2 измененных файлов: 18 добавлений и 2 удалений
  1. 9
    1
      src/services/ProductService.js
  2. 9
    1
      src/utils/helpers.js

+ 9
- 1
src/services/ProductService.js Просмотреть файл

@@ -72,7 +72,9 @@ const getProducts = async () => {
72 72
           metafields(
73 73
             identifiers: [{key: "published_date", namespace: "custom"}, {key: "selected", namespace: "custom"}]
74 74
           ) {
75
+            namespace
75 76
             key
77
+            type
76 78
             value
77 79
           }
78 80
         }
@@ -162,9 +164,15 @@ const getProduct = async (handle = "") => {
162 164
         }
163 165
       }
164 166
       metafields(
165
-        identifiers: [{key: "published_date", namespace: "custom"}, {key: "selected", namespace: "custom"}]
167
+        identifiers: [
168
+          {key: "published_date", namespace: "custom"},
169
+          {key: "selected", namespace: "custom"},
170
+          {key: "material", namespace: "custom"}
171
+        ]
166 172
       ) {
173
+        namespace
167 174
         key
175
+        type
168 176
         value
169 177
       }
170 178
     }

+ 9
- 1
src/utils/helpers.js Просмотреть файл

@@ -5,6 +5,13 @@ export const formatProductData = (product) => {
5 5
 
6 6
     if(!product) return
7 7
 
8
+    const metafieldsByKey = (product?.metafields || [])
9
+        .filter(Boolean)
10
+        .reduce((acc, metafield) => ({
11
+            ...acc,
12
+            [metafield.key]: metafield
13
+        }), {})
14
+
8 15
     let publishedDate = product?.metafields[0]?.value
9 16
     let selected = product?.metafields[1]?.value
10 17
 
@@ -24,7 +31,8 @@ export const formatProductData = (product) => {
24 31
         compareAtPriceRangeMaxVariantPrice: product?.compareAtPriceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
25 32
         productType: product?.productType || null,
26 33
         variants: product?.variants?.nodes || null,
34
+        metafields: metafieldsByKey,
27 35
         
28 36
     }
29 37
 
30
-}
38
+}

Загрузка…
Отмена
Сохранить