Procházet zdrojové kódy

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

master
nadia před 13 hodinami
rodič
revize
b70a8704ba
2 změnil soubory, kde provedl 18 přidání a 2 odebrání
  1. 9
    1
      src/services/ProductService.js
  2. 9
    1
      src/utils/helpers.js

+ 9
- 1
src/services/ProductService.js Zobrazit soubor

72
           metafields(
72
           metafields(
73
             identifiers: [{key: "published_date", namespace: "custom"}, {key: "selected", namespace: "custom"}]
73
             identifiers: [{key: "published_date", namespace: "custom"}, {key: "selected", namespace: "custom"}]
74
           ) {
74
           ) {
75
+            namespace
75
             key
76
             key
77
+            type
76
             value
78
             value
77
           }
79
           }
78
         }
80
         }
162
         }
164
         }
163
       }
165
       }
164
       metafields(
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
         key
174
         key
175
+        type
168
         value
176
         value
169
       }
177
       }
170
     }
178
     }

+ 9
- 1
src/utils/helpers.js Zobrazit soubor

5
 
5
 
6
     if(!product) return
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
     let publishedDate = product?.metafields[0]?.value
15
     let publishedDate = product?.metafields[0]?.value
9
     let selected = product?.metafields[1]?.value
16
     let selected = product?.metafields[1]?.value
10
 
17
 
24
         compareAtPriceRangeMaxVariantPrice: product?.compareAtPriceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
31
         compareAtPriceRangeMaxVariantPrice: product?.compareAtPriceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
25
         productType: product?.productType || null,
32
         productType: product?.productType || null,
26
         variants: product?.variants?.nodes || null,
33
         variants: product?.variants?.nodes || null,
34
+        metafields: metafieldsByKey,
27
         
35
         
28
     }
36
     }
29
 
37
 
30
-}
38
+}

Načítá se…
Zrušit
Uložit