@things-factory/integration-sellercraft 4.2.2 → 4.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/dist-server/constants/order-status-mapping.js +13 -3
  2. package/dist-server/constants/order-status-mapping.js.map +1 -1
  3. package/dist-server/constants/platform.js +2 -1
  4. package/dist-server/constants/platform.js.map +1 -1
  5. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +1 -1
  6. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  7. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +25 -8
  8. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
  9. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +8 -4
  10. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
  11. package/dist-server/routers/sellercraft-router.js +2 -1
  12. package/dist-server/routers/sellercraft-router.js.map +1 -1
  13. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +253 -231
  14. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
  15. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +48 -23
  16. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
  17. package/package.json +3 -3
  18. package/server/constants/order-status-mapping.ts +13 -3
  19. package/server/constants/platform.ts +2 -1
  20. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +1 -1
  21. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +34 -15
  22. package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +8 -4
  23. package/server/routers/sellercraft-router.ts +2 -1
  24. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +305 -270
  25. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +47 -26
@@ -1,11 +1,11 @@
1
1
  import { Ctx, Mutation, Resolver } from 'type-graphql'
2
2
  import { getRepository } from 'typeorm'
3
3
 
4
- import { MarketplaceChannel } from './marketplace-channel'
5
-
6
4
  import { config } from '@things-factory/env'
7
5
  import { StoreAPI } from '@things-factory/integration-marketplace'
6
+
8
7
  import { SellercraftChannelIntegrationAPI } from '../../controllers/sellercraft-channel-integration-api'
8
+ import { MarketplaceChannel } from './marketplace-channel'
9
9
 
10
10
  @Resolver()
11
11
  export class MarketplaceChannelProductMutation {
@@ -34,11 +34,12 @@ export class MarketplaceChannelProductMutation {
34
34
 
35
35
  for (var j = 0; j < shops.length; j++) {
36
36
  var store = {
37
- accessKey: shops[j].credential.consumer_key,
38
- accessSecret: shops[j].credential.consumer_secret,
39
- storeURL: shops[j].credential.store_url,
37
+ accessKey: shops[j]?.credential?.consumer_key || '',
38
+ accessSecret: shops[j]?.credential?.consumer_secret || '',
39
+ storeURL: shops[j]?.credential?.store_url || '',
40
40
  platform: channels[i].name,
41
- accessToken: shops[j].credential.access_token // Magento+
41
+ accessToken: shops[j]?.credential?.access_token, // Magento+, Tiktok
42
+ channelShopId: shops[j]?.channel_shop_id
42
43
  }
43
44
 
44
45
  let countryCode = shops[j].country_code
@@ -50,20 +51,32 @@ export class MarketplaceChannelProductMutation {
50
51
 
51
52
  const productResult = []
52
53
  let totalPages: number = 1
53
- var limit: number = 50
54
-
54
+ let limit: number = 50
55
+ let parentLinks = []
56
+
55
57
  for (let page = 0; page < totalPages; page++) {
56
- const { results, total } = await StoreAPI.getStoreProducts(store, {
58
+ const { results, total, parentLinkList } = await StoreAPI.getStoreProducts(store, {
57
59
  pagination: { page, limit }
58
60
  })
59
61
  totalPages = Math.ceil(total / limit)
60
62
  productResult.push(...results)
63
+ if (store.platform == 'magento') parentLinks.push(...parentLinkList)
61
64
  }
62
65
 
63
- const categoryResult = await StoreAPI.getStoreProductCategories(store, {})
66
+ const categoryResult = []
67
+ let totalPagesCategory: number = 1
68
+ let limitCategory: number = 100
69
+
70
+ for (let page = 0; page < totalPagesCategory; page++) {
71
+ const { results, total } = await StoreAPI.getStoreProductCategories(store, {
72
+ pagination: { page, limitCategory }
73
+ })
74
+ totalPagesCategory = Math.ceil(total / limitCategory)
75
+ categoryResult.push(...results)
76
+ }
64
77
 
65
78
  let mappedProducts = productResult.map(item => {
66
- let { categoryId, itemId: productId, parentId, name, brand, isVerified, images, attributes, variations } = item
79
+ let { categoryId, itemId: productId, name, brand, isVerified, images, attributes, variations } = item
67
80
 
68
81
  variations = variations.map(variation => {
69
82
  let {
@@ -71,7 +84,7 @@ export class MarketplaceChannelProductMutation {
71
84
  variationId,
72
85
  name,
73
86
  isEnabled: isEnabled,
74
- isEnabled: isSellable,
87
+ isSellable: isSellable,
75
88
  attributes,
76
89
  stockLocked,
77
90
  qty: stockReported,
@@ -96,7 +109,7 @@ export class MarketplaceChannelProductMutation {
96
109
  priceDiscounted,
97
110
  inventoryProducts: [
98
111
  {
99
- qty: stockReported,
112
+ qty: 1,
100
113
  name: `${name} - ${variationSku}`,
101
114
  sku: variationSku,
102
115
  productVersions: [
@@ -106,7 +119,7 @@ export class MarketplaceChannelProductMutation {
106
119
  packageWidthMM: width,
107
120
  packageHeightMM: height,
108
121
  packageWeightGram: weight,
109
- qty: 1
122
+ qty: stockReported
110
123
  }
111
124
  ]
112
125
  }
@@ -126,7 +139,7 @@ export class MarketplaceChannelProductMutation {
126
139
  channelCode: channels[i].channelCode,
127
140
  channelCountry: shops[j].country_code,
128
141
  categoryId,
129
- productId: parentId || productId,
142
+ productId: parentLinks.find(e => e.children.includes(productId))?.id || productId,
130
143
  name,
131
144
  brand,
132
145
  isVerified,
@@ -136,7 +149,7 @@ export class MarketplaceChannelProductMutation {
136
149
  }
137
150
  })
138
151
 
139
- let mappedCategories = categoryResult.results.map(category => {
152
+ let mappedCategories = categoryResult.map(category => {
140
153
  let { id: categoryId, name: categoryName, parent, isActive } = category
141
154
 
142
155
  return {
@@ -151,18 +164,26 @@ export class MarketplaceChannelProductMutation {
151
164
  }
152
165
  })
153
166
 
154
- mappedCategories = mappedCategories.map(category => {
155
- if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
156
- category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId)
157
- }
158
- return category
159
- })
167
+ try {
168
+ mappedCategories = mappedCategories.map(category => {
169
+ if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
170
+ category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId)
171
+ }
172
+ return category
173
+ })
160
174
 
161
- await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
162
- categories: mappedCategories
163
- })
175
+ await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
176
+ categories: mappedCategories
177
+ })
178
+ } catch (e) {}
164
179
 
165
- await SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, { products: mappedProducts })
180
+ try {
181
+ for (let k = 0, l = mappedProducts.length; k < l; k++) {
182
+ await SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, {
183
+ products: [mappedProducts[k]]
184
+ })
185
+ }
186
+ } catch (e) {}
166
187
  }
167
188
 
168
189
  return true