@things-factory/integration-sellercraft 4.1.35 → 4.2.1
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.
- package/dist-server/constants/order-status-mapping.js +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js +17 -21
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +2 -2
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +12 -18
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
- package/dist-server/routers/sellercraft-router.js +6 -6
- package/dist-server/routers/sellercraft-router.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +182 -20
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +36 -16
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
- package/package.json +15 -15
- package/server/constants/order-status-mapping.ts +1 -1
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.ts +18 -22
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +3 -3
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +18 -18
- package/server/routers/sellercraft-router.ts +10 -22
- package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +187 -32
- package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +50 -46
@@ -41,13 +41,14 @@ export class MarketplaceChannelOrderMutation {
|
|
41
41
|
accessKey: shops[j].credential.consumer_key,
|
42
42
|
accessSecret: shops[j].credential.consumer_secret,
|
43
43
|
storeURL: shops[j].credential.store_url,
|
44
|
-
platform: channels[i].name
|
44
|
+
platform: channels[i].name,
|
45
|
+
accessToken: shops[j].credential.access_token // Magento+
|
45
46
|
}
|
46
47
|
|
47
48
|
// let countryCode = shops[j].country_code
|
48
49
|
// let channelCode = shops[j].org_prefix
|
49
|
-
let organisationId = shops[j].
|
50
|
-
let channelShopId = shops[j].
|
50
|
+
let organisationId = shops[j].account_id
|
51
|
+
let channelShopId = shops[j].channel_shop_id
|
51
52
|
|
52
53
|
const orderReq = {
|
53
54
|
fromDate: fromDate,
|
@@ -80,7 +81,7 @@ export class MarketplaceChannelOrderMutation {
|
|
80
81
|
country: billCountry,
|
81
82
|
phone: billPhone1,
|
82
83
|
phone_2: billPhone2
|
83
|
-
} = order
|
84
|
+
} = order?.billing
|
84
85
|
|
85
86
|
let {
|
86
87
|
first_name: shipFirstName,
|
@@ -98,15 +99,7 @@ export class MarketplaceChannelOrderMutation {
|
|
98
99
|
} = order.shipping
|
99
100
|
|
100
101
|
let orderItems = order.orderItems.map(item => {
|
101
|
-
let {
|
102
|
-
name: id,
|
103
|
-
variationId: variationId,
|
104
|
-
slaExpiresAt,
|
105
|
-
total,
|
106
|
-
totalTax,
|
107
|
-
subtotal,
|
108
|
-
subtotalTax
|
109
|
-
} = item
|
102
|
+
let { name: id, variationId: variationId, slaExpiresAt, total, totalTax, subtotal, subtotalTax, qty } = item
|
110
103
|
|
111
104
|
return {
|
112
105
|
id,
|
@@ -115,18 +108,159 @@ export class MarketplaceChannelOrderMutation {
|
|
115
108
|
createdAt: order.orderCreatedAt,
|
116
109
|
updatedAt: order.orderUpdatedAt,
|
117
110
|
charges: [
|
111
|
+
{
|
112
|
+
name: 'CHARGES_MARKETING',
|
113
|
+
grossAmount: 0,
|
114
|
+
nettAmount: 0
|
115
|
+
},
|
116
|
+
{
|
117
|
+
name: 'CLAIMS_DAMAGE',
|
118
|
+
grossAmount: 0,
|
119
|
+
nettAmount: 0
|
120
|
+
},
|
121
|
+
{
|
122
|
+
name: 'CLAIMS_LOST',
|
123
|
+
grossAmount: 0,
|
124
|
+
nettAmount: 0
|
125
|
+
},
|
126
|
+
{
|
127
|
+
name: 'COMMISSION_PLATFORM',
|
128
|
+
grossAmount: 0,
|
129
|
+
nettAmount: 0
|
130
|
+
},
|
131
|
+
{
|
132
|
+
name: 'DEPOSIT_PRESALE',
|
133
|
+
grossAmount: 0,
|
134
|
+
nettAmount: 0
|
135
|
+
},
|
136
|
+
{
|
137
|
+
name: 'FEE_MISCELLANEOUS',
|
138
|
+
grossAmount: 0,
|
139
|
+
nettAmount: 0
|
140
|
+
},
|
141
|
+
{
|
142
|
+
name: 'FEE_TRANSACTION',
|
143
|
+
grossAmount: 0,
|
144
|
+
nettAmount: 0
|
145
|
+
},
|
118
146
|
{
|
119
147
|
name: 'PRICE_NORMAL_SELLING',
|
120
148
|
grossAmount: total,
|
121
149
|
nettAmount: subtotal
|
122
150
|
},
|
151
|
+
{
|
152
|
+
name: 'PRICE_RECOMMENDED_RETAIL',
|
153
|
+
grossAmount: 0,
|
154
|
+
nettAmount: 0
|
155
|
+
},
|
156
|
+
{
|
157
|
+
name: 'PROMOTIONS_CUSTOMER_RECEIVED',
|
158
|
+
grossAmount: 0,
|
159
|
+
nettAmount: 0
|
160
|
+
},
|
161
|
+
{
|
162
|
+
name: 'PROMOTIONS_REBATE_PLATFORM',
|
163
|
+
grossAmount: 0,
|
164
|
+
nettAmount: 0
|
165
|
+
},
|
166
|
+
{
|
167
|
+
name: 'PROMOTIONS_REBATE_SELLER',
|
168
|
+
grossAmount: 0,
|
169
|
+
nettAmount: 0
|
170
|
+
},
|
171
|
+
{
|
172
|
+
name: 'REVERSAL_CHARGES_MARKETING',
|
173
|
+
grossAmount: 0,
|
174
|
+
nettAmount: 0
|
175
|
+
},
|
176
|
+
{
|
177
|
+
name: 'REVERSAL_COMMISSION',
|
178
|
+
grossAmount: 0,
|
179
|
+
nettAmount: 0
|
180
|
+
},
|
181
|
+
{
|
182
|
+
name: 'REVERSAL_FEE_MISCELLANEOUS',
|
183
|
+
grossAmount: 0,
|
184
|
+
nettAmount: 0
|
185
|
+
},
|
186
|
+
{
|
187
|
+
name: 'REVERSAL_PROMOTIONS_CUSTOMER_RECEIVED',
|
188
|
+
grossAmount: 0,
|
189
|
+
nettAmount: 0
|
190
|
+
},
|
191
|
+
{
|
192
|
+
name: 'REVERSAL_SELLER_RETURN_REFUND_AMOUNT',
|
193
|
+
grossAmount: 0,
|
194
|
+
nettAmount: 0
|
195
|
+
},
|
196
|
+
{
|
197
|
+
name: 'REVERSAL_SHIPPING_CUSTOMER_PAID',
|
198
|
+
grossAmount: 0,
|
199
|
+
nettAmount: 0
|
200
|
+
},
|
201
|
+
{
|
202
|
+
name: 'REVERSAL_SHIPPING_REBATE_PLATFORM',
|
203
|
+
grossAmount: 0,
|
204
|
+
nettAmount: 0
|
205
|
+
},
|
206
|
+
{
|
207
|
+
name: 'REVERSAL_SHIPPING_SELLER_PAID',
|
208
|
+
grossAmount: 0,
|
209
|
+
nettAmount: 0
|
210
|
+
},
|
211
|
+
{
|
212
|
+
name: 'SHIPPING_COST_TOTAL',
|
213
|
+
grossAmount: 0,
|
214
|
+
nettAmount: 0
|
215
|
+
},
|
216
|
+
{
|
217
|
+
name: 'SHIPPING_CUSTOMER_PAID',
|
218
|
+
grossAmount: 0,
|
219
|
+
nettAmount: 0
|
220
|
+
},
|
221
|
+
{
|
222
|
+
name: 'SHIPPING_REBATE_PLATFORM',
|
223
|
+
grossAmount: 0,
|
224
|
+
nettAmount: 0
|
225
|
+
},
|
226
|
+
{
|
227
|
+
name: 'SHIPPING_SELLER_PAID',
|
228
|
+
grossAmount: 0,
|
229
|
+
nettAmount: 0
|
230
|
+
},
|
123
231
|
{
|
124
232
|
name: 'TAXES',
|
125
233
|
grossAmount: totalTax,
|
126
234
|
nettAmount: subtotalTax
|
235
|
+
},
|
236
|
+
{
|
237
|
+
name: 'VOUCHERS_CUSTOMER_RECEIVED',
|
238
|
+
grossAmount: 0,
|
239
|
+
nettAmount: 0
|
240
|
+
},
|
241
|
+
{
|
242
|
+
name: 'VOUCHERS_REBATE_PLATFORM',
|
243
|
+
grossAmount: 0,
|
244
|
+
nettAmount: 0
|
245
|
+
},
|
246
|
+
{
|
247
|
+
name: 'VOUCHERS_REBATE_SELLER',
|
248
|
+
grossAmount: 0,
|
249
|
+
nettAmount: 0
|
127
250
|
}
|
128
251
|
],
|
129
|
-
slaExpiresAt
|
252
|
+
slaExpiresAt,
|
253
|
+
qty
|
254
|
+
}
|
255
|
+
})
|
256
|
+
|
257
|
+
let mappedOrderItems = []
|
258
|
+
orderItems.map(oi => {
|
259
|
+
for (let i = 0; i < oi.qty; i++) {
|
260
|
+
mappedOrderItems.push({
|
261
|
+
...oi,
|
262
|
+
id: `${oi.id}-${i + 1}`
|
263
|
+
})
|
130
264
|
}
|
131
265
|
})
|
132
266
|
|
@@ -138,19 +272,19 @@ export class MarketplaceChannelOrderMutation {
|
|
138
272
|
id,
|
139
273
|
billFirstName,
|
140
274
|
billLastName,
|
141
|
-
billAddress1,
|
142
|
-
billAddress2,
|
143
|
-
billAddress3,
|
144
|
-
billAddress4,
|
145
|
-
billAddress5,
|
146
|
-
billCity,
|
147
|
-
billPostalCode,
|
148
|
-
billCountry,
|
149
|
-
billPhone1,
|
150
|
-
billPhone2,
|
275
|
+
billAddress1: billAddress1.toString() || shipAddress1.toString(),
|
276
|
+
billAddress2: billAddress2 || shipAddress2,
|
277
|
+
billAddress3: billAddress3 || shipAddress3,
|
278
|
+
billAddress4: billAddress4 || shipAddress4,
|
279
|
+
billAddress5: billAddress5 || shipAddress5,
|
280
|
+
billCity: billCity || shipCity,
|
281
|
+
billPostalCode: billPostalCode || shipPostalCode,
|
282
|
+
billCountry: billCountry || shipCountry,
|
283
|
+
billPhone1: billPhone1 || shipPhone1,
|
284
|
+
billPhone2: billPhone2 || shipPhone2,
|
151
285
|
shipFirstName,
|
152
286
|
shipLastName,
|
153
|
-
shipAddress1,
|
287
|
+
shipAddress1: shipAddress1.toString(),
|
154
288
|
shipAddress2,
|
155
289
|
shipAddress3,
|
156
290
|
shipAddress4,
|
@@ -160,19 +294,16 @@ export class MarketplaceChannelOrderMutation {
|
|
160
294
|
shipCountry,
|
161
295
|
shipPhone1,
|
162
296
|
shipPhone2,
|
163
|
-
|
297
|
+
mappedOrderItems,
|
164
298
|
channelShopId,
|
165
299
|
organisationId,
|
166
|
-
status
|
300
|
+
status,
|
301
|
+
charges: getOrderCharges(mappedOrderItems)
|
167
302
|
}
|
168
|
-
|
169
303
|
})
|
170
304
|
|
171
305
|
if (mappedOrderResult.length > 0) {
|
172
|
-
|
173
|
-
sellercraftStore,
|
174
|
-
{ orders: mappedOrderResult }
|
175
|
-
)
|
306
|
+
await SellercraftChannelIntegrationAPI.ingestChannelOrder(sellercraftStore, { orders: mappedOrderResult })
|
176
307
|
}
|
177
308
|
}
|
178
309
|
|
@@ -180,3 +311,27 @@ export class MarketplaceChannelOrderMutation {
|
|
180
311
|
}
|
181
312
|
}
|
182
313
|
}
|
314
|
+
|
315
|
+
function getOrderCharges(mappedOrderItems) {
|
316
|
+
let chargesList = []
|
317
|
+
|
318
|
+
for (let i = 0; i < mappedOrderItems.length; i++) {
|
319
|
+
for (let j = 0; j < mappedOrderItems[i].charges.length; j++) {
|
320
|
+
let charge = mappedOrderItems[i].charges[j]
|
321
|
+
let foundCharge = chargesList.find(cl => cl.name == charge.name)
|
322
|
+
if (foundCharge) {
|
323
|
+
foundCharge.grossAmount = foundCharge.grossAmount + charge.grossAmount
|
324
|
+
foundCharge.nettAmount = foundCharge.nettAmount + charge.nettAmount
|
325
|
+
chargesList = chargesList.filter(cl => cl.name != charge.name)
|
326
|
+
} else {
|
327
|
+
foundCharge = {
|
328
|
+
name: charge.name,
|
329
|
+
grossAmount: charge.grossAmount,
|
330
|
+
nettAmount: charge.nettAmount
|
331
|
+
}
|
332
|
+
}
|
333
|
+
chargesList.push(foundCharge)
|
334
|
+
}
|
335
|
+
}
|
336
|
+
return chargesList
|
337
|
+
}
|
@@ -10,9 +10,7 @@ import { SellercraftChannelIntegrationAPI } from '../../controllers/sellercraft-
|
|
10
10
|
@Resolver()
|
11
11
|
export class MarketplaceChannelProductMutation {
|
12
12
|
@Mutation(returns => Boolean)
|
13
|
-
async syncAllMarketplaceChannelProducts(
|
14
|
-
@Ctx() context: any
|
15
|
-
): Promise<boolean> {
|
13
|
+
async syncAllMarketplaceChannelProducts(@Ctx() context: any): Promise<boolean> {
|
16
14
|
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
17
15
|
const { tokenCraftApiKey: apiKey, getShopsTokenCraftUrl } = sellercraftChannelIntegrationConfig
|
18
16
|
|
@@ -39,31 +37,33 @@ export class MarketplaceChannelProductMutation {
|
|
39
37
|
accessKey: shops[j].credential.consumer_key,
|
40
38
|
accessSecret: shops[j].credential.consumer_secret,
|
41
39
|
storeURL: shops[j].credential.store_url,
|
42
|
-
platform: channels[i].name
|
40
|
+
platform: channels[i].name,
|
41
|
+
accessToken: shops[j].credential.access_token // Magento+
|
43
42
|
}
|
44
43
|
|
45
44
|
let countryCode = shops[j].country_code
|
46
45
|
let channelCode = shops[j].org_prefix
|
47
|
-
let organisationId = shops[j].
|
48
|
-
let channelShopId = shops[j].
|
46
|
+
let organisationId = shops[j].account_id
|
47
|
+
let channelShopId = shops[j].channel_shop_id
|
49
48
|
|
50
49
|
var sellercraftStore = { ...store, platform: 'sellercraftChannelIntegration' }
|
51
50
|
|
52
|
-
const productResult =
|
51
|
+
const productResult = []
|
52
|
+
let totalPages: number = 1
|
53
|
+
var limit: number = 50
|
54
|
+
|
55
|
+
for (let page = 0; page < totalPages; page++) {
|
56
|
+
const { results, total } = await StoreAPI.getStoreProducts(store, {
|
57
|
+
pagination: { page, limit }
|
58
|
+
})
|
59
|
+
totalPages = Math.ceil(total / limit)
|
60
|
+
productResult.push(...results)
|
61
|
+
}
|
53
62
|
|
54
63
|
const categoryResult = await StoreAPI.getStoreProductCategories(store, {})
|
55
64
|
|
56
|
-
let mappedProducts = productResult.
|
57
|
-
let {
|
58
|
-
categoryId,
|
59
|
-
itemId: productId,
|
60
|
-
name,
|
61
|
-
brand,
|
62
|
-
isVerified,
|
63
|
-
images,
|
64
|
-
attributes,
|
65
|
-
variations
|
66
|
-
} = item
|
65
|
+
let mappedProducts = productResult.map(item => {
|
66
|
+
let { categoryId, itemId: productId, name, brand, isVerified, images, attributes, variations } = item
|
67
67
|
|
68
68
|
variations = variations.map(variation => {
|
69
69
|
let {
|
@@ -94,23 +94,27 @@ export class MarketplaceChannelProductMutation {
|
|
94
94
|
stockReported,
|
95
95
|
fullPrice,
|
96
96
|
priceDiscounted,
|
97
|
-
inventoryProducts: [
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
97
|
+
inventoryProducts: [
|
98
|
+
{
|
99
|
+
qty: stockReported,
|
100
|
+
name: `${name} - ${variationSku}`,
|
101
|
+
sku: variationSku,
|
102
|
+
productVersions: [
|
103
|
+
{
|
104
|
+
label: 'Default',
|
105
|
+
packageLengthMM: length,
|
106
|
+
packageWidthMM: width,
|
107
|
+
packageHeightMM: height,
|
108
|
+
packageWeightGram: weight,
|
109
|
+
qty: 1
|
110
|
+
}
|
111
|
+
]
|
112
|
+
}
|
113
|
+
]
|
110
114
|
}
|
111
115
|
})
|
112
116
|
|
113
|
-
images = images
|
117
|
+
images = images?.map(image => {
|
114
118
|
return {
|
115
119
|
url: image
|
116
120
|
}
|
@@ -132,13 +136,8 @@ export class MarketplaceChannelProductMutation {
|
|
132
136
|
}
|
133
137
|
})
|
134
138
|
|
135
|
-
let mappedCategories = categoryResult.results.map(
|
136
|
-
let {
|
137
|
-
id: categoryId,
|
138
|
-
name: categoryName,
|
139
|
-
parent,
|
140
|
-
isActive
|
141
|
-
} = category
|
139
|
+
let mappedCategories = categoryResult.results.map(category => {
|
140
|
+
let { id: categoryId, name: categoryName, parent, isActive } = category
|
142
141
|
|
143
142
|
return {
|
144
143
|
categoryId,
|
@@ -147,18 +146,23 @@ export class MarketplaceChannelProductMutation {
|
|
147
146
|
isLeaf: parent == 0 ? false : true,
|
148
147
|
isActive: isActive || true,
|
149
148
|
channelCode,
|
150
|
-
countryCode
|
149
|
+
countryCode,
|
150
|
+
childrenCategories: []
|
151
|
+
}
|
152
|
+
})
|
153
|
+
|
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)
|
151
157
|
}
|
158
|
+
return category
|
152
159
|
})
|
153
160
|
|
154
|
-
|
155
|
-
|
161
|
+
await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
|
162
|
+
categories: mappedCategories
|
156
163
|
})
|
157
164
|
|
158
|
-
|
159
|
-
|
160
|
-
const ingestProduct = await SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, { products: mappedProducts })
|
161
|
-
|
165
|
+
await SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, { products: mappedProducts })
|
162
166
|
}
|
163
167
|
|
164
168
|
return true
|