@things-factory/marketplace-base 4.1.4 → 4.1.12
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/entities/marketplace-order-shipping.js +4 -0
- package/dist-server/entities/marketplace-order-shipping.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/auto-initialise-logistics-by-batch.js +6 -6
- package/dist-server/graphql/resolvers/marketplace-order/auto-initialise-logistics-by-batch.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/auto-update-order-ready-to-ship.js +4 -3
- package/dist-server/graphql/resolvers/marketplace-order/auto-update-order-ready-to-ship.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/generate-marketplace-order.js +11 -5
- package/dist-server/graphql/resolvers/marketplace-order/generate-marketplace-order.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/initialise-logistics-by-batch.js +2 -0
- package/dist-server/graphql/resolvers/marketplace-order/initialise-logistics-by-batch.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.js +98 -25
- package/dist-server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-order.js +30 -13
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-order.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/update-order-ready-to-ship.js +57 -33
- package/dist-server/graphql/resolvers/marketplace-order/update-order-ready-to-ship.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order-shipping/marketplace-order-shippings.js +2 -1
- package/dist-server/graphql/resolvers/marketplace-order-shipping/marketplace-order-shippings.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-report/marketplace-sales-report.js +2 -1
- package/dist-server/graphql/resolvers/marketplace-report/marketplace-sales-report.js.map +1 -1
- package/dist-server/graphql/types/marketplace-order/index.js +8 -7
- package/dist-server/graphql/types/marketplace-order/index.js.map +1 -1
- package/dist-server/graphql/types/marketplace-order/logistics-info.js +1 -0
- package/dist-server/graphql/types/marketplace-order/logistics-info.js.map +1 -1
- package/dist-server/graphql/types/marketplace-order-shipping/marketplace-order-shipping.js +1 -0
- package/dist-server/graphql/types/marketplace-order-shipping/marketplace-order-shipping.js.map +1 -1
- package/package.json +6 -6
- package/server/entities/marketplace-order-shipping.ts +3 -0
- package/server/graphql/resolvers/marketplace-order/auto-initialise-logistics-by-batch.ts +6 -6
- package/server/graphql/resolvers/marketplace-order/auto-update-order-ready-to-ship.ts +4 -3
- package/server/graphql/resolvers/marketplace-order/generate-marketplace-order.ts +17 -7
- package/server/graphql/resolvers/marketplace-order/initialise-logistics-by-batch.ts +2 -0
- package/server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.ts +111 -27
- package/server/graphql/resolvers/marketplace-order/sync-marketplace-order.ts +30 -11
- package/server/graphql/resolvers/marketplace-order/update-order-ready-to-ship.ts +66 -37
- package/server/graphql/resolvers/marketplace-order-shipping/marketplace-order-shippings.ts +2 -1
- package/server/graphql/resolvers/marketplace-report/marketplace-sales-report.ts +2 -1
- package/server/graphql/types/marketplace-order/index.ts +8 -7
- package/server/graphql/types/marketplace-order/logistics-info.ts +1 -0
- package/server/graphql/types/marketplace-order-shipping/marketplace-order-shipping.ts +1 -0
|
@@ -50,7 +50,7 @@ export async function generateMarketplaceOrder(
|
|
|
50
50
|
const itemCount: number = marketplaceOrder.marketplaceOrderItems?.length
|
|
51
51
|
|
|
52
52
|
newMarketplaceOrder.name = marketplaceOrder?.name ? marketplaceOrder.name : NoGenerator.marketplaceOrder()
|
|
53
|
-
|
|
53
|
+
newMarketplaceOrder.itemCount = itemCount
|
|
54
54
|
newMarketplaceOrder.marketplaceStore = marketplaceStore
|
|
55
55
|
newMarketplaceOrder.domain = domain
|
|
56
56
|
newMarketplaceOrder.creator = user
|
|
@@ -108,19 +108,28 @@ export async function generateMarketplaceOrder(
|
|
|
108
108
|
})
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
let
|
|
112
|
-
.getRepository(
|
|
113
|
-
.
|
|
114
|
-
where: { domain: marketplaceStore.domain,
|
|
111
|
+
let existingMarketplaceOrderItem: MarketplaceOrderItemEntity = await tx
|
|
112
|
+
.getRepository(MarketplaceOrderItemEntity)
|
|
113
|
+
.findOne({
|
|
114
|
+
where: { domain: marketplaceStore.domain, name: orderItem.orderItemId }
|
|
115
115
|
})
|
|
116
116
|
|
|
117
|
+
let existingMarketplaceOrderShippingItems: MarketplaceOrderShippingItemEntity[] = []
|
|
118
|
+
|
|
119
|
+
if (existingMarketplaceOrderItem) {
|
|
120
|
+
existingMarketplaceOrderShippingItems = await tx.getRepository(MarketplaceOrderShippingItemEntity).find({
|
|
121
|
+
where: { domain: marketplaceStore.domain, marketplaceOrderItem: existingMarketplaceOrderItem }
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
117
125
|
if (existingMarketplaceOrderShippingItems && existingMarketplaceOrderShippingItems?.length) {
|
|
118
126
|
} else {
|
|
119
127
|
if (productBundle) {
|
|
120
128
|
const productBundleSettings: ProductBundleSetting[] = productBundle.productBundleSettings
|
|
121
129
|
let marketplaceOrderShippingItems: MarketplaceOrderShippingItemEntity[] = []
|
|
122
130
|
productBundleSettings.map(productBundleSetting => {
|
|
123
|
-
let marketplaceOrderShippingItem: MarketplaceOrderShippingItemEntity =
|
|
131
|
+
let marketplaceOrderShippingItem: MarketplaceOrderShippingItemEntity =
|
|
132
|
+
new MarketplaceOrderShippingItemEntity()
|
|
124
133
|
marketplaceOrderShippingItem.name = uuid()
|
|
125
134
|
marketplaceOrderShippingItem.qty = marketplaceOrderItem.qty * productBundleSetting.bundleQty
|
|
126
135
|
marketplaceOrderShippingItem.domain = marketplaceStore.domain
|
|
@@ -133,7 +142,8 @@ export async function generateMarketplaceOrder(
|
|
|
133
142
|
|
|
134
143
|
await tx.getRepository(MarketplaceOrderShippingItemEntity).save(marketplaceOrderShippingItems)
|
|
135
144
|
} else {
|
|
136
|
-
let marketplaceOrderShippingItem: MarketplaceOrderShippingItemEntity =
|
|
145
|
+
let marketplaceOrderShippingItem: MarketplaceOrderShippingItemEntity =
|
|
146
|
+
new MarketplaceOrderShippingItemEntity()
|
|
137
147
|
marketplaceOrderShippingItem.name = uuid()
|
|
138
148
|
marketplaceOrderShippingItem.qty = marketplaceOrderItem.qty
|
|
139
149
|
marketplaceOrderShippingItem.domain = marketplaceStore.domain
|
|
@@ -27,6 +27,8 @@ export const initialiseLogisticsByBatch = {
|
|
|
27
27
|
marketplaceOrderShipping.trackingNo = patch?.trackingNo
|
|
28
28
|
marketplaceOrderShipping.transporter = patch?.shippingProvider
|
|
29
29
|
marketplaceOrderShipping.ownTransporter = patch?.shippingProvider
|
|
30
|
+
marketplaceOrderShipping.ownTrackingNo = patch.ownTrackingNo || patch?.trackingNo
|
|
31
|
+
marketplaceOrderShipping.trackingUrl = patch?.trackingUrl
|
|
30
32
|
await tx.getRepository(MarketplaceOrderShipping).save(marketplaceOrderShipping)
|
|
31
33
|
|
|
32
34
|
marketplaceOrder.shippingProvider = patch?.shippingProvider
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getRepository } from 'typeorm'
|
|
1
|
+
import { getRepository, IsNull } from 'typeorm'
|
|
2
|
+
import uuid from 'uuid/v4'
|
|
2
3
|
|
|
3
4
|
import { User } from '@things-factory/auth-base'
|
|
4
5
|
import { Bizplace, getCustomerBizplaces } from '@things-factory/biz-base'
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
MarketplaceOrder,
|
|
12
13
|
MarketplaceOrderItem,
|
|
13
14
|
MarketplaceOrderShipping,
|
|
15
|
+
MarketplaceOrderShippingItem,
|
|
14
16
|
MarketplaceProductVariation
|
|
15
17
|
} from '../../../entities'
|
|
16
18
|
import { NoGenerator } from '../../../utils'
|
|
@@ -28,9 +30,8 @@ export const syncAllMarketplaceOrder = {
|
|
|
28
30
|
if (marketplaceStores?.length === 0) throw new Error('No active marketplace store')
|
|
29
31
|
let whiteListStores: MarketplaceStore[] = marketplaceStores
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (blackListStores && blackListStores?.length) {
|
|
33
|
+
if (blackListStores) {
|
|
34
|
+
blackListStores = blackListStores.split(',')
|
|
34
35
|
whiteListStores = marketplaceStores.filter(store => blackListStores.indexOf(store.name) < 0)
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -117,8 +118,9 @@ export const syncAllMarketplaceOrder = {
|
|
|
117
118
|
'domain',
|
|
118
119
|
'fulfillmentCenter',
|
|
119
120
|
'marketplaceOrderItems',
|
|
120
|
-
'marketplaceOrderItems.
|
|
121
|
-
'marketplaceOrderItems.marketplaceOrderShipping'
|
|
121
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
122
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping',
|
|
123
|
+
'marketplaceOrderItems.marketplaceProductVariation'
|
|
122
124
|
]
|
|
123
125
|
})
|
|
124
126
|
|
|
@@ -194,7 +196,9 @@ export const syncAllMarketplaceOrder = {
|
|
|
194
196
|
let patch = {
|
|
195
197
|
id: releaseOrder.id,
|
|
196
198
|
marketplaceOrderStatus: marketplaceOrder.status,
|
|
197
|
-
trackingNo: foundMarketplaceOrderShipping?.trackingNo
|
|
199
|
+
trackingNo: foundMarketplaceOrderShipping?.trackingNo == '[]'
|
|
200
|
+
? foundMarketplaceOrderShipping.ownTrackingNo :
|
|
201
|
+
foundMarketplaceOrderShipping?.trackingNo
|
|
198
202
|
? foundMarketplaceOrderShipping.trackingNo
|
|
199
203
|
: foundMarketplaceOrderShipping.ownTrackingNo,
|
|
200
204
|
transporter: dropPickProvider ? dropPickProvider : marketplaceOrder.shippingProvider
|
|
@@ -216,7 +220,9 @@ export const syncAllMarketplaceOrder = {
|
|
|
216
220
|
let patch = {
|
|
217
221
|
id: releaseOrder.id,
|
|
218
222
|
marketplaceOrderStatus: marketplaceOrder.status,
|
|
219
|
-
trackingNo: foundMarketplaceOrderShipping?.trackingNo
|
|
223
|
+
trackingNo: foundMarketplaceOrderShipping?.trackingNo == '[]'
|
|
224
|
+
? foundMarketplaceOrderShipping.ownTrackingNo :
|
|
225
|
+
foundMarketplaceOrderShipping?.trackingNo
|
|
220
226
|
? foundMarketplaceOrderShipping.trackingNo
|
|
221
227
|
: foundMarketplaceOrderShipping.ownTrackingNo,
|
|
222
228
|
transporter: dropPickProvider ? dropPickProvider : marketplaceOrder.shippingProvider
|
|
@@ -236,7 +242,7 @@ export const syncAllMarketplaceOrder = {
|
|
|
236
242
|
})
|
|
237
243
|
|
|
238
244
|
if (releaseOrders?.length) {
|
|
239
|
-
for (
|
|
245
|
+
for (let a = 0; a < releaseOrders.length; a++) {
|
|
240
246
|
const releaseOrderId: string = releaseOrders[a].id
|
|
241
247
|
await FulfillmentAPI.cancelReleaseOrder(fulfillmentCenter, {
|
|
242
248
|
customerBizplaceId,
|
|
@@ -322,10 +328,12 @@ export const syncAllMarketplaceOrder = {
|
|
|
322
328
|
attentionTo: orderShipping.attentionTo,
|
|
323
329
|
city: orderShipping.city,
|
|
324
330
|
country: orderShipping.country,
|
|
331
|
+
state: orderShipping?.state,
|
|
325
332
|
postCode: orderShipping.postCode,
|
|
326
333
|
phone1: orderShipping.phone1,
|
|
327
334
|
phone2: orderShipping.phone2,
|
|
328
|
-
|
|
335
|
+
email: orderShipping?.email,
|
|
336
|
+
trackingNo: order?.trackingNo,
|
|
329
337
|
shippingFee: orderShipping.shippingFee,
|
|
330
338
|
actualShippingFee: orderShipping.actualShippingFee,
|
|
331
339
|
marketplaceShippingFeeVoucher: orderShipping.marketplaceShippingFeeVoucher,
|
|
@@ -346,7 +354,11 @@ export const syncAllMarketplaceOrder = {
|
|
|
346
354
|
marketplaceOrderShipping = {
|
|
347
355
|
...existingOrderShipping,
|
|
348
356
|
...marketplaceOrderShipping,
|
|
349
|
-
trackingNo:
|
|
357
|
+
trackingNo: marketplaceOrderShipping?.trackingNo
|
|
358
|
+
? marketplaceOrderShipping.trackingNo
|
|
359
|
+
: existingOrderShipping?.trackingNo
|
|
360
|
+
? existingOrderShipping.trackingNo
|
|
361
|
+
: marketplaceOrderShipping.trackingNo,
|
|
350
362
|
updater: user
|
|
351
363
|
}
|
|
352
364
|
|
|
@@ -366,10 +378,15 @@ export const syncAllMarketplaceOrder = {
|
|
|
366
378
|
let foundVariations = []
|
|
367
379
|
for (var j = 0; j < order.orderItems.length; j++) {
|
|
368
380
|
var item = order.orderItems[j]
|
|
369
|
-
let
|
|
370
|
-
where: { domain: marketplaceStore.domain, variationId: item.variationId }
|
|
381
|
+
let foundVariationsQuery = await getRepository(MarketplaceProductVariation).find({
|
|
382
|
+
where: { domain: marketplaceStore.domain, variationId: item.variationId },
|
|
383
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
371
384
|
})
|
|
372
385
|
|
|
386
|
+
let foundVariation = foundVariationsQuery.filter(
|
|
387
|
+
fv => fv.marketplaceProduct.marketplaceStore.id == marketplaceStore.id
|
|
388
|
+
)[0]
|
|
389
|
+
|
|
373
390
|
if (foundVariation) {
|
|
374
391
|
foundVariations.push(foundVariation)
|
|
375
392
|
}
|
|
@@ -380,7 +397,8 @@ export const syncAllMarketplaceOrder = {
|
|
|
380
397
|
name: item.variationName,
|
|
381
398
|
variationSku: item.variationSku,
|
|
382
399
|
channelSku: item.sku,
|
|
383
|
-
status: 'INACTIVE'
|
|
400
|
+
status: 'INACTIVE',
|
|
401
|
+
domain: marketplaceStore.domain
|
|
384
402
|
}
|
|
385
403
|
|
|
386
404
|
await getRepository(MarketplaceProductVariation).save(newVariation)
|
|
@@ -395,8 +413,8 @@ export const syncAllMarketplaceOrder = {
|
|
|
395
413
|
marketplaceOrderItem.status = marketplaceOrder.status
|
|
396
414
|
marketplaceOrderItem.docRefNo = item.docRefNo
|
|
397
415
|
marketplaceOrderItem.marketplaceProductVariation = foundVariation
|
|
398
|
-
marketplaceOrderItem.marketplaceOrder = marketplaceOrder
|
|
399
416
|
marketplaceOrderItem.trackingCode = order.trackingNo
|
|
417
|
+
marketplaceOrderItem.marketplaceOrder = marketplaceOrder
|
|
400
418
|
marketplaceOrderItem.originalPrice = item.originalPrice
|
|
401
419
|
marketplaceOrderItem.discount = item.discount
|
|
402
420
|
marketplaceOrderItem.promotionId = item.promotionId
|
|
@@ -417,7 +435,7 @@ export const syncAllMarketplaceOrder = {
|
|
|
417
435
|
marketplaceOrderItem.promotionalChargesFlexiCombo = item.promotionalChargesFlexiCombo
|
|
418
436
|
marketplaceOrderItem.autoShippingSubsidyMarketplace = item.autoShippingSubsidyMarketplace
|
|
419
437
|
marketplaceOrderItem.originalShippingFee = item.originalShippingFee
|
|
420
|
-
marketplaceOrderItem.taxAmount = item.
|
|
438
|
+
marketplaceOrderItem.taxAmount = item.taxAmount
|
|
421
439
|
|
|
422
440
|
marketplaceOrderItems.push({ ...marketplaceOrderItem })
|
|
423
441
|
|
|
@@ -426,10 +444,12 @@ export const syncAllMarketplaceOrder = {
|
|
|
426
444
|
}
|
|
427
445
|
|
|
428
446
|
if (existingMarketplaceOrder) {
|
|
447
|
+
let existingOrderItems: MarketplaceOrderItem[] = []
|
|
448
|
+
existingOrderItems = existingMarketplaceOrder.marketplaceOrderItems
|
|
449
|
+
|
|
450
|
+
existingOrderItems = await checkUpdateItemId(existingOrderItems, marketplaceOrderItems)
|
|
451
|
+
|
|
429
452
|
if (existingMarketplaceOrder.isSplitted) {
|
|
430
|
-
let existingOrderItems: MarketplaceOrderItem[] = []
|
|
431
|
-
existingOrderItems = existingMarketplaceOrder.marketplaceOrderItems
|
|
432
|
-
|
|
433
453
|
marketplaceOrderItems = existingOrderItems.filter(
|
|
434
454
|
itm => itm.name == item.name && itm.marketplaceProductVariation.variationId == item.variationId
|
|
435
455
|
)
|
|
@@ -437,14 +457,10 @@ export const syncAllMarketplaceOrder = {
|
|
|
437
457
|
return {
|
|
438
458
|
...marketplaceOrderitem,
|
|
439
459
|
status: order.status,
|
|
440
|
-
marketplaceProductVariation: foundVariation,
|
|
441
460
|
trackingCode: order.trackingNo
|
|
442
461
|
}
|
|
443
462
|
})
|
|
444
463
|
} else {
|
|
445
|
-
let existingOrderItems: MarketplaceOrderItem[] = []
|
|
446
|
-
existingOrderItems = existingMarketplaceOrder.marketplaceOrderItems
|
|
447
|
-
|
|
448
464
|
if (existingOrderItems.length > marketplaceOrderItems.length) {
|
|
449
465
|
let nonMatchedOrderItems = []
|
|
450
466
|
existingOrderItems.map(item => {
|
|
@@ -666,11 +682,10 @@ export const syncAllMarketplaceOrder = {
|
|
|
666
682
|
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
667
683
|
})
|
|
668
684
|
|
|
669
|
-
let item = order.orderItems.find(e => e.variationId == foundVariation.variationId)
|
|
670
685
|
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
671
686
|
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
672
687
|
)
|
|
673
|
-
|
|
688
|
+
let item = order.orderItems.find(e => e.variationId == foundVariation.variationId)
|
|
674
689
|
await Promise.all(
|
|
675
690
|
activeVariations.map(async variation => {
|
|
676
691
|
await calculateReserveQtyForBundle(variation, marketplaceOrder.domain, item.qty)
|
|
@@ -684,8 +699,6 @@ export const syncAllMarketplaceOrder = {
|
|
|
684
699
|
)
|
|
685
700
|
}
|
|
686
701
|
|
|
687
|
-
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
688
|
-
|
|
689
702
|
if (order?.orderShipping) {
|
|
690
703
|
savedMarketplaceOrderShipping.totalWeight = orderTotalWeight
|
|
691
704
|
savedMarketplaceOrderShipping = await getRepository(MarketplaceOrderShipping).save(
|
|
@@ -699,6 +712,62 @@ export const syncAllMarketplaceOrder = {
|
|
|
699
712
|
await getRepository(MarketplaceOrder).save(marketplaceOrder)
|
|
700
713
|
await getRepository(MarketplaceOrderItem).save(marketplaceOrderItems)
|
|
701
714
|
|
|
715
|
+
for (let i = 0; i < marketplaceOrderItems.length; i++) {
|
|
716
|
+
const marketplaceOrderItem: MarketplaceOrderItem = marketplaceOrderItems[i]
|
|
717
|
+
const marketplaceProductVariation: MarketplaceProductVariation =
|
|
718
|
+
marketplaceOrderItem.marketplaceProductVariation
|
|
719
|
+
let existingMarketplaceOrderShippingItems: MarketplaceOrderShippingItem[] = await getRepository(
|
|
720
|
+
MarketplaceOrderShippingItem
|
|
721
|
+
).find({
|
|
722
|
+
where: { domain: marketplaceStore.domain, marketplaceOrderItem }
|
|
723
|
+
})
|
|
724
|
+
|
|
725
|
+
let product: Product = await getRepository(Product).findOne({
|
|
726
|
+
where: { domain: marketplaceStore.domain, sku: marketplaceProductVariation.sku, deletedAt: IsNull() },
|
|
727
|
+
relations: ['productDetails']
|
|
728
|
+
})
|
|
729
|
+
|
|
730
|
+
let productBundle: ProductBundle
|
|
731
|
+
if (!product) {
|
|
732
|
+
productBundle = await getRepository(ProductBundle).findOne({
|
|
733
|
+
where: { domain: marketplaceStore.domain, sku: marketplaceProductVariation.sku },
|
|
734
|
+
relations: ['productBundleSettings', 'productBundleSettings.product']
|
|
735
|
+
})
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
if (existingMarketplaceOrderShippingItems && existingMarketplaceOrderShippingItems?.length) {
|
|
739
|
+
} else {
|
|
740
|
+
if (productBundle) {
|
|
741
|
+
const productBundleSettings: ProductBundleSetting[] = productBundle.productBundleSettings
|
|
742
|
+
let marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] = []
|
|
743
|
+
productBundleSettings.map(productBundleSetting => {
|
|
744
|
+
let marketplaceOrderShippingItem: MarketplaceOrderShippingItem =
|
|
745
|
+
new MarketplaceOrderShippingItem()
|
|
746
|
+
marketplaceOrderShippingItem.name = uuid()
|
|
747
|
+
marketplaceOrderShippingItem.qty = marketplaceOrderItem.qty * productBundleSetting.bundleQty
|
|
748
|
+
marketplaceOrderShippingItem.domain = marketplaceStore.domain
|
|
749
|
+
marketplaceOrderShippingItem.marketplaceOrderItem = marketplaceOrderItem
|
|
750
|
+
marketplaceOrderShippingItem.marketplaceOrderShipping = savedMarketplaceOrderShipping
|
|
751
|
+
marketplaceOrderShippingItem.product = productBundleSetting.product
|
|
752
|
+
|
|
753
|
+
marketplaceOrderShippingItems.push(marketplaceOrderShippingItem)
|
|
754
|
+
})
|
|
755
|
+
|
|
756
|
+
await getRepository(MarketplaceOrderShippingItem).save(marketplaceOrderShippingItems)
|
|
757
|
+
} else {
|
|
758
|
+
let marketplaceOrderShippingItem: MarketplaceOrderShippingItem = new MarketplaceOrderShippingItem()
|
|
759
|
+
marketplaceOrderShippingItem.name = uuid()
|
|
760
|
+
marketplaceOrderShippingItem.qty = marketplaceOrderItem.qty
|
|
761
|
+
marketplaceOrderShippingItem.domain = marketplaceStore.domain
|
|
762
|
+
marketplaceOrderShippingItem.marketplaceOrderItem = marketplaceOrderItem
|
|
763
|
+
marketplaceOrderShippingItem.marketplaceOrderShipping = savedMarketplaceOrderShipping
|
|
764
|
+
marketplaceOrderShippingItem.product = product ? product : null
|
|
765
|
+
|
|
766
|
+
await getRepository(MarketplaceOrderShippingItem).save(marketplaceOrderShippingItem)
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
702
771
|
if (m == marketplaceOrders.length - 1) {
|
|
703
772
|
lastOrderId = order.name
|
|
704
773
|
}
|
|
@@ -786,3 +855,18 @@ async function calculateReserveQtyForBundle(variation, domain, qty, operator = '
|
|
|
786
855
|
}
|
|
787
856
|
}
|
|
788
857
|
}
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
function checkUpdateItemId(existingOrderItems, marketplaceOrderItems) {
|
|
861
|
+
for (let item of marketplaceOrderItems) {
|
|
862
|
+
let existingItem = existingOrderItems.find(i => i.name == item.name)
|
|
863
|
+
|
|
864
|
+
if (!existingItem) {
|
|
865
|
+
let existingItemByVariation = existingOrderItems.find(i => i.marketplaceProductVariation.id == item.marketplaceProductVariation.id)
|
|
866
|
+
existingOrderItems = existingOrderItems.filter(i => i != existingItemByVariation)
|
|
867
|
+
existingItemByVariation.name = item.name
|
|
868
|
+
existingOrderItems.push(existingItemByVariation)
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
return existingOrderItems
|
|
872
|
+
}
|
|
@@ -176,7 +176,9 @@ export const syncMarketplaceOrder = {
|
|
|
176
176
|
let patch = {
|
|
177
177
|
id: releaseOrder.id,
|
|
178
178
|
marketplaceOrderStatus: marketplaceOrder.status,
|
|
179
|
-
trackingNo: foundMarketplaceOrderShipping?.trackingNo
|
|
179
|
+
trackingNo: foundMarketplaceOrderShipping?.trackingNo == '[]'
|
|
180
|
+
? foundMarketplaceOrderShipping.ownTrackingNo :
|
|
181
|
+
foundMarketplaceOrderShipping?.trackingNo
|
|
180
182
|
? foundMarketplaceOrderShipping.trackingNo
|
|
181
183
|
: foundMarketplaceOrderShipping.ownTrackingNo,
|
|
182
184
|
transporter: dropPickProvider ? dropPickProvider : marketplaceOrder.shippingProvider
|
|
@@ -198,7 +200,9 @@ export const syncMarketplaceOrder = {
|
|
|
198
200
|
let patch = {
|
|
199
201
|
id: releaseOrder.id,
|
|
200
202
|
marketplaceOrderStatus: marketplaceOrder.status,
|
|
201
|
-
trackingNo: foundMarketplaceOrderShipping?.trackingNo
|
|
203
|
+
trackingNo: foundMarketplaceOrderShipping?.trackingNo == '[]'
|
|
204
|
+
? foundMarketplaceOrderShipping.ownTrackingNo :
|
|
205
|
+
foundMarketplaceOrderShipping?.trackingNo
|
|
202
206
|
? foundMarketplaceOrderShipping.trackingNo
|
|
203
207
|
: foundMarketplaceOrderShipping.ownTrackingNo,
|
|
204
208
|
transporter: dropPickProvider ? dropPickProvider : marketplaceOrder.shippingProvider
|
|
@@ -351,11 +355,13 @@ export const syncMarketplaceOrder = {
|
|
|
351
355
|
let foundVariations = []
|
|
352
356
|
for (var j = 0; j < order.orderItems.length; j++) {
|
|
353
357
|
var item = order.orderItems[j]
|
|
354
|
-
let
|
|
358
|
+
let foundVariationsQuery = await tx.getRepository(MarketplaceProductVariation).find({
|
|
355
359
|
where: { domain: marketplaceStore.domain, variationId: item.variationId },
|
|
356
360
|
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
357
361
|
})
|
|
358
362
|
|
|
363
|
+
let foundVariation = foundVariationsQuery.filter(fv => fv.marketplaceProduct.marketplaceStore.id == marketplaceStore.id)[0]
|
|
364
|
+
|
|
359
365
|
if (foundVariation) {
|
|
360
366
|
foundVariations.push(foundVariation)
|
|
361
367
|
}
|
|
@@ -366,7 +372,8 @@ export const syncMarketplaceOrder = {
|
|
|
366
372
|
name: item.variationName,
|
|
367
373
|
variationSku: item.variationSku,
|
|
368
374
|
channelSku: item.sku,
|
|
369
|
-
status: 'INACTIVE'
|
|
375
|
+
status: 'INACTIVE',
|
|
376
|
+
domain: marketplaceStore.domain
|
|
370
377
|
}
|
|
371
378
|
|
|
372
379
|
await tx.getRepository(MarketplaceProductVariation).save(newVariation)
|
|
@@ -412,10 +419,12 @@ export const syncMarketplaceOrder = {
|
|
|
412
419
|
}
|
|
413
420
|
|
|
414
421
|
if (existingMarketplaceOrder) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
422
|
+
let existingOrderItems: MarketplaceOrderItem[] = []
|
|
423
|
+
existingOrderItems = existingMarketplaceOrder.marketplaceOrderItems
|
|
424
|
+
|
|
425
|
+
existingOrderItems = await checkUpdateItemId(existingOrderItems, marketplaceOrderItems)
|
|
418
426
|
|
|
427
|
+
if (existingMarketplaceOrder.isSplitted) {
|
|
419
428
|
marketplaceOrderItems = existingOrderItems.filter(
|
|
420
429
|
itm => itm.name == item.name && itm.marketplaceProductVariation.variationId == item.variationId
|
|
421
430
|
)
|
|
@@ -423,14 +432,10 @@ export const syncMarketplaceOrder = {
|
|
|
423
432
|
return {
|
|
424
433
|
...marketplaceOrderitem,
|
|
425
434
|
status: order.status,
|
|
426
|
-
marketplaceProductVariation: foundVariation,
|
|
427
435
|
trackingCode: order.trackingNo
|
|
428
436
|
}
|
|
429
437
|
})
|
|
430
438
|
} else {
|
|
431
|
-
let existingOrderItems: MarketplaceOrderItem[] = []
|
|
432
|
-
existingOrderItems = existingMarketplaceOrder.marketplaceOrderItems
|
|
433
|
-
|
|
434
439
|
if (existingOrderItems.length > marketplaceOrderItems.length) {
|
|
435
440
|
let nonMatchedOrderItems = []
|
|
436
441
|
existingOrderItems.map(item => {
|
|
@@ -816,3 +821,17 @@ async function calculateReserveQtyForBundle(tx, variation, domain, qty, operator
|
|
|
816
821
|
}
|
|
817
822
|
}
|
|
818
823
|
}
|
|
824
|
+
|
|
825
|
+
function checkUpdateItemId(existingOrderItems, marketplaceOrderItems) {
|
|
826
|
+
for (let item of marketplaceOrderItems) {
|
|
827
|
+
let existingItem = existingOrderItems.find(i => i.name == item.name)
|
|
828
|
+
|
|
829
|
+
if (!existingItem) {
|
|
830
|
+
let existingItemByVariation = existingOrderItems.find(i => i.marketplaceProductVariation.id == item.marketplaceProductVariation.id)
|
|
831
|
+
existingOrderItems = existingOrderItems.filter(i => i != existingItemByVariation)
|
|
832
|
+
existingItemByVariation.name = item.name
|
|
833
|
+
existingOrderItems.push(existingItemByVariation)
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
return existingOrderItems
|
|
837
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EntityManager } from 'typeorm'
|
|
2
2
|
|
|
3
3
|
import { MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'
|
|
4
|
+
import { Domain } from '@things-factory/shell'
|
|
4
5
|
|
|
5
6
|
import {
|
|
6
7
|
MarketplaceOrder,
|
|
@@ -10,10 +11,13 @@ import {
|
|
|
10
11
|
} from '../../../entities'
|
|
11
12
|
|
|
12
13
|
export const updateOrderReadyToShip = {
|
|
13
|
-
async updateOrderReadyToShip(_: any, { shippingProvider, deliveryType, orderNo }, context: any) {
|
|
14
|
+
async updateOrderReadyToShip(_: any, { shippingProvider, deliveryType, orderNo, orderId, domainId }, context: any) {
|
|
14
15
|
const { tx }: { tx: EntityManager } = context.state
|
|
16
|
+
|
|
17
|
+
const domain: Domain = await tx.getRepository(Domain).findOne(domainId)
|
|
18
|
+
|
|
15
19
|
let foundMarketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
16
|
-
where: { name: orderNo },
|
|
20
|
+
where: { name: orderId, orderNo, domain },
|
|
17
21
|
relations: [
|
|
18
22
|
'marketplaceStore',
|
|
19
23
|
'marketplaceOrderItems',
|
|
@@ -43,45 +47,70 @@ export const updateOrderReadyToShip = {
|
|
|
43
47
|
return marketplaceOrderShippings.find(a => a.id === id)
|
|
44
48
|
})
|
|
45
49
|
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
orderItemIds =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
orderItemIds
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
50
|
+
if (marketplaceStore.platform === 'lazada') {
|
|
51
|
+
if (
|
|
52
|
+
uniqueMarketplaceOrderShippings.some(marketplaceOrderShipping => marketplaceOrderShipping.trackingNo != null)
|
|
53
|
+
) {
|
|
54
|
+
uniqueMarketplaceOrderShippings.map((orderShipping: MarketplaceOrderShipping) => {
|
|
55
|
+
if (orderShipping?.trackingNo) {
|
|
56
|
+
const trackingNoInfo: any[] = JSON.parse(orderShipping.trackingNo)
|
|
57
|
+
const orderTrackingNos: string[] = trackingNoInfo.map(item => item.tracking_code)
|
|
58
|
+
const uniqueTrackingNos = [...new Set(orderTrackingNos)]
|
|
59
|
+
|
|
60
|
+
let orderItemIds: string[] = []
|
|
61
|
+
|
|
62
|
+
if (uniqueTrackingNos?.length == 1) {
|
|
63
|
+
orderItemIds = trackingNoInfo.map(item => item.order_item_id)
|
|
64
|
+
trackingInfoArr.push({ orderItemIds, trackingNo: uniqueTrackingNos[0] })
|
|
65
|
+
} else {
|
|
66
|
+
uniqueTrackingNos.map(trackingNo => {
|
|
67
|
+
orderItemIds = trackingNoInfo
|
|
68
|
+
.filter(info => info.tracking_code === trackingNo)
|
|
69
|
+
.map(filteredInfo => filteredInfo.order_item_id)
|
|
70
|
+
|
|
71
|
+
trackingInfoArr.push({ orderItemIds, trackingNo })
|
|
72
|
+
})
|
|
73
|
+
}
|
|
66
74
|
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
for (var i = 0; i < trackingInfoArr?.length; i++) {
|
|
72
|
-
const trackingInfo = trackingInfoArr[i]
|
|
73
|
-
const trackingNo = trackingInfo.trackingNo
|
|
74
|
-
const orderItemId = trackingInfo.orderItemIds
|
|
75
|
+
})
|
|
76
|
+
}
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
orderItemId
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
for (var i = 0; i < trackingInfoArr?.length; i++) {
|
|
79
|
+
const trackingInfo = trackingInfoArr[i]
|
|
80
|
+
const trackingNo = trackingInfo.trackingNo
|
|
81
|
+
const orderItemId = trackingInfo.orderItemIds
|
|
82
|
+
|
|
83
|
+
const res = await StoreAPI.setStoreOrderStatusReadyToShip(marketplaceStore, {
|
|
84
|
+
shipmentProvider: shippingProvider,
|
|
85
|
+
deliveryType,
|
|
86
|
+
orderItemId,
|
|
87
|
+
trackingNo
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
let mos = uniqueMarketplaceOrderShippings.filter(mos => mos.trackingNo != null || mos.ownTrackingNo != null)
|
|
92
|
+
if (mos.length > 0) {
|
|
93
|
+
let trackingNo = mos[0].ownTrackingNo
|
|
94
|
+
const note = mos[0].trackingUrl || trackingNo
|
|
95
|
+
|
|
96
|
+
const res = await StoreAPI.setStoreOrderStatusReadyToShip(marketplaceStore, {
|
|
97
|
+
orderId,
|
|
98
|
+
trackingUrl: mos[0].trackingUrl || '',
|
|
99
|
+
trackingNo,
|
|
100
|
+
order: foundMarketplaceOrder,
|
|
101
|
+
note
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
if (marketplaceStore.platform === 'woocommerce') {
|
|
105
|
+
await StoreAPI.updateOrderStatus(marketplaceStore, {
|
|
106
|
+
orderId,
|
|
107
|
+
status: 'READY_TO_SHIP'
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
}
|
|
82
111
|
}
|
|
83
112
|
|
|
84
|
-
const updatedOrder = await StoreAPI.getStoreOrder(marketplaceStore, { orderId
|
|
113
|
+
const updatedOrder = await StoreAPI.getStoreOrder(marketplaceStore, { orderId })
|
|
85
114
|
|
|
86
115
|
foundMarketplaceOrder.status = updatedOrder.status
|
|
87
116
|
foundMarketplaceOrder.orderUpdatedAt = updatedOrder.orderUpdatedAt
|
|
@@ -12,7 +12,8 @@ export const marketplaceOrderShippingsResolver = {
|
|
|
12
12
|
|
|
13
13
|
const qb: SelectQueryBuilder<MarketplaceOrderShipping> = getRepository(MarketplaceOrderShipping)
|
|
14
14
|
.createQueryBuilder('MOS')
|
|
15
|
-
.innerJoinAndSelect('MOS.
|
|
15
|
+
.innerJoinAndSelect('MOS.marketplaceOrderShippingItems', 'MOSI')
|
|
16
|
+
.innerJoinAndSelect('MOSI.marketplaceOrderItem', 'MOI')
|
|
16
17
|
.innerJoinAndSelect('MOI.marketplaceOrder', 'MO')
|
|
17
18
|
.innerJoinAndSelect('MOI.marketplaceProductVariation', 'MPV')
|
|
18
19
|
.innerJoinAndSelect('MOS.marketplaceStore', 'MS')
|
|
@@ -24,7 +24,8 @@ export const marketplaceSalesReportsResolver = {
|
|
|
24
24
|
let qb: SelectQueryBuilder<MarketplaceOrderItem> = getRepository(MarketplaceOrderItem).createQueryBuilder('moi')
|
|
25
25
|
buildQuery(qb, params, context)
|
|
26
26
|
qb.leftJoinAndSelect('moi.domain', 'domain')
|
|
27
|
-
.leftJoinAndSelect('moi.
|
|
27
|
+
.leftJoinAndSelect('moi.marketplaceOrderShippingItems', 'mosi')
|
|
28
|
+
.leftJoinAndSelect('mosi.marketplaceOrderShipping', 'mos')
|
|
28
29
|
.leftJoinAndSelect('moi.marketplaceOrder', 'mo')
|
|
29
30
|
.leftJoinAndSelect('mo.fulfillmentCenter', 'fc')
|
|
30
31
|
.leftJoinAndSelect('mo.marketplaceStore', 'ms')
|
|
@@ -23,13 +23,14 @@ export const MarketplaceOrderResolver = gql`
|
|
|
23
23
|
generateMarketplaceOrder(marketplaceOrder: NewMarketplaceOrder!): MarketplaceOrder @transaction
|
|
24
24
|
cancelMarketplaceOrder(orderNo: String!, patch: MarketplaceOrderPatch!): MarketplaceOrder @transaction
|
|
25
25
|
syncMarketplaceOrder(storeId: String!, fromDate: String, toDate: String): Boolean @transaction
|
|
26
|
-
syncAllMarketplaceOrder(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
syncAllMarketplaceOrder(companyDomainId: String, fromDate: String, toDate: String, blackListStores: String): Boolean
|
|
27
|
+
updateOrderReadyToShip(
|
|
28
|
+
shippingProvider: String
|
|
29
|
+
deliveryType: String
|
|
30
|
+
orderNo: String!
|
|
31
|
+
orderId: String!
|
|
32
|
+
domainId: String!
|
|
33
|
+
): Boolean @transaction
|
|
33
34
|
initialiseLogistics(deliveryType: LogisticsInit, orderNo: String!): Boolean @transaction
|
|
34
35
|
initialiseLogisticsByBatch(patches: [LogisticsInfo]!): Boolean @transaction
|
|
35
36
|
initialiseShopeeLogisticsByBatch(patches: [LogisticsInfo]!): Boolean
|