@things-factory/integration-sellercraft 5.0.0-alpha.5 → 5.0.0-alpha.52

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 (63) hide show
  1. package/dist-server/constants/index.js +1 -0
  2. package/dist-server/constants/index.js.map +1 -1
  3. package/dist-server/constants/order-status-mapping.js +31 -0
  4. package/dist-server/constants/order-status-mapping.js.map +1 -0
  5. package/dist-server/constants/platform.js +4 -1
  6. package/dist-server/constants/platform.js.map +1 -1
  7. package/dist-server/controllers/index.js +2 -0
  8. package/dist-server/controllers/index.js.map +1 -1
  9. package/dist-server/controllers/sellercraft/sellercraft.js +2 -2
  10. package/dist-server/controllers/sellercraft/sellercraft.js.map +1 -1
  11. package/dist-server/controllers/sellercraft-api/decorators.js +2 -0
  12. package/dist-server/controllers/sellercraft-api/decorators.js.map +1 -1
  13. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js +19 -20
  14. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js.map +1 -1
  15. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js +5 -2
  16. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js.map +1 -1
  17. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +29 -19
  18. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  19. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +27 -41
  20. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
  21. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +18 -7
  22. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
  23. package/dist-server/routers/sellercraft-router.js +221 -135
  24. package/dist-server/routers/sellercraft-router.js.map +1 -1
  25. package/dist-server/service/index.js +5 -1
  26. package/dist-server/service/index.js.map +1 -1
  27. package/dist-server/service/marketplace-channel/index.js +9 -0
  28. package/dist-server/service/marketplace-channel/index.js.map +1 -0
  29. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +366 -0
  30. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -0
  31. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +212 -0
  32. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -0
  33. package/dist-server/service/marketplace-channel/marketplace-channel.js +88 -0
  34. package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -0
  35. package/dist-server/service/sellercraft/sellercraft-mutation.js +3 -6
  36. package/dist-server/service/sellercraft/sellercraft-mutation.js.map +1 -1
  37. package/dist-server/service/sellercraft/sellercraft-query.js +1 -1
  38. package/dist-server/service/sellercraft/sellercraft-query.js.map +1 -1
  39. package/dist-server/service/sellercraft/sellercraft.js +1 -1
  40. package/dist-server/utils/tokencraft-util.js +63 -0
  41. package/dist-server/utils/tokencraft-util.js.map +1 -0
  42. package/package.json +15 -15
  43. package/server/constants/index.ts +2 -1
  44. package/server/constants/order-status-mapping.ts +28 -0
  45. package/server/constants/platform.ts +4 -1
  46. package/server/controllers/index.ts +2 -0
  47. package/server/controllers/sellercraft/sellercraft.ts +2 -2
  48. package/server/controllers/sellercraft-api/decorators.ts +3 -0
  49. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.ts +19 -20
  50. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.ts +6 -2
  51. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +30 -19
  52. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +34 -48
  53. package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +16 -7
  54. package/server/routers/sellercraft-router.ts +231 -147
  55. package/server/service/index.ts +6 -1
  56. package/server/service/marketplace-channel/index.ts +6 -0
  57. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +418 -0
  58. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +221 -0
  59. package/server/service/marketplace-channel/marketplace-channel.ts +68 -0
  60. package/server/service/sellercraft/sellercraft-mutation.ts +3 -3
  61. package/server/service/sellercraft/sellercraft-query.ts +1 -1
  62. package/server/service/sellercraft/sellercraft.ts +1 -1
  63. package/server/utils/tokencraft-util.ts +60 -0
@@ -0,0 +1,418 @@
1
+ import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
2
+ import { getRepository } from 'typeorm'
3
+
4
+ import { config } from '@things-factory/env'
5
+ import { StoreAPI } from '@things-factory/integration-marketplace'
6
+
7
+ import { SHIPPING_TYPE } from '../../constants'
8
+ import { SellercraftChannelIntegrationAPI } from '../../controllers/sellercraft-channel-integration-api'
9
+ import { MarketplaceChannel } from './marketplace-channel'
10
+ import { getShops } from '../../utils/tokencraft-util'
11
+
12
+ @Resolver()
13
+ export class MarketplaceChannelOrderMutation {
14
+ @Mutation(returns => Boolean)
15
+ async syncAllMarketplaceChannelOrders(
16
+ @Ctx() context: any,
17
+ @Arg('fromCreatedDate', { nullable: true }) fromCreatedDate?: string,
18
+ @Arg('toCreatedDate', { nullable: true }) toCreatedDate?: string,
19
+ @Arg('fromUpdatedDate', { nullable: true }) fromUpdatedDate?: string,
20
+ @Arg('toUpdatedDate', { nullable: true }) toUpdatedDate?: string
21
+ ): Promise<boolean> {
22
+ const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
23
+
24
+ const channels: MarketplaceChannel[] = await getRepository(MarketplaceChannel).find({ where: { isActive: true } })
25
+
26
+ for (var i = 0; i < channels.length; i++) {
27
+ try {
28
+ const channel: MarketplaceChannel = channels[i]
29
+ let shops: any = await getShops(channel.channelId)
30
+
31
+ for (var j = 0; j < shops.length; j++) {
32
+ try {
33
+ var store = {
34
+ accessKey: shops[j]?.credential?.consumer_key || '',
35
+ accessSecret: shops[j]?.credential?.consumer_secret || '',
36
+ storeURL: shops[j]?.credential?.store_url || '',
37
+ platform: channel.name,
38
+ accessToken: shops[j]?.credential?.access_token, // Magento+, Tiktok
39
+ channelShopId: shops[j]?.channel_shop_id,
40
+ storeId: shops[j]?.credential?.store_url || ''
41
+ }
42
+
43
+ // let countryCode = shops[j].country_code
44
+ // let channelCode = shops[j].org_prefix
45
+ let organisationId = shops[j].account_id
46
+ let channelShopId = shops[j].channel_shop_id
47
+
48
+ let orderResult = []
49
+ let page: number = store.platform == 'magento' ? 1 : 0
50
+ let hasMorePage: boolean = true
51
+ let lastOrderId: string
52
+ let cursor: string
53
+ var limit: number = 50
54
+
55
+ while (hasMorePage) {
56
+ const {
57
+ results: marketplaceOrders,
58
+ more,
59
+ nextCursor
60
+ } = await StoreAPI.getStoreOrders(store, {
61
+ fromCreatedDate,
62
+ toCreatedDate,
63
+ fromUpdatedDate,
64
+ toUpdatedDate,
65
+ pagination: { page, limit },
66
+ lastOrderId,
67
+ nextCursor: cursor
68
+ })
69
+
70
+ orderResult.push(...marketplaceOrders)
71
+
72
+ if (more) page++
73
+ hasMorePage = more
74
+ cursor = nextCursor
75
+ }
76
+
77
+ var sellercraftStore = { ...store, platform: 'sellercraftChannelIntegration' }
78
+
79
+ let mappedOrderResult = orderResult.map(order => {
80
+ let id = store.platform == 'magento' || store.platform == 'shopify' ? order.name : order.orderNo
81
+ let {
82
+ firstName: custFirstName,
83
+ lastName: custLastName,
84
+ orderCreatedAt: createdAt,
85
+ orderUpdatedAt: updatedAt,
86
+ status,
87
+ sellercraftStatus,
88
+ isSOF
89
+ } = order
90
+
91
+ let {
92
+ first_name: billFirstName,
93
+ last_name: billLastName,
94
+ address_1: billAddress1,
95
+ address_2: billAddress2,
96
+ address_3: billAddress3,
97
+ address_4: billAddress4,
98
+ address_5: billAddress5,
99
+ city: billCity,
100
+ postcode: billPostalCode,
101
+ country: billCountry,
102
+ phone: billPhone1,
103
+ phone_2: billPhone2
104
+ } = order?.billing
105
+
106
+ let {
107
+ first_name: shipFirstName,
108
+ last_name: shipLastName,
109
+ address_1: shipAddress1,
110
+ address_2: shipAddress2,
111
+ address_3: shipAddress3,
112
+ address_4: shipAddress4,
113
+ address_5: shipAddress5,
114
+ city: shipCity,
115
+ postcode: shipPostalCode,
116
+ country: shipCountry,
117
+ phone: shipPhone1,
118
+ phone_2: shipPhone2
119
+ } = order.shipping
120
+
121
+ let orderPackage = order?.orderPackage || {}
122
+
123
+ let orderItems = order.orderItems.map(item => {
124
+ let {
125
+ name: id,
126
+ variationId: variationId,
127
+ slaExpiresAt,
128
+ total,
129
+ totalTax,
130
+ subtotal,
131
+ subtotalTax,
132
+ qty
133
+ } = item
134
+
135
+ return {
136
+ id,
137
+ variationId,
138
+ currency: order.orderShipping.collectionCurrency,
139
+ createdAt: order.orderCreatedAt,
140
+ updatedAt: order.orderUpdatedAt,
141
+ charges: [
142
+ {
143
+ name: 'CHARGES_MARKETING',
144
+ grossAmount: 0,
145
+ nettAmount: 0
146
+ },
147
+ {
148
+ name: 'CLAIMS_DAMAGE',
149
+ grossAmount: 0,
150
+ nettAmount: 0
151
+ },
152
+ {
153
+ name: 'CLAIMS_LOST',
154
+ grossAmount: 0,
155
+ nettAmount: 0
156
+ },
157
+ {
158
+ name: 'COMMISSION_PLATFORM',
159
+ grossAmount: 0,
160
+ nettAmount: 0
161
+ },
162
+ {
163
+ name: 'DEPOSIT_PRESALE',
164
+ grossAmount: 0,
165
+ nettAmount: 0
166
+ },
167
+ {
168
+ name: 'FEE_MISCELLANEOUS',
169
+ grossAmount: 0,
170
+ nettAmount: 0
171
+ },
172
+ {
173
+ name: 'FEE_TRANSACTION',
174
+ grossAmount: 0,
175
+ nettAmount: 0
176
+ },
177
+ {
178
+ name: 'PRICE_NORMAL_SELLING',
179
+ grossAmount: total,
180
+ nettAmount: subtotal
181
+ },
182
+ {
183
+ name: 'PRICE_RECOMMENDED_RETAIL',
184
+ grossAmount: 0,
185
+ nettAmount: 0
186
+ },
187
+ {
188
+ name: 'PROMOTIONS_CUSTOMER_RECEIVED',
189
+ grossAmount: 0,
190
+ nettAmount: 0
191
+ },
192
+ {
193
+ name: 'PROMOTIONS_REBATE_PLATFORM',
194
+ grossAmount: 0,
195
+ nettAmount: 0
196
+ },
197
+ {
198
+ name: 'PROMOTIONS_REBATE_SELLER',
199
+ grossAmount: 0,
200
+ nettAmount: 0
201
+ },
202
+ {
203
+ name: 'REVERSAL_CHARGES_MARKETING',
204
+ grossAmount: 0,
205
+ nettAmount: 0
206
+ },
207
+ {
208
+ name: 'REVERSAL_COMMISSION',
209
+ grossAmount: 0,
210
+ nettAmount: 0
211
+ },
212
+ {
213
+ name: 'REVERSAL_FEE_MISCELLANEOUS',
214
+ grossAmount: 0,
215
+ nettAmount: 0
216
+ },
217
+ {
218
+ name: 'REVERSAL_PROMOTIONS_CUSTOMER_RECEIVED',
219
+ grossAmount: 0,
220
+ nettAmount: 0
221
+ },
222
+ {
223
+ name: 'REVERSAL_SELLER_RETURN_REFUND_AMOUNT',
224
+ grossAmount: 0,
225
+ nettAmount: 0
226
+ },
227
+ {
228
+ name: 'REVERSAL_SHIPPING_CUSTOMER_PAID',
229
+ grossAmount: 0,
230
+ nettAmount: 0
231
+ },
232
+ {
233
+ name: 'REVERSAL_SHIPPING_REBATE_PLATFORM',
234
+ grossAmount: 0,
235
+ nettAmount: 0
236
+ },
237
+ {
238
+ name: 'REVERSAL_SHIPPING_SELLER_PAID',
239
+ grossAmount: 0,
240
+ nettAmount: 0
241
+ },
242
+ {
243
+ name: 'SHIPPING_COST_TOTAL',
244
+ grossAmount: 0,
245
+ nettAmount: 0
246
+ },
247
+ {
248
+ name: 'SHIPPING_CUSTOMER_PAID',
249
+ grossAmount: 0,
250
+ nettAmount: 0
251
+ },
252
+ {
253
+ name: 'SHIPPING_REBATE_PLATFORM',
254
+ grossAmount: 0,
255
+ nettAmount: 0
256
+ },
257
+ {
258
+ name: 'SHIPPING_SELLER_PAID',
259
+ grossAmount: 0,
260
+ nettAmount: 0
261
+ },
262
+ {
263
+ name: 'TAXES',
264
+ grossAmount: totalTax,
265
+ nettAmount: subtotalTax
266
+ },
267
+ {
268
+ name: 'VOUCHERS_CUSTOMER_RECEIVED',
269
+ grossAmount: 0,
270
+ nettAmount: 0
271
+ },
272
+ {
273
+ name: 'VOUCHERS_REBATE_PLATFORM',
274
+ grossAmount: 0,
275
+ nettAmount: 0
276
+ },
277
+ {
278
+ name: 'VOUCHERS_REBATE_SELLER',
279
+ grossAmount: 0,
280
+ nettAmount: 0
281
+ }
282
+ ],
283
+ slaExpiresAt,
284
+ qty
285
+ }
286
+ })
287
+
288
+ let mappedOrderItems = []
289
+ orderItems.map(oi => {
290
+ for (let i = 0; i < oi.qty; i++) {
291
+ mappedOrderItems.push({
292
+ ...oi,
293
+ id: `${oi.id}-${i + 1}`
294
+ })
295
+ }
296
+ })
297
+
298
+ return {
299
+ custFirstName,
300
+ custLastName,
301
+ createdAt,
302
+ updatedAt,
303
+ id,
304
+ billFirstName,
305
+ billLastName,
306
+ billAddress1: billAddress1.toString() || shipAddress1.toString(),
307
+ billAddress2: billAddress2 || shipAddress2,
308
+ billAddress3: billAddress3 || shipAddress3,
309
+ billAddress4: billAddress4 || shipAddress4,
310
+ billAddress5: billAddress5 || shipAddress5,
311
+ billCity: billCity || shipCity,
312
+ billPostalCode: billPostalCode || shipPostalCode,
313
+ billCountry: billCountry || shipCountry,
314
+ billPhone1: billPhone1 || shipPhone1,
315
+ billPhone2: billPhone2 || shipPhone2,
316
+ shipFirstName,
317
+ shipLastName,
318
+ shipAddress1: shipAddress1.toString(),
319
+ shipAddress2,
320
+ shipAddress3,
321
+ shipAddress4,
322
+ shipAddress5,
323
+ shipCity,
324
+ shipPostalCode,
325
+ shipCountry,
326
+ shipPhone1,
327
+ shipPhone2,
328
+ mappedOrderItems,
329
+ channelShopId,
330
+ organisationId,
331
+ status: sellercraftStatus || status,
332
+ isSOF: isSOF ? isSOF : false,
333
+ orderPackage,
334
+ charges: getOrderCharges(mappedOrderItems)
335
+ }
336
+ })
337
+
338
+ if (mappedOrderResult.length > 0) {
339
+ while (mappedOrderResult.length > 0) {
340
+ let spliceResult = mappedOrderResult.splice(
341
+ 0,
342
+ mappedOrderResult.length >= 20 ? 20 : mappedOrderResult.length
343
+ )
344
+
345
+ try {
346
+ await SellercraftChannelIntegrationAPI.ingestChannelOrder(sellercraftStore, {
347
+ orders: spliceResult
348
+ })
349
+ } catch (e) {}
350
+
351
+ await Promise.all(
352
+ spliceResult.map(async result => {
353
+ if (!result?.isSOF && result?.orderPackage?.packageId) {
354
+ let orderPackage: any = result.orderPackage
355
+ let newOrderPackage: any = {
356
+ channelShopId,
357
+ nativeOrderId: result.id,
358
+ nativePackageId: orderPackage.packageId,
359
+ shippingTrackingCode: orderPackage.trackingNumber,
360
+ shippingTypeValue: orderPackage?.shippingType
361
+ ? orderPackage.shippingType
362
+ : SHIPPING_TYPE.DROP_SHIPPING,
363
+ warehouseCode: SHIPPING_TYPE.DROP_SHIPPING,
364
+ shipper: {
365
+ name: orderPackage.shippingProvider,
366
+ isCodSupported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
367
+ },
368
+ documents: orderPackage?.orderDocument || [],
369
+ shipperLastMile: {
370
+ name: orderPackage.shippingProvider,
371
+ isCodSupported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
372
+ },
373
+ orderItemIds: orderPackage?.orderListIdList
374
+ ? orderPackage.orderListIdList
375
+ : result.mappedOrderItems.map(orderItem => orderItem.id)
376
+ }
377
+ try {
378
+ await SellercraftChannelIntegrationAPI.ingestChannelOrderPackage(
379
+ sellercraftStore,
380
+ newOrderPackage
381
+ )
382
+ } catch (e) {}
383
+ }
384
+ })
385
+ )
386
+ }
387
+ }
388
+ } catch (e) {}
389
+ }
390
+ } catch (e) {}
391
+ }
392
+ return true
393
+ }
394
+ }
395
+
396
+ function getOrderCharges(mappedOrderItems) {
397
+ let chargesList = []
398
+
399
+ for (let i = 0; i < mappedOrderItems.length; i++) {
400
+ for (let j = 0; j < mappedOrderItems[i].charges.length; j++) {
401
+ let charge = mappedOrderItems[i].charges[j]
402
+ let foundCharge = chargesList.find(cl => cl.name == charge.name)
403
+ if (foundCharge) {
404
+ foundCharge.grossAmount = parseFloat(foundCharge.grossAmount) + parseFloat(charge.grossAmount)
405
+ foundCharge.nettAmount = parseFloat(foundCharge.nettAmount) + parseFloat(charge.nettAmount)
406
+ chargesList = chargesList.filter(cl => cl.name != charge.name)
407
+ } else {
408
+ foundCharge = {
409
+ name: charge.name,
410
+ grossAmount: charge.grossAmount,
411
+ nettAmount: charge.nettAmount
412
+ }
413
+ }
414
+ chargesList.push(foundCharge)
415
+ }
416
+ }
417
+ return chargesList
418
+ }
@@ -0,0 +1,221 @@
1
+ import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
2
+ import { getRepository } from 'typeorm'
3
+
4
+ import { config } from '@things-factory/env'
5
+ import { StoreAPI } from '@things-factory/integration-marketplace'
6
+
7
+ import { SellercraftChannelIntegrationAPI } from '../../controllers/sellercraft-channel-integration-api'
8
+ import { MarketplaceChannel } from './marketplace-channel'
9
+ import { getShops } from '../../utils/tokencraft-util'
10
+
11
+ @Resolver()
12
+ export class MarketplaceChannelProductMutation {
13
+ @Mutation(returns => Boolean)
14
+ async syncAllMarketplaceChannelProducts(
15
+ @Ctx() context: any,
16
+ @Arg('fromUpdatedDate', { nullable: true }) fromUpdatedDate?: string,
17
+ @Arg('toUpdatedDate', { nullable: true }) toUpdatedDate?: string
18
+ ): Promise<boolean> {
19
+ const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
20
+
21
+ const channels: MarketplaceChannel[] = await getRepository(MarketplaceChannel).find({ where: { isActive: true } })
22
+
23
+ for (var i = 0; i < channels.length; i++) {
24
+ try {
25
+ let shops: any = await getShops(channels[i].channelId)
26
+
27
+ for (var j = 0; j < shops.length; j++) {
28
+ try {
29
+ var store = {
30
+ accessKey: shops[j]?.credential?.consumer_key || '',
31
+ accessSecret: shops[j]?.credential?.consumer_secret || '',
32
+ storeURL: shops[j]?.credential?.store_url || '',
33
+ platform: channels[i].name,
34
+ accessToken: shops[j]?.credential?.access_token, // Magento+, Tiktok
35
+ channelShopId: shops[j]?.channel_shop_id,
36
+ storeId: shops[j]?.credential?.store_url || ''
37
+ }
38
+
39
+ let countryCode = shops[j].country_code
40
+ let channelCode = shops[j].org_prefix
41
+ let organisationId = shops[j].account_id
42
+ let channelShopId = shops[j].channel_shop_id
43
+
44
+ var sellercraftStore = { ...store, platform: 'sellercraftChannelIntegration' }
45
+
46
+ const productResult = []
47
+ let totalPages: number = 1
48
+ let limit: number = 50
49
+ let parentLinks = []
50
+
51
+ for (let page = 0; page < totalPages; page++) {
52
+ const { results, total, parentLinkList } = await StoreAPI.getStoreProducts(store, {
53
+ pagination: { page, limit }
54
+ })
55
+ totalPages = Math.ceil(total / limit)
56
+ productResult.push(...results)
57
+ if (store.platform == 'magento') parentLinks.push(...parentLinkList)
58
+ }
59
+
60
+ const categoryResult = []
61
+ let totalPagesCategory: number = 1
62
+ let limitCategory: number = 100
63
+
64
+ if (store.platform != 'shopify') {
65
+ for (let page = 0; page < totalPagesCategory; page++) {
66
+ const { results, total } = await StoreAPI.getStoreProductCategories(store, {
67
+ pagination: { page, limitCategory }
68
+ })
69
+ totalPagesCategory = Math.ceil(total / limitCategory)
70
+ categoryResult.push(...results)
71
+ }
72
+ } else {
73
+ categoryResult.push({ id: 1, name: 'default', isActive: true })
74
+ }
75
+
76
+ let mappedProducts = productResult.map(item => {
77
+ let { categoryId, itemId: productId, name, brand, isVerified, images, sellercraftAttributes, variations } = item
78
+
79
+ variations = variations.map(variation => {
80
+ let {
81
+ variationSku,
82
+ variationId,
83
+ name,
84
+ isEnabled: isEnabled,
85
+ isSellable: isSellable,
86
+ sellercraftAttributes,
87
+ stockLocked,
88
+ qty: stockReported,
89
+ costPrice: fullPrice,
90
+ sellPrice: priceDiscounted,
91
+ length,
92
+ width,
93
+ height,
94
+ weight,
95
+ extraMetadata
96
+ } = variation
97
+
98
+ return {
99
+ variationSku,
100
+ variationId,
101
+ name,
102
+ isEnabled,
103
+ isSellable,
104
+ attributes: sellercraftAttributes || [],
105
+ stockLocked,
106
+ stockReported,
107
+ fullPrice: parseFloat(fullPrice) || 0,
108
+ priceDiscounted: parseFloat(priceDiscounted) || 0,
109
+ inventoryProducts: [
110
+ {
111
+ qty: 1,
112
+ name: `${name} - ${variationSku}`,
113
+ sku: variationSku,
114
+ productVersions: [
115
+ {
116
+ label: 'Default',
117
+ packageLengthMM: length,
118
+ packageWidthMM: width,
119
+ packageHeightMM: height,
120
+ packageWeightGram: weight,
121
+ qty: stockReported
122
+ }
123
+ ]
124
+ }
125
+ ],
126
+ extraMetadata
127
+ }
128
+ })
129
+
130
+ images = images?.map(image => {
131
+ return {
132
+ url: image
133
+ }
134
+ })
135
+
136
+ return {
137
+ organisationId,
138
+ channelShopId: channelShopId,
139
+ channelCode: channels[i].channelCode,
140
+ channelCountry: shops[j].country_code,
141
+ categoryId: store.platform == 'shopify' ? 1 : categoryId,
142
+ productId: parentLinks.find(e => e.children.includes(productId))?.id || productId,
143
+ name,
144
+ brand,
145
+ isVerified,
146
+ images,
147
+ attributes: sellercraftAttributes || [],
148
+ variations
149
+ }
150
+ })
151
+
152
+ let mappedCategories = categoryResult.map(category => {
153
+ let { id: categoryId, name: categoryName, parent, isActive } = category
154
+
155
+ return {
156
+ categoryId,
157
+ categoryName,
158
+ parent,
159
+ isActive: isActive || true,
160
+ channelCode,
161
+ countryCode,
162
+ childrenCategories: []
163
+ }
164
+ })
165
+
166
+ if (store.platform == 'magento') {
167
+ let newList = []
168
+ for (let np of mappedProducts) {
169
+ if (np.productId == np.variations[0].variationId) {
170
+ let vars = mappedProducts
171
+ .filter(e => e.productId == np.productId)
172
+ .map(e => {
173
+ return e.variations[0]
174
+ })
175
+ np.variations = vars
176
+ if (np.variations.length > 1) {
177
+ np.variations = np.variations.filter(v => v.variationId != np.productId)
178
+ }
179
+ newList.push(np)
180
+ }
181
+ }
182
+ mappedProducts = newList
183
+ }
184
+
185
+ try {
186
+ let filterList = []
187
+ mappedCategories = mappedCategories.map(category => {
188
+ if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
189
+ category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId)
190
+ filterList.push(...mappedCategories.filter(e => e.parent == category.categoryId))
191
+ }
192
+ return category
193
+ })
194
+
195
+ mappedCategories = mappedCategories
196
+ .map(mc => {
197
+ if (filterList.indexOf(mc) == -1) {
198
+ return mc
199
+ }
200
+ })
201
+ .filter(e => e)
202
+
203
+ await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
204
+ categories: mappedCategories
205
+ })
206
+ } catch (e) {}
207
+
208
+ try {
209
+ for (let k = 0, l = mappedProducts.length; k < l; k++) {
210
+ await SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, {
211
+ products: [mappedProducts[k]]
212
+ })
213
+ }
214
+ } catch (e) {}
215
+ } catch (e) {}
216
+ }
217
+ } catch (e) {}
218
+ }
219
+ return true
220
+ }
221
+ }
@@ -0,0 +1,68 @@
1
+ import { Field, ID, ObjectType } from 'type-graphql'
2
+ import {
3
+ Column,
4
+ CreateDateColumn,
5
+ Entity,
6
+ Index,
7
+ ManyToOne,
8
+ PrimaryGeneratedColumn,
9
+ RelationId,
10
+ UpdateDateColumn
11
+ } from 'typeorm'
12
+
13
+ import { User } from '@things-factory/auth-base'
14
+ import { Domain } from '@things-factory/shell'
15
+
16
+ @Entity()
17
+ @Index('ix_marketplace_channel_0 ', (marketplaceChannel: MarketplaceChannel) => [marketplaceChannel.domain, marketplaceChannel.name], { unique: true })
18
+ @ObjectType({ description: 'Entity for Marketplace Channel' })
19
+ export class MarketplaceChannel {
20
+ @PrimaryGeneratedColumn('uuid')
21
+ @Field(type => ID)
22
+ readonly id: string
23
+
24
+ @ManyToOne(type => Domain)
25
+ @Field({ nullable: true })
26
+ domain?: Domain
27
+
28
+ @RelationId((marketplaceChannel: MarketplaceChannel) => marketplaceChannel.domain)
29
+ domainId?: string
30
+
31
+ @Column()
32
+ @Field()
33
+ name: string
34
+
35
+ @Column()
36
+ @Field()
37
+ channelCode: string
38
+
39
+ @Column()
40
+ @Field()
41
+ channelId: string
42
+
43
+ @Column({ default: true })
44
+ @Field()
45
+ isActive: boolean
46
+
47
+ @CreateDateColumn()
48
+ @Field({ nullable: true })
49
+ createdAt?: Date
50
+
51
+ @UpdateDateColumn()
52
+ @Field({ nullable: true })
53
+ updatedAt?: Date
54
+
55
+ @ManyToOne(type => User, { nullable: true })
56
+ @Field({ nullable: true })
57
+ creator?: User
58
+
59
+ @RelationId((marketplaceChannel: MarketplaceChannel) => marketplaceChannel.creator)
60
+ creatorId?: string
61
+
62
+ @ManyToOne(type => User, { nullable: true })
63
+ @Field({ nullable: true })
64
+ updater?: User
65
+
66
+ @RelationId((marketplaceChannel: MarketplaceChannel) => marketplaceChannel.updater)
67
+ updaterId?: string
68
+ }