@etsoo/appscript 1.4.59 → 1.4.60
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.
|
@@ -67,6 +67,10 @@ export type ShoppingCartItemBase = {
|
|
|
67
67
|
* 数量
|
|
68
68
|
*/
|
|
69
69
|
qty: number;
|
|
70
|
+
/**
|
|
71
|
+
* Asset qty
|
|
72
|
+
*/
|
|
73
|
+
assetQty?: number;
|
|
70
74
|
/**
|
|
71
75
|
* Product level promotions
|
|
72
76
|
* 产品层次促销
|
|
@@ -317,6 +321,15 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
|
|
|
317
321
|
* @param item Shopping cart item
|
|
318
322
|
*/
|
|
319
323
|
updateDiscount(item: ShoppingCartItem): void;
|
|
324
|
+
/**
|
|
325
|
+
* Update asset item
|
|
326
|
+
* 更新资产项目
|
|
327
|
+
* @param id Product id
|
|
328
|
+
* @param qty Asset qty
|
|
329
|
+
* @param itemCreator New item creator
|
|
330
|
+
* @returns Updated or not
|
|
331
|
+
*/
|
|
332
|
+
updateAssetItem(id: T['id'], assetQty: number | undefined, itemCreator?: () => Omit<T, 'id' | 'price' | 'assetQty' | 'subtotal' | 'discount' | 'promotions'>): boolean;
|
|
320
333
|
/**
|
|
321
334
|
* Update item
|
|
322
335
|
* 更新项目
|
|
@@ -361,6 +361,54 @@ class ShoppingCart {
|
|
|
361
361
|
updateDiscount(item) {
|
|
362
362
|
item.discount = item.promotions.sum('amount');
|
|
363
363
|
}
|
|
364
|
+
/**
|
|
365
|
+
* Update asset item
|
|
366
|
+
* 更新资产项目
|
|
367
|
+
* @param id Product id
|
|
368
|
+
* @param qty Asset qty
|
|
369
|
+
* @param itemCreator New item creator
|
|
370
|
+
* @returns Updated or not
|
|
371
|
+
*/
|
|
372
|
+
updateAssetItem(id, assetQty, itemCreator) {
|
|
373
|
+
var _a;
|
|
374
|
+
if (assetQty == null || assetQty <= 0)
|
|
375
|
+
assetQty = 1;
|
|
376
|
+
const index = this.items.findIndex((item) => item.id === id);
|
|
377
|
+
if (index === -1) {
|
|
378
|
+
// New
|
|
379
|
+
if (itemCreator) {
|
|
380
|
+
const price = this.prices[id];
|
|
381
|
+
const data = itemCreator();
|
|
382
|
+
const qty = data.qty;
|
|
383
|
+
const newItem = {
|
|
384
|
+
...data,
|
|
385
|
+
id,
|
|
386
|
+
price,
|
|
387
|
+
subtotal: price * qty * assetQty,
|
|
388
|
+
discount: 0,
|
|
389
|
+
promotions: Array()
|
|
390
|
+
};
|
|
391
|
+
this.addItem(newItem);
|
|
392
|
+
}
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
// Update
|
|
397
|
+
const item = this.items[index];
|
|
398
|
+
// Price may be cached first
|
|
399
|
+
const price = (_a = this.prices[id]) !== null && _a !== void 0 ? _a : item.price;
|
|
400
|
+
const qty = item.qty;
|
|
401
|
+
const newItem = {
|
|
402
|
+
...item,
|
|
403
|
+
price,
|
|
404
|
+
subtotal: price * qty * assetQty,
|
|
405
|
+
discount: 0
|
|
406
|
+
};
|
|
407
|
+
this.items.splice(index, 1, newItem);
|
|
408
|
+
this.doChange('update', [item, newItem]);
|
|
409
|
+
}
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
364
412
|
/**
|
|
365
413
|
* Update item
|
|
366
414
|
* 更新项目
|
|
@@ -383,12 +431,13 @@ class ShoppingCart {
|
|
|
383
431
|
// New
|
|
384
432
|
if (itemCreator) {
|
|
385
433
|
const price = this.prices[id];
|
|
434
|
+
const data = itemCreator();
|
|
386
435
|
const newItem = {
|
|
387
|
-
...
|
|
436
|
+
...data,
|
|
388
437
|
id,
|
|
389
438
|
price,
|
|
390
439
|
qty,
|
|
391
|
-
subtotal: price * qty,
|
|
440
|
+
subtotal: price * qty * (data.assetQty || 1),
|
|
392
441
|
discount: 0,
|
|
393
442
|
promotions: Array()
|
|
394
443
|
};
|
|
@@ -405,7 +454,7 @@ class ShoppingCart {
|
|
|
405
454
|
...item,
|
|
406
455
|
qty,
|
|
407
456
|
price,
|
|
408
|
-
subtotal: price * qty,
|
|
457
|
+
subtotal: price * qty * (item.assetQty || 1),
|
|
409
458
|
discount: 0
|
|
410
459
|
};
|
|
411
460
|
this.items.splice(index, 1, newItem);
|
|
@@ -424,7 +473,12 @@ class ShoppingCart {
|
|
|
424
473
|
if (index !== -1) {
|
|
425
474
|
const item = this.items[index];
|
|
426
475
|
const qty = item.qty;
|
|
427
|
-
const
|
|
476
|
+
const assetQty = item.assetQty || 1;
|
|
477
|
+
const newItem = {
|
|
478
|
+
...item,
|
|
479
|
+
price,
|
|
480
|
+
subtotal: price * qty * assetQty
|
|
481
|
+
};
|
|
428
482
|
this.items.splice(index, 1, newItem);
|
|
429
483
|
this.doChange('update', [item, newItem]);
|
|
430
484
|
}
|
|
@@ -67,6 +67,10 @@ export type ShoppingCartItemBase = {
|
|
|
67
67
|
* 数量
|
|
68
68
|
*/
|
|
69
69
|
qty: number;
|
|
70
|
+
/**
|
|
71
|
+
* Asset qty
|
|
72
|
+
*/
|
|
73
|
+
assetQty?: number;
|
|
70
74
|
/**
|
|
71
75
|
* Product level promotions
|
|
72
76
|
* 产品层次促销
|
|
@@ -317,6 +321,15 @@ export declare class ShoppingCart<T extends ShoppingCartItem> {
|
|
|
317
321
|
* @param item Shopping cart item
|
|
318
322
|
*/
|
|
319
323
|
updateDiscount(item: ShoppingCartItem): void;
|
|
324
|
+
/**
|
|
325
|
+
* Update asset item
|
|
326
|
+
* 更新资产项目
|
|
327
|
+
* @param id Product id
|
|
328
|
+
* @param qty Asset qty
|
|
329
|
+
* @param itemCreator New item creator
|
|
330
|
+
* @returns Updated or not
|
|
331
|
+
*/
|
|
332
|
+
updateAssetItem(id: T['id'], assetQty: number | undefined, itemCreator?: () => Omit<T, 'id' | 'price' | 'assetQty' | 'subtotal' | 'discount' | 'promotions'>): boolean;
|
|
320
333
|
/**
|
|
321
334
|
* Update item
|
|
322
335
|
* 更新项目
|
|
@@ -358,6 +358,54 @@ export class ShoppingCart {
|
|
|
358
358
|
updateDiscount(item) {
|
|
359
359
|
item.discount = item.promotions.sum('amount');
|
|
360
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* Update asset item
|
|
363
|
+
* 更新资产项目
|
|
364
|
+
* @param id Product id
|
|
365
|
+
* @param qty Asset qty
|
|
366
|
+
* @param itemCreator New item creator
|
|
367
|
+
* @returns Updated or not
|
|
368
|
+
*/
|
|
369
|
+
updateAssetItem(id, assetQty, itemCreator) {
|
|
370
|
+
var _a;
|
|
371
|
+
if (assetQty == null || assetQty <= 0)
|
|
372
|
+
assetQty = 1;
|
|
373
|
+
const index = this.items.findIndex((item) => item.id === id);
|
|
374
|
+
if (index === -1) {
|
|
375
|
+
// New
|
|
376
|
+
if (itemCreator) {
|
|
377
|
+
const price = this.prices[id];
|
|
378
|
+
const data = itemCreator();
|
|
379
|
+
const qty = data.qty;
|
|
380
|
+
const newItem = {
|
|
381
|
+
...data,
|
|
382
|
+
id,
|
|
383
|
+
price,
|
|
384
|
+
subtotal: price * qty * assetQty,
|
|
385
|
+
discount: 0,
|
|
386
|
+
promotions: Array()
|
|
387
|
+
};
|
|
388
|
+
this.addItem(newItem);
|
|
389
|
+
}
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
// Update
|
|
394
|
+
const item = this.items[index];
|
|
395
|
+
// Price may be cached first
|
|
396
|
+
const price = (_a = this.prices[id]) !== null && _a !== void 0 ? _a : item.price;
|
|
397
|
+
const qty = item.qty;
|
|
398
|
+
const newItem = {
|
|
399
|
+
...item,
|
|
400
|
+
price,
|
|
401
|
+
subtotal: price * qty * assetQty,
|
|
402
|
+
discount: 0
|
|
403
|
+
};
|
|
404
|
+
this.items.splice(index, 1, newItem);
|
|
405
|
+
this.doChange('update', [item, newItem]);
|
|
406
|
+
}
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
361
409
|
/**
|
|
362
410
|
* Update item
|
|
363
411
|
* 更新项目
|
|
@@ -380,12 +428,13 @@ export class ShoppingCart {
|
|
|
380
428
|
// New
|
|
381
429
|
if (itemCreator) {
|
|
382
430
|
const price = this.prices[id];
|
|
431
|
+
const data = itemCreator();
|
|
383
432
|
const newItem = {
|
|
384
|
-
...
|
|
433
|
+
...data,
|
|
385
434
|
id,
|
|
386
435
|
price,
|
|
387
436
|
qty,
|
|
388
|
-
subtotal: price * qty,
|
|
437
|
+
subtotal: price * qty * (data.assetQty || 1),
|
|
389
438
|
discount: 0,
|
|
390
439
|
promotions: Array()
|
|
391
440
|
};
|
|
@@ -402,7 +451,7 @@ export class ShoppingCart {
|
|
|
402
451
|
...item,
|
|
403
452
|
qty,
|
|
404
453
|
price,
|
|
405
|
-
subtotal: price * qty,
|
|
454
|
+
subtotal: price * qty * (item.assetQty || 1),
|
|
406
455
|
discount: 0
|
|
407
456
|
};
|
|
408
457
|
this.items.splice(index, 1, newItem);
|
|
@@ -421,7 +470,12 @@ export class ShoppingCart {
|
|
|
421
470
|
if (index !== -1) {
|
|
422
471
|
const item = this.items[index];
|
|
423
472
|
const qty = item.qty;
|
|
424
|
-
const
|
|
473
|
+
const assetQty = item.assetQty || 1;
|
|
474
|
+
const newItem = {
|
|
475
|
+
...item,
|
|
476
|
+
price,
|
|
477
|
+
subtotal: price * qty * assetQty
|
|
478
|
+
};
|
|
425
479
|
this.items.splice(index, 1, newItem);
|
|
426
480
|
this.doChange('update', [item, newItem]);
|
|
427
481
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.60",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"@babel/plugin-transform-runtime": "^7.23.2",
|
|
64
64
|
"@babel/preset-env": "^7.23.2",
|
|
65
65
|
"@babel/runtime-corejs3": "^7.23.2",
|
|
66
|
-
"@types/crypto-js": "^4.1.
|
|
67
|
-
"@types/jest": "^29.5.
|
|
66
|
+
"@types/crypto-js": "^4.1.3",
|
|
67
|
+
"@types/jest": "^29.5.6",
|
|
68
68
|
"jest": "^29.7.0",
|
|
69
69
|
"jest-environment-jsdom": "^29.7.0",
|
|
70
70
|
"ts-jest": "^29.1.1",
|
|
@@ -77,6 +77,11 @@ export type ShoppingCartItemBase = {
|
|
|
77
77
|
*/
|
|
78
78
|
qty: number;
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Asset qty
|
|
82
|
+
*/
|
|
83
|
+
assetQty?: number;
|
|
84
|
+
|
|
80
85
|
/**
|
|
81
86
|
* Product level promotions
|
|
82
87
|
* 产品层次促销
|
|
@@ -571,6 +576,63 @@ export class ShoppingCart<T extends ShoppingCartItem> {
|
|
|
571
576
|
item.discount = item.promotions.sum('amount');
|
|
572
577
|
}
|
|
573
578
|
|
|
579
|
+
/**
|
|
580
|
+
* Update asset item
|
|
581
|
+
* 更新资产项目
|
|
582
|
+
* @param id Product id
|
|
583
|
+
* @param qty Asset qty
|
|
584
|
+
* @param itemCreator New item creator
|
|
585
|
+
* @returns Updated or not
|
|
586
|
+
*/
|
|
587
|
+
updateAssetItem(
|
|
588
|
+
id: T['id'],
|
|
589
|
+
assetQty: number | undefined,
|
|
590
|
+
itemCreator?: () => Omit<
|
|
591
|
+
T,
|
|
592
|
+
'id' | 'price' | 'assetQty' | 'subtotal' | 'discount' | 'promotions'
|
|
593
|
+
>
|
|
594
|
+
) {
|
|
595
|
+
if (assetQty == null || assetQty <= 0) assetQty = 1;
|
|
596
|
+
|
|
597
|
+
const index = this.items.findIndex((item) => item.id === id);
|
|
598
|
+
if (index === -1) {
|
|
599
|
+
// New
|
|
600
|
+
if (itemCreator) {
|
|
601
|
+
const price = this.prices[id];
|
|
602
|
+
const data = itemCreator();
|
|
603
|
+
const qty = data.qty;
|
|
604
|
+
const newItem = {
|
|
605
|
+
...data,
|
|
606
|
+
id,
|
|
607
|
+
price,
|
|
608
|
+
subtotal: price * qty * assetQty,
|
|
609
|
+
discount: 0,
|
|
610
|
+
promotions: Array<ShoppingPromotion>()
|
|
611
|
+
} as T;
|
|
612
|
+
this.addItem(newItem);
|
|
613
|
+
}
|
|
614
|
+
return false;
|
|
615
|
+
} else {
|
|
616
|
+
// Update
|
|
617
|
+
const item = this.items[index];
|
|
618
|
+
|
|
619
|
+
// Price may be cached first
|
|
620
|
+
const price = this.prices[id] ?? item.price;
|
|
621
|
+
const qty = item.qty;
|
|
622
|
+
|
|
623
|
+
const newItem = {
|
|
624
|
+
...item,
|
|
625
|
+
price,
|
|
626
|
+
subtotal: price * qty * assetQty,
|
|
627
|
+
discount: 0
|
|
628
|
+
};
|
|
629
|
+
this.items.splice(index, 1, newItem);
|
|
630
|
+
this.doChange('update', [item, newItem]);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
return true;
|
|
634
|
+
}
|
|
635
|
+
|
|
574
636
|
/**
|
|
575
637
|
* Update item
|
|
576
638
|
* 更新项目
|
|
@@ -598,12 +660,13 @@ export class ShoppingCart<T extends ShoppingCartItem> {
|
|
|
598
660
|
// New
|
|
599
661
|
if (itemCreator) {
|
|
600
662
|
const price = this.prices[id];
|
|
663
|
+
const data = itemCreator();
|
|
601
664
|
const newItem = {
|
|
602
|
-
...
|
|
665
|
+
...data,
|
|
603
666
|
id,
|
|
604
667
|
price,
|
|
605
668
|
qty,
|
|
606
|
-
subtotal: price * qty,
|
|
669
|
+
subtotal: price * qty * (data.assetQty || 1),
|
|
607
670
|
discount: 0,
|
|
608
671
|
promotions: Array<ShoppingPromotion>()
|
|
609
672
|
} as T;
|
|
@@ -620,7 +683,7 @@ export class ShoppingCart<T extends ShoppingCartItem> {
|
|
|
620
683
|
...item,
|
|
621
684
|
qty,
|
|
622
685
|
price,
|
|
623
|
-
subtotal: price * qty,
|
|
686
|
+
subtotal: price * qty * (item.assetQty || 1),
|
|
624
687
|
discount: 0
|
|
625
688
|
};
|
|
626
689
|
this.items.splice(index, 1, newItem);
|
|
@@ -642,7 +705,12 @@ export class ShoppingCart<T extends ShoppingCartItem> {
|
|
|
642
705
|
if (index !== -1) {
|
|
643
706
|
const item = this.items[index];
|
|
644
707
|
const qty = item.qty;
|
|
645
|
-
const
|
|
708
|
+
const assetQty = item.assetQty || 1;
|
|
709
|
+
const newItem = {
|
|
710
|
+
...item,
|
|
711
|
+
price,
|
|
712
|
+
subtotal: price * qty * assetQty
|
|
713
|
+
};
|
|
646
714
|
this.items.splice(index, 1, newItem);
|
|
647
715
|
this.doChange('update', [item, newItem]);
|
|
648
716
|
}
|