Sfoglia il codice sorgente

allow overwrite order via published date

master
azri 2 settimane fa
parent
commit
1f973882f0
2 ha cambiato i file con 12 aggiunte e 5 eliminazioni
  1. 6
    2
      src/services/ProductService.js
  2. 6
    3
      src/utils/helpers.js

+ 6
- 2
src/services/ProductService.js Vedi File

@@ -69,7 +69,9 @@ const getProducts = async () => {
69 69
               }
70 70
             }
71 71
           }
72
-          metafield(key: "selected", namespace: "custom") {
72
+          metafields(
73
+            identifiers: [{key: "published_date", namespace: "custom"}, {key: "selected", namespace: "custom"}]
74
+          ) {
73 75
             key
74 76
             value
75 77
           }
@@ -159,7 +161,9 @@ const getProduct = async (handle = "") => {
159 161
           }
160 162
         }
161 163
       }
162
-      metafield(key: "selected", namespace: "custom") {
164
+      metafields(
165
+        identifiers: [{key: "published_date", namespace: "custom"}, {key: "selected", namespace: "custom"}]
166
+      ) {
163 167
         key
164 168
         value
165 169
       }

+ 6
- 3
src/utils/helpers.js Vedi File

@@ -4,17 +4,20 @@
4 4
 export const formatProductData = (product) => {
5 5
 
6 6
     if(!product) return
7
-    
7
+
8
+    let publishedDate = product?.metafields[0]?.value
9
+    let selected = product?.metafields[1]?.value
10
+
8 11
     return {
9 12
         id: product?.id || null,
10 13
         handle: product?.handle || "",
11 14
         title: product?.title || "",
12
-        createdAt: product?.createdAt,
15
+        createdAt: publishedDate || product?.createdAt,
13 16
         collections: product?.collections?.nodes || null,
14 17
         descriptionHtml: product?.descriptionHtml || "",
15 18
         tags:product?.tags || null,
16 19
         images: product?.images?.nodes || null,
17
-        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
20
+        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
18 21
         minVariantPrice: product?.priceRange?.minVariantPrice || {amount:0 , currencyCode:''},
19 22
         maxVariantPrice: product?.priceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
20 23
         compareAtPriceRangeMinVariantPrice: product?.compareAtPriceRange?.minVariantPrice || {amount:0 , currencyCode:''},

Loading…
Annulla
Salva