@things-factory/integration-sellercraft 4.2.3 → 4.2.8

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 (28) hide show
  1. package/dist-server/constants/order-status-mapping.js +18 -4
  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-package.js +5 -2
  6. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js.map +1 -1
  7. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +2 -2
  8. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  9. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +25 -8
  10. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
  11. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +8 -4
  12. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
  13. package/dist-server/routers/sellercraft-router.js +26 -17
  14. package/dist-server/routers/sellercraft-router.js.map +1 -1
  15. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +291 -233
  16. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
  17. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +41 -23
  18. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
  19. package/package.json +3 -3
  20. package/server/constants/order-status-mapping.ts +18 -3
  21. package/server/constants/platform.ts +2 -1
  22. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.ts +6 -2
  23. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +2 -2
  24. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +34 -15
  25. package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +8 -4
  26. package/server/routers/sellercraft-router.ts +23 -17
  27. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +345 -271
  28. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +38 -35
@@ -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,38 +51,32 @@ export class MarketplaceChannelProductMutation {
50
51
 
51
52
  const productResult = []
52
53
  let totalPages: number = 1
53
- var limit: number = 50
54
+ let limit: number = 50
55
+ let parentLinks = []
54
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
66
  const categoryResult = []
64
67
  let totalPagesCategory: number = 1
65
- var limitCategory: number = 100
68
+ let limitCategory: number = 100
66
69
 
67
70
  for (let page = 0; page < totalPagesCategory; page++) {
68
- const { results, total } = await StoreAPI.getStoreProductCategories(store, { pagination: { page, limitCategory } })
71
+ const { results, total } = await StoreAPI.getStoreProductCategories(store, {
72
+ pagination: { page, limitCategory }
73
+ })
69
74
  totalPagesCategory = Math.ceil(total / limitCategory)
70
75
  categoryResult.push(...results)
71
76
  }
72
77
 
73
78
  let mappedProducts = productResult.map(item => {
74
- let {
75
- categoryId,
76
- itemId: productId,
77
- parentId,
78
- name,
79
- brand,
80
- isVerified,
81
- images,
82
- attributes,
83
- variations
84
- } = item
79
+ let { categoryId, itemId: productId, name, brand, isVerified, images, attributes, variations } = item
85
80
 
86
81
  variations = variations.map(variation => {
87
82
  let {
@@ -89,7 +84,7 @@ export class MarketplaceChannelProductMutation {
89
84
  variationId,
90
85
  name,
91
86
  isEnabled: isEnabled,
92
- isEnabled: isSellable,
87
+ isSellable: isSellable,
93
88
  attributes,
94
89
  stockLocked,
95
90
  qty: stockReported,
@@ -114,7 +109,7 @@ export class MarketplaceChannelProductMutation {
114
109
  priceDiscounted,
115
110
  inventoryProducts: [
116
111
  {
117
- qty: stockReported,
112
+ qty: 1,
118
113
  name: `${name} - ${variationSku}`,
119
114
  sku: variationSku,
120
115
  productVersions: [
@@ -124,7 +119,7 @@ export class MarketplaceChannelProductMutation {
124
119
  packageWidthMM: width,
125
120
  packageHeightMM: height,
126
121
  packageWeightGram: weight,
127
- qty: 1
122
+ qty: stockReported
128
123
  }
129
124
  ]
130
125
  }
@@ -144,7 +139,7 @@ export class MarketplaceChannelProductMutation {
144
139
  channelCode: channels[i].channelCode,
145
140
  channelCountry: shops[j].country_code,
146
141
  categoryId,
147
- productId: parentId || productId,
142
+ productId: parentLinks.find(e => e.children.includes(productId))?.id || productId,
148
143
  name,
149
144
  brand,
150
145
  isVerified,
@@ -169,18 +164,26 @@ export class MarketplaceChannelProductMutation {
169
164
  }
170
165
  })
171
166
 
172
- mappedCategories = mappedCategories.map(category => {
173
- if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
174
- category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId)
175
- }
176
- return category
177
- })
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
+ })
178
174
 
179
- await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
180
- categories: mappedCategories
181
- })
175
+ await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
176
+ categories: mappedCategories
177
+ })
178
+ } catch (e) {}
182
179
 
183
- 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) {}
184
187
  }
185
188
 
186
189
  return true