소스 검색

Merge remote-tracking branch 'origin/api-template'

master
azri 4 일 전
부모
커밋
e73098dd7e

+ 21
- 0
API/shopify/storefront/authentication.js 파일 보기

@@ -0,0 +1,21 @@
1
+// import {createStorefrontApiClient} from '@shopify/storefront-api-client';
2
+
3
+// const client = createStorefrontApiClient({
4
+//   storeDomain: 'http://amberdevstore.myshopify.com',
5
+//   apiVersion: '2024-10',
6
+//   publicAccessToken: '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',
7
+// });
8
+
9
+const adminApiClient = new shopify.clients.Rest({session});
10
+const storefrontTokenResponse = await adminApiClient.post({
11
+  path: 'storefront_access_tokens',
12
+  type: DataType.JSON,
13
+  data: {
14
+    storefront_access_token: {
15
+      title: 'This is my test access token',
16
+    },
17
+  },
18
+});
19
+
20
+const storefrontAccessToken =
21
+  storefrontTokenResponse.body['b3e24842a76e27e1d87206daededdab0']['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'];

+ 57
- 0
API/shopify/storefront/product/getProduct.js 파일 보기

@@ -0,0 +1,57 @@
1
+const storefrontClient = require('../storefrontClient');
2
+
3
+const defaultQuery = 'status:active, product_type:clothing, product_categroy:dresses'; // Replace to see custom result
4
+
5
+const defaultResult = 10; // Replace to change the number of result
6
+
7
+const defaultSortBy = 'TITLE'; // Replace with CREATED_AT if need to sort by date, current value is for name 
8
+
9
+const getProduct = async ( maxResults = defaultResult, sortBy = defaultSortBy, customQuery = defaultQuery ) => {
10
+    try {
11
+ 
12
+        const query = `{
13
+            products (first: ${maxResults}, sortKey: ${sortBy}, query: ${customQuery}) {
14
+                edges {
15
+                    node {
16
+                        id
17
+                        title
18
+                        status
19
+                        productType
20
+                        comparisonAtPriceRange {
21
+                            minVariantPrice {
22
+                                amount
23
+                                currencyCode
24
+                            }
25
+                            maxVariantPrice {
26
+                                amount
27
+                                currencyCode
28
+                            }
29
+                        }
30
+                        variants(first: 5) {
31
+                            edges {
32
+                                node {
33
+                                    id
34
+                                    title
35
+                                    price
36
+                                }
37
+                            }
38
+                        }
39
+                    }
40
+                }
41
+                pageInfo {
42
+                        hasNextPage
43
+                        hasPreviousPage
44
+                }
45
+            }
46
+        }`;
47
+
48
+        const products = await storefrontClient.query({ data: query });
49
+
50
+        return products;
51
+    } catch (error) {
52
+        throw error;
53
+    }
54
+};
55
+
56
+// Example
57
+// getProduct(5, CREATED_AT, 'product_type:clothing'); 

+ 13
- 0
API/shopify/storefront/storefrontClient.js 파일 보기

@@ -0,0 +1,13 @@
1
+const shopify = require('@shopify/shopify-api'); // Adjust import based on your environment
2
+
3
+// Load the access token and shop
4
+const storefrontAccessToken = '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'; // Replace with your actual access token
5
+const shop = 'amberdevstore.myshopify.com'; // Replace with your actual shop domain
6
+
7
+// Create and export the storefront client
8
+const storefrontClient = new shopify.clients.Storefront({
9
+  domain: shop,
10
+  storefrontAccessToken,
11
+});
12
+
13
+module.exports = storefrontClient;

+ 4
- 0
API/shopify/storefront/to_do_list.txt 파일 보기

@@ -0,0 +1,4 @@
1
+1. product tag
2
+2. product sort by date and name
3
+3. product suggested ( tagging?? )
4
+4. buang product replace with new product

Loading…
취소
저장