Browse Source

allow overwrite order via published date

master
azri 2 weeks ago
parent
commit
1f973882f0
2 changed files with 12 additions and 5 deletions
  1. 6
    2
      src/services/ProductService.js
  2. 6
    3
      src/utils/helpers.js

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

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
             key
75
             key
74
             value
76
             value
75
           }
77
           }
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
         key
167
         key
164
         value
168
         value
165
       }
169
       }

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

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

Loading…
Cancel
Save