@things-factory/marketplace-base 3.8.29 → 3.8.30
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 +183 -101
- 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 +187 -113
- 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 +293 -172
- package/server/graphql/resolvers/marketplace-order/sync-marketplace-order.ts +279 -168
|
@@ -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 this.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
|
|
@@ -330,13 +361,17 @@ export const syncAllMarketplaceOrder = {
|
|
|
330
361
|
}
|
|
331
362
|
|
|
332
363
|
let orderTotalWeight: number = 0
|
|
333
|
-
let
|
|
364
|
+
let foundVariations = []
|
|
334
365
|
for (var j = 0; j < order.orderItems.length; j++) {
|
|
335
366
|
var item = order.orderItems[j]
|
|
336
|
-
foundVariation = await getRepository(MarketplaceProductVariation).findOne({
|
|
367
|
+
let foundVariation = await getRepository(MarketplaceProductVariation).findOne({
|
|
337
368
|
where: { domain: marketplaceStore.domain, variationId: item.variationId }
|
|
338
369
|
})
|
|
339
370
|
|
|
371
|
+
if (foundVariation) {
|
|
372
|
+
foundVariations.push(foundVariation)
|
|
373
|
+
}
|
|
374
|
+
|
|
340
375
|
if (!foundVariation) {
|
|
341
376
|
let newVariation: any = {
|
|
342
377
|
variationId: item.variationId,
|
|
@@ -424,158 +459,199 @@ export const syncAllMarketplaceOrder = {
|
|
|
424
459
|
if (nonMatchedOrderItems.length > 0 && !cancelStatuses.includes(marketplaceOrder.status)) {
|
|
425
460
|
await Promise.all(
|
|
426
461
|
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
|
-
|
|
462
|
+
for (var foundVariation of foundVariations) {
|
|
463
|
+
if (foundVariation.sku) {
|
|
464
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
465
|
+
MarketplaceProductVariation
|
|
466
|
+
).find({
|
|
467
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
468
|
+
relations: [
|
|
469
|
+
'domain',
|
|
470
|
+
'marketplaceProduct',
|
|
471
|
+
'marketplaceProduct.marketplaceStore',
|
|
472
|
+
'marketplaceProduct.marketplaceStore.marketplaceDistributors'
|
|
473
|
+
]
|
|
474
|
+
})
|
|
475
|
+
|
|
476
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
477
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
478
|
+
)
|
|
479
|
+
|
|
480
|
+
await Promise.all(
|
|
481
|
+
activeVariations.map(async variation => {
|
|
482
|
+
await this.calculateReserveQtyForBundle(
|
|
483
|
+
variation,
|
|
484
|
+
marketplaceOrder.domain,
|
|
485
|
+
item.qty,
|
|
486
|
+
'-'
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
variation.reserveQty -= item.qty
|
|
490
|
+
variation.qty += item.qty
|
|
491
|
+
|
|
492
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
493
|
+
})
|
|
494
|
+
)
|
|
495
|
+
}
|
|
451
496
|
}
|
|
452
|
-
|
|
453
|
-
foundVariation.qty += item.qty
|
|
454
|
-
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
455
497
|
})
|
|
456
498
|
)
|
|
457
499
|
|
|
458
500
|
await getRepository(MarketplaceOrderItem).delete(nonMatchedOrderItems)
|
|
459
501
|
}
|
|
460
502
|
|
|
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
|
-
|
|
503
|
+
if (!cancelStatuses.includes(marketplaceOrder.status)) {
|
|
504
|
+
existingOrderItems = await Promise.all(
|
|
505
|
+
marketplaceOrderItems.map(async item => {
|
|
506
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
507
|
+
itm =>
|
|
508
|
+
itm.name == item.name &&
|
|
509
|
+
itm.marketplaceProductVariation.variationId ==
|
|
510
|
+
item.marketplaceProductVariation.variationId
|
|
511
|
+
)
|
|
512
|
+
if (matchedOrderItem) {
|
|
513
|
+
for (var foundVariation of foundVariations) {
|
|
514
|
+
if (foundVariation.sku) {
|
|
515
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
516
|
+
MarketplaceProductVariation
|
|
517
|
+
).find({
|
|
518
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
519
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
520
|
+
})
|
|
521
|
+
|
|
522
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
523
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
524
|
+
)
|
|
525
|
+
|
|
526
|
+
await Promise.all(
|
|
527
|
+
activeVariations.map(async variation => {
|
|
528
|
+
if (
|
|
529
|
+
!existingMarketplaceOrder?.releaseOrderId &&
|
|
530
|
+
matchedOrderItem.qty - item.qty != 0
|
|
531
|
+
) {
|
|
532
|
+
await this.calculateReserveQtyForBundle(
|
|
533
|
+
variation,
|
|
534
|
+
marketplaceOrder.domain,
|
|
535
|
+
matchedOrderItem.qty - item.qty
|
|
536
|
+
)
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
540
|
+
? variation.reserveQty
|
|
541
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
542
|
+
|
|
543
|
+
variation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
544
|
+
? variation.qty
|
|
545
|
+
: variation.qty + item.qty - matchedOrderItem.qty
|
|
546
|
+
|
|
547
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
548
|
+
})
|
|
549
|
+
)
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return {
|
|
553
|
+
...matchedOrderItem,
|
|
554
|
+
...item,
|
|
555
|
+
updater: user
|
|
556
|
+
}
|
|
490
557
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
: foundVariation.qty + item.qty - matchedOrderItem.qty
|
|
495
|
-
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
496
|
-
|
|
497
|
-
return {
|
|
498
|
-
...matchedOrderItem,
|
|
499
|
-
...item,
|
|
500
|
-
updater: user
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
})
|
|
504
|
-
)
|
|
558
|
+
})
|
|
559
|
+
)
|
|
560
|
+
}
|
|
505
561
|
} 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
|
-
|
|
562
|
+
if (!cancelStatuses.includes(marketplaceOrder.status)) {
|
|
563
|
+
existingOrderItems = await Promise.all(
|
|
564
|
+
marketplaceOrderItems.map(async item => {
|
|
565
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
566
|
+
itm =>
|
|
567
|
+
itm.name == item.name &&
|
|
568
|
+
itm.marketplaceProductVariation.variationId ==
|
|
569
|
+
item.marketplaceProductVariation.variationId
|
|
570
|
+
)
|
|
571
|
+
if (matchedOrderItem) {
|
|
572
|
+
for (var foundVariation of foundVariations) {
|
|
573
|
+
if (foundVariation.sku) {
|
|
574
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
575
|
+
MarketplaceProductVariation
|
|
576
|
+
).find({
|
|
577
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
578
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
582
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
583
|
+
)
|
|
584
|
+
|
|
585
|
+
await Promise.all(
|
|
586
|
+
activeVariations.map(async variation => {
|
|
587
|
+
if (
|
|
588
|
+
!existingMarketplaceOrder?.releaseOrderId &&
|
|
589
|
+
matchedOrderItem.qty - item.qty != 0
|
|
590
|
+
) {
|
|
591
|
+
await this.calculateReserveQtyForBundle(
|
|
592
|
+
variation,
|
|
593
|
+
marketplaceOrder.domain,
|
|
594
|
+
matchedOrderItem.qty - item.qty
|
|
595
|
+
)
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
599
|
+
? variation.reserveQty
|
|
600
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
601
|
+
|
|
602
|
+
variation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
603
|
+
? variation.qty
|
|
604
|
+
: variation.qty + item.qty - matchedOrderItem.qty
|
|
605
|
+
|
|
606
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
607
|
+
})
|
|
608
|
+
)
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return {
|
|
612
|
+
...matchedOrderItem,
|
|
613
|
+
...item,
|
|
614
|
+
updater: user
|
|
615
|
+
}
|
|
616
|
+
} else {
|
|
617
|
+
for (var foundVariation of foundVariations) {
|
|
618
|
+
if (foundVariation.sku) {
|
|
619
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
620
|
+
MarketplaceProductVariation
|
|
621
|
+
).find({
|
|
622
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
623
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
624
|
+
})
|
|
625
|
+
|
|
626
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
627
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
628
|
+
)
|
|
629
|
+
|
|
630
|
+
await Promise.all(
|
|
631
|
+
activeVariations.map(async variation => {
|
|
632
|
+
await this.calculateReserveQtyForBundle(
|
|
633
|
+
variation,
|
|
634
|
+
marketplaceOrder.domain,
|
|
635
|
+
item.qty
|
|
636
|
+
)
|
|
637
|
+
|
|
638
|
+
variation.reserveQty += item.qty
|
|
639
|
+
if (variation.qty - item.qty >= 0) {
|
|
640
|
+
variation.qty -= item.qty
|
|
641
|
+
}
|
|
642
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
643
|
+
})
|
|
644
|
+
)
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
...item,
|
|
649
|
+
updater: user
|
|
650
|
+
}
|
|
546
651
|
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
MarketplaceProductVariation
|
|
551
|
-
).find({
|
|
552
|
-
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
553
|
-
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
554
|
-
})
|
|
555
|
-
|
|
556
|
-
let variationsFromOtherStores: MarketplaceProductVariation[] = allVariations.filter(
|
|
557
|
-
variation =>
|
|
558
|
-
variation.id != foundVariation.id &&
|
|
559
|
-
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
560
|
-
)
|
|
561
|
-
|
|
562
|
-
variationsFromOtherStores.map(async variation => {
|
|
563
|
-
variation.reserveQty += item.qty
|
|
564
|
-
|
|
565
|
-
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
566
|
-
})
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
foundVariation.qty -= item.qty
|
|
570
|
-
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
571
|
-
|
|
572
|
-
return {
|
|
573
|
-
...item,
|
|
574
|
-
updater: user
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
})
|
|
578
|
-
)
|
|
652
|
+
})
|
|
653
|
+
)
|
|
654
|
+
}
|
|
579
655
|
}
|
|
580
656
|
|
|
581
657
|
marketplaceOrderItems = existingOrderItems
|
|
@@ -588,35 +664,43 @@ export const syncAllMarketplaceOrder = {
|
|
|
588
664
|
}
|
|
589
665
|
}
|
|
590
666
|
} else {
|
|
591
|
-
if (
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
667
|
+
if (!cancelStatuses.includes(marketplaceOrder.status)) {
|
|
668
|
+
for (var foundVariation of foundVariations) {
|
|
669
|
+
if (foundVariation.sku) {
|
|
670
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
671
|
+
MarketplaceProductVariation
|
|
672
|
+
).find({
|
|
673
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
674
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
675
|
+
})
|
|
598
676
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
)
|
|
677
|
+
let item = order.orderItems.find(e => e.variationId == foundVariation.variationId)
|
|
678
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
679
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
680
|
+
)
|
|
604
681
|
|
|
605
|
-
|
|
606
|
-
|
|
682
|
+
await Promise.all(
|
|
683
|
+
activeVariations.map(async variation => {
|
|
684
|
+
await this.calculateReserveQtyForBundle(variation, marketplaceOrder.domain, item.qty)
|
|
685
|
+
variation.reserveQty += item.qty
|
|
686
|
+
if (variation.qty - item.qty >= 0) {
|
|
687
|
+
variation.qty -= item.qty
|
|
688
|
+
}
|
|
607
689
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
690
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
691
|
+
})
|
|
692
|
+
)
|
|
693
|
+
}
|
|
611
694
|
|
|
612
|
-
|
|
613
|
-
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
695
|
+
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
614
696
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
697
|
+
if (order?.orderShipping) {
|
|
698
|
+
savedMarketplaceOrderShipping.totalWeight = orderTotalWeight
|
|
699
|
+
savedMarketplaceOrderShipping = await getRepository(MarketplaceOrderShipping).save(
|
|
700
|
+
savedMarketplaceOrderShipping
|
|
701
|
+
)
|
|
702
|
+
}
|
|
703
|
+
}
|
|
620
704
|
}
|
|
621
705
|
}
|
|
622
706
|
|
|
@@ -640,19 +724,19 @@ export const syncAllMarketplaceOrder = {
|
|
|
640
724
|
let hasMore = true
|
|
641
725
|
let perPage: number = 100
|
|
642
726
|
var payoutDateList = []
|
|
643
|
-
|
|
727
|
+
|
|
644
728
|
while (hasMore) {
|
|
645
729
|
const { result: payoutDates, more } = await StoreAPI.getStoreOrderPayoutDates(marketplaceStore, {
|
|
646
730
|
fromDate,
|
|
647
731
|
toDate,
|
|
648
732
|
pagination: { page: pageNo, limit: perPage }
|
|
649
733
|
})
|
|
650
|
-
|
|
734
|
+
|
|
651
735
|
payoutDateList.push(...payoutDates)
|
|
652
736
|
if (more) pageNo++
|
|
653
737
|
hasMore = more
|
|
654
738
|
}
|
|
655
|
-
|
|
739
|
+
|
|
656
740
|
await Promise.all(
|
|
657
741
|
payoutDateList.map(async item => {
|
|
658
742
|
await getRepository(MarketplaceOrder).update(
|
|
@@ -665,9 +749,46 @@ export const syncAllMarketplaceOrder = {
|
|
|
665
749
|
)
|
|
666
750
|
})
|
|
667
751
|
)
|
|
668
|
-
}
|
|
752
|
+
}
|
|
669
753
|
}
|
|
670
754
|
|
|
671
755
|
return true
|
|
756
|
+
},
|
|
757
|
+
async calculateReserveQtyForBundle(variation, domain, qty, operator = '+') {
|
|
758
|
+
const productBundle: ProductBundle = await getRepository(ProductBundle).findOne({
|
|
759
|
+
where: { sku: variation.sku, domain }
|
|
760
|
+
})
|
|
761
|
+
|
|
762
|
+
if (productBundle) {
|
|
763
|
+
const productBundleSettings: ProductBundleSetting[] = await getRepository(ProductBundleSetting).find({
|
|
764
|
+
where: { productBundle },
|
|
765
|
+
relations: ['productBundle', 'product']
|
|
766
|
+
})
|
|
767
|
+
|
|
768
|
+
for (let setting of productBundleSettings) {
|
|
769
|
+
const product: Product = await getRepository(Product).findOne({
|
|
770
|
+
where: { id: setting.product.id }
|
|
771
|
+
})
|
|
772
|
+
|
|
773
|
+
const mpvs: MarketplaceProductVariation[] = await getRepository(MarketplaceProductVariation).find({
|
|
774
|
+
where: { domain, sku: product.sku },
|
|
775
|
+
relations: ['domain']
|
|
776
|
+
})
|
|
777
|
+
|
|
778
|
+
for (let mpv of mpvs) {
|
|
779
|
+
if (operator === '+') {
|
|
780
|
+
mpv.reserveQty += setting.bundleQty * qty
|
|
781
|
+
if (mpv.qty - setting.bundleQty * qty >= 0) {
|
|
782
|
+
mpv.qty -= setting.bundleQty * qty
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (operator === '-') {
|
|
786
|
+
mpv.reserveQty -= setting.bundleQty * qty
|
|
787
|
+
mpv.qty += setting.bundleQty * qty
|
|
788
|
+
}
|
|
789
|
+
await getRepository(MarketplaceProductVariation).save(mpv)
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
672
793
|
}
|
|
673
794
|
}
|