@things-factory/marketplace-base 3.8.29 → 3.8.35
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/graphql/resolvers/marketplace-order/sync-all-marketplace-order.js +184 -102
- 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 +188 -114
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-order.js.map +1 -1
- package/package.json +3 -2
- package/server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.ts +286 -174
- package/server/graphql/resolvers/marketplace-order/sync-marketplace-order.ts +275 -170
|
@@ -5,6 +5,7 @@ import { Bizplace, getCustomerBizplaces } from '@things-factory/biz-base'
|
|
|
5
5
|
import { FulfillmentAPI, FulfillmentCenter } from '@things-factory/integration-fulfillment'
|
|
6
6
|
import { MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'
|
|
7
7
|
import { Domain } from '@things-factory/shell'
|
|
8
|
+
import { Product, ProductBundle, ProductBundleSetting } from '@things-factory/product-base'
|
|
8
9
|
|
|
9
10
|
import {
|
|
10
11
|
MarketplaceOrder,
|
|
@@ -134,6 +135,36 @@ export const syncAllMarketplaceOrder = {
|
|
|
134
135
|
updater: user
|
|
135
136
|
}
|
|
136
137
|
|
|
138
|
+
if (
|
|
139
|
+
!marketplaceOrder?.releaseOrderId &&
|
|
140
|
+
cancelStatuses.includes(marketplaceOrder.status) &&
|
|
141
|
+
!cancelStatuses.includes(existingMarketplaceOrder.status)
|
|
142
|
+
) {
|
|
143
|
+
for (let item of marketplaceOrder.marketplaceOrderItems) {
|
|
144
|
+
let foundVariations = await getRepository(MarketplaceProductVariation).find({
|
|
145
|
+
where: {
|
|
146
|
+
domain: marketplaceOrder.domain,
|
|
147
|
+
sku: item.marketplaceProductVariation.sku
|
|
148
|
+
},
|
|
149
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
let activeVariations: MarketplaceProductVariation[] = foundVariations.filter(
|
|
153
|
+
variation =>
|
|
154
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED' && variation.sku != null
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
await Promise.all(
|
|
158
|
+
activeVariations.map(async variation => {
|
|
159
|
+
await calculateReserveQtyForBundle(variation, marketplaceOrder.domain, item.qty, '-')
|
|
160
|
+
|
|
161
|
+
variation.reserveQty -= item.qty
|
|
162
|
+
variation.qty += item.qty
|
|
163
|
+
await getRepository(MarketplaceProductVariation).save(variation)
|
|
164
|
+
})
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
137
168
|
if (marketplaceOrder?.releaseOrderId) {
|
|
138
169
|
const fulfillmentCenter: FulfillmentCenter = marketplaceOrder.fulfillmentCenter
|
|
139
170
|
const centerId: string = fulfillmentCenter.centerId
|
|
@@ -239,8 +270,6 @@ export const syncAllMarketplaceOrder = {
|
|
|
239
270
|
}
|
|
240
271
|
}
|
|
241
272
|
|
|
242
|
-
marketplaceOrder = await getRepository(MarketplaceOrder).save(marketplaceOrder)
|
|
243
|
-
|
|
244
273
|
let savedMarketplaceOrderShipping: MarketplaceOrderShipping = new MarketplaceOrderShipping()
|
|
245
274
|
let savedMarketplaceOrderShippings: MarketplaceOrderShipping[] = []
|
|
246
275
|
|
|
@@ -330,13 +359,17 @@ export const syncAllMarketplaceOrder = {
|
|
|
330
359
|
}
|
|
331
360
|
|
|
332
361
|
let orderTotalWeight: number = 0
|
|
333
|
-
let
|
|
362
|
+
let foundVariations = []
|
|
334
363
|
for (var j = 0; j < order.orderItems.length; j++) {
|
|
335
364
|
var item = order.orderItems[j]
|
|
336
|
-
foundVariation = await getRepository(MarketplaceProductVariation).findOne({
|
|
365
|
+
let foundVariation = await getRepository(MarketplaceProductVariation).findOne({
|
|
337
366
|
where: { domain: marketplaceStore.domain, variationId: item.variationId }
|
|
338
367
|
})
|
|
339
368
|
|
|
369
|
+
if (foundVariation) {
|
|
370
|
+
foundVariations.push(foundVariation)
|
|
371
|
+
}
|
|
372
|
+
|
|
340
373
|
if (!foundVariation) {
|
|
341
374
|
let newVariation: any = {
|
|
342
375
|
variationId: item.variationId,
|
|
@@ -424,158 +457,190 @@ export const syncAllMarketplaceOrder = {
|
|
|
424
457
|
if (nonMatchedOrderItems.length > 0 && !cancelStatuses.includes(marketplaceOrder.status)) {
|
|
425
458
|
await Promise.all(
|
|
426
459
|
nonMatchedOrderItems.map(async item => {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
MarketplaceProductVariation
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
variation.
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
460
|
+
for (var foundVariation of foundVariations) {
|
|
461
|
+
if (foundVariation.sku) {
|
|
462
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
463
|
+
MarketplaceProductVariation
|
|
464
|
+
).find({
|
|
465
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
466
|
+
relations: [
|
|
467
|
+
'domain',
|
|
468
|
+
'marketplaceProduct',
|
|
469
|
+
'marketplaceProduct.marketplaceStore',
|
|
470
|
+
'marketplaceProduct.marketplaceStore.marketplaceDistributors'
|
|
471
|
+
]
|
|
472
|
+
})
|
|
473
|
+
|
|
474
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
475
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
await Promise.all(
|
|
479
|
+
activeVariations.map(async variation => {
|
|
480
|
+
await calculateReserveQtyForBundle(variation, marketplaceOrder.domain, item.qty, '-')
|
|
481
|
+
|
|
482
|
+
variation.reserveQty -= item.qty
|
|
483
|
+
variation.qty += item.qty
|
|
484
|
+
|
|
485
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
486
|
+
})
|
|
487
|
+
)
|
|
488
|
+
}
|
|
451
489
|
}
|
|
452
|
-
|
|
453
|
-
foundVariation.qty += item.qty
|
|
454
|
-
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
455
490
|
})
|
|
456
491
|
)
|
|
457
492
|
|
|
458
493
|
await getRepository(MarketplaceOrderItem).delete(nonMatchedOrderItems)
|
|
459
494
|
}
|
|
460
495
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
itm
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
496
|
+
if (!cancelStatuses.includes(marketplaceOrder.status)) {
|
|
497
|
+
existingOrderItems = await Promise.all(
|
|
498
|
+
marketplaceOrderItems.map(async item => {
|
|
499
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
500
|
+
itm =>
|
|
501
|
+
itm.name == item.name &&
|
|
502
|
+
itm.marketplaceProductVariation.variationId ==
|
|
503
|
+
item.marketplaceProductVariation.variationId
|
|
504
|
+
)
|
|
505
|
+
if (matchedOrderItem) {
|
|
506
|
+
for (var foundVariation of foundVariations) {
|
|
507
|
+
if (foundVariation.sku) {
|
|
508
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
509
|
+
MarketplaceProductVariation
|
|
510
|
+
).find({
|
|
511
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
512
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
513
|
+
})
|
|
514
|
+
|
|
515
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
516
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
517
|
+
)
|
|
518
|
+
|
|
519
|
+
await Promise.all(
|
|
520
|
+
activeVariations.map(async variation => {
|
|
521
|
+
if (
|
|
522
|
+
!existingMarketplaceOrder?.releaseOrderId &&
|
|
523
|
+
matchedOrderItem.qty - item.qty != 0
|
|
524
|
+
) {
|
|
525
|
+
await calculateReserveQtyForBundle(
|
|
526
|
+
variation,
|
|
527
|
+
marketplaceOrder.domain,
|
|
528
|
+
matchedOrderItem.qty - item.qty
|
|
529
|
+
)
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
533
|
+
? variation.reserveQty
|
|
534
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
535
|
+
|
|
536
|
+
variation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
537
|
+
? variation.qty
|
|
538
|
+
: variation.qty + item.qty - matchedOrderItem.qty
|
|
539
|
+
|
|
540
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
541
|
+
})
|
|
542
|
+
)
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return {
|
|
546
|
+
...matchedOrderItem,
|
|
547
|
+
...item,
|
|
548
|
+
updater: user
|
|
549
|
+
}
|
|
501
550
|
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
|
|
551
|
+
})
|
|
552
|
+
)
|
|
553
|
+
}
|
|
505
554
|
} else {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
itm
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
555
|
+
if (!cancelStatuses.includes(marketplaceOrder.status)) {
|
|
556
|
+
existingOrderItems = await Promise.all(
|
|
557
|
+
marketplaceOrderItems.map(async item => {
|
|
558
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
559
|
+
itm =>
|
|
560
|
+
itm.name == item.name &&
|
|
561
|
+
itm.marketplaceProductVariation.variationId ==
|
|
562
|
+
item.marketplaceProductVariation.variationId
|
|
563
|
+
)
|
|
564
|
+
if (matchedOrderItem) {
|
|
565
|
+
for (var foundVariation of foundVariations) {
|
|
566
|
+
if (foundVariation.sku) {
|
|
567
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
568
|
+
MarketplaceProductVariation
|
|
569
|
+
).find({
|
|
570
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
571
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
572
|
+
})
|
|
573
|
+
|
|
574
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
575
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
await Promise.all(
|
|
579
|
+
activeVariations.map(async variation => {
|
|
580
|
+
if (
|
|
581
|
+
!existingMarketplaceOrder?.releaseOrderId &&
|
|
582
|
+
matchedOrderItem.qty - item.qty != 0
|
|
583
|
+
) {
|
|
584
|
+
await calculateReserveQtyForBundle(
|
|
585
|
+
variation,
|
|
586
|
+
marketplaceOrder.domain,
|
|
587
|
+
matchedOrderItem.qty - item.qty
|
|
588
|
+
)
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
592
|
+
? variation.reserveQty
|
|
593
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
594
|
+
|
|
595
|
+
variation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
596
|
+
? variation.qty
|
|
597
|
+
: variation.qty + item.qty - matchedOrderItem.qty
|
|
598
|
+
|
|
599
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
600
|
+
})
|
|
601
|
+
)
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return {
|
|
605
|
+
...matchedOrderItem,
|
|
606
|
+
...item,
|
|
607
|
+
updater: user
|
|
608
|
+
}
|
|
609
|
+
} else {
|
|
610
|
+
for (var foundVariation of foundVariations) {
|
|
611
|
+
if (foundVariation.sku) {
|
|
612
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
613
|
+
MarketplaceProductVariation
|
|
614
|
+
).find({
|
|
615
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
616
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
617
|
+
})
|
|
618
|
+
|
|
619
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
620
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
621
|
+
)
|
|
622
|
+
|
|
623
|
+
await Promise.all(
|
|
624
|
+
activeVariations.map(async variation => {
|
|
625
|
+
await calculateReserveQtyForBundle(variation, marketplaceOrder.domain, item.qty)
|
|
626
|
+
|
|
627
|
+
variation.reserveQty += item.qty
|
|
628
|
+
if (variation.qty - item.qty >= 0) {
|
|
629
|
+
variation.qty -= item.qty
|
|
630
|
+
}
|
|
631
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
632
|
+
})
|
|
633
|
+
)
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return {
|
|
637
|
+
...item,
|
|
638
|
+
updater: user
|
|
639
|
+
}
|
|
575
640
|
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
|
|
641
|
+
})
|
|
642
|
+
)
|
|
643
|
+
}
|
|
579
644
|
}
|
|
580
645
|
|
|
581
646
|
marketplaceOrderItems = existingOrderItems
|
|
@@ -588,38 +653,47 @@ export const syncAllMarketplaceOrder = {
|
|
|
588
653
|
}
|
|
589
654
|
}
|
|
590
655
|
} else {
|
|
591
|
-
if (
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
656
|
+
if (!cancelStatuses.includes(marketplaceOrder.status)) {
|
|
657
|
+
for (var foundVariation of foundVariations) {
|
|
658
|
+
if (foundVariation.sku) {
|
|
659
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
660
|
+
MarketplaceProductVariation
|
|
661
|
+
).find({
|
|
662
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
663
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
664
|
+
})
|
|
598
665
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
)
|
|
666
|
+
let item = order.orderItems.find(e => e.variationId == foundVariation.variationId)
|
|
667
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
668
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
669
|
+
)
|
|
604
670
|
|
|
605
|
-
|
|
606
|
-
|
|
671
|
+
await Promise.all(
|
|
672
|
+
activeVariations.map(async variation => {
|
|
673
|
+
await calculateReserveQtyForBundle(variation, marketplaceOrder.domain, item.qty)
|
|
674
|
+
variation.reserveQty += item.qty
|
|
675
|
+
if (variation.qty - item.qty >= 0) {
|
|
676
|
+
variation.qty -= item.qty
|
|
677
|
+
}
|
|
607
678
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
679
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
680
|
+
})
|
|
681
|
+
)
|
|
682
|
+
}
|
|
611
683
|
|
|
612
|
-
|
|
613
|
-
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
684
|
+
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
614
685
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
686
|
+
if (order?.orderShipping) {
|
|
687
|
+
savedMarketplaceOrderShipping.totalWeight = orderTotalWeight
|
|
688
|
+
savedMarketplaceOrderShipping = await getRepository(MarketplaceOrderShipping).save(
|
|
689
|
+
savedMarketplaceOrderShipping
|
|
690
|
+
)
|
|
691
|
+
}
|
|
692
|
+
}
|
|
620
693
|
}
|
|
621
694
|
}
|
|
622
695
|
|
|
696
|
+
await getRepository(MarketplaceOrder).save(marketplaceOrder)
|
|
623
697
|
await getRepository(MarketplaceOrderItem).save(marketplaceOrderItems)
|
|
624
698
|
|
|
625
699
|
if (m == marketplaceOrders.length - 1) {
|
|
@@ -640,19 +714,19 @@ export const syncAllMarketplaceOrder = {
|
|
|
640
714
|
let hasMore = true
|
|
641
715
|
let perPage: number = 100
|
|
642
716
|
var payoutDateList = []
|
|
643
|
-
|
|
717
|
+
|
|
644
718
|
while (hasMore) {
|
|
645
719
|
const { result: payoutDates, more } = await StoreAPI.getStoreOrderPayoutDates(marketplaceStore, {
|
|
646
720
|
fromDate,
|
|
647
721
|
toDate,
|
|
648
722
|
pagination: { page: pageNo, limit: perPage }
|
|
649
723
|
})
|
|
650
|
-
|
|
724
|
+
|
|
651
725
|
payoutDateList.push(...payoutDates)
|
|
652
726
|
if (more) pageNo++
|
|
653
727
|
hasMore = more
|
|
654
728
|
}
|
|
655
|
-
|
|
729
|
+
|
|
656
730
|
await Promise.all(
|
|
657
731
|
payoutDateList.map(async item => {
|
|
658
732
|
await getRepository(MarketplaceOrder).update(
|
|
@@ -665,9 +739,47 @@ export const syncAllMarketplaceOrder = {
|
|
|
665
739
|
)
|
|
666
740
|
})
|
|
667
741
|
)
|
|
668
|
-
}
|
|
742
|
+
}
|
|
669
743
|
}
|
|
670
744
|
|
|
671
745
|
return true
|
|
672
746
|
}
|
|
673
747
|
}
|
|
748
|
+
|
|
749
|
+
async function calculateReserveQtyForBundle(variation, domain, qty, operator = '+') {
|
|
750
|
+
const productBundle: ProductBundle = await getRepository(ProductBundle).findOne({
|
|
751
|
+
where: { sku: variation.sku, domain }
|
|
752
|
+
})
|
|
753
|
+
|
|
754
|
+
if (productBundle) {
|
|
755
|
+
const productBundleSettings: ProductBundleSetting[] = await getRepository(ProductBundleSetting).find({
|
|
756
|
+
where: { productBundle },
|
|
757
|
+
relations: ['productBundle', 'product']
|
|
758
|
+
})
|
|
759
|
+
|
|
760
|
+
for (let setting of productBundleSettings) {
|
|
761
|
+
const product: Product = await getRepository(Product).findOne({
|
|
762
|
+
where: { id: setting.product.id }
|
|
763
|
+
})
|
|
764
|
+
|
|
765
|
+
const mpvs: MarketplaceProductVariation[] = await getRepository(MarketplaceProductVariation).find({
|
|
766
|
+
where: { domain, sku: product.sku },
|
|
767
|
+
relations: ['domain']
|
|
768
|
+
})
|
|
769
|
+
|
|
770
|
+
for (let mpv of mpvs) {
|
|
771
|
+
if (operator === '+') {
|
|
772
|
+
mpv.reserveQty += setting.bundleQty * qty
|
|
773
|
+
if (mpv.qty - setting.bundleQty * qty >= 0) {
|
|
774
|
+
mpv.qty -= setting.bundleQty * qty
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
if (operator === '-') {
|
|
778
|
+
mpv.reserveQty -= setting.bundleQty * qty
|
|
779
|
+
mpv.qty += setting.bundleQty * qty
|
|
780
|
+
}
|
|
781
|
+
await getRepository(MarketplaceProductVariation).save(mpv)
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|