ts-glitter 19.2.7 → 19.2.9

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.
@@ -810,6 +810,9 @@ export class Shopping {
810
810
  };
811
811
 
812
812
  const processProduct = async (product: any) => {
813
+ if(!product || !product.content){
814
+ return
815
+ }
813
816
  const createPriceMap = (type: MultiSaleType): Record<string, Map<string, number>> => {
814
817
  return Object.fromEntries(
815
818
  product.content.multi_sale_price
@@ -950,8 +953,14 @@ export class Shopping {
950
953
  };
951
954
 
952
955
  if (Array.isArray(products.data)) {
956
+ products.data=products.data.filter((dd)=>{
957
+ return dd && dd.content
958
+ })
953
959
  await Promise.all(products.data.map(processProduct));
954
960
  } else {
961
+ if((products.data) && !products.data.content){
962
+ products.data=undefined
963
+ }
955
964
  await processProduct(products.data);
956
965
  }
957
966
 
@@ -1022,6 +1031,9 @@ export class Shopping {
1022
1031
  userID: string;
1023
1032
  viewSource: string;
1024
1033
  }) {
1034
+ if(!json.product.content){
1035
+ return []
1036
+ }
1025
1037
  const id = `${json.product.id}`;
1026
1038
  const collection = json.product.content.collection || [];
1027
1039
  const userData = json.userData;
@@ -1867,7 +1879,6 @@ export class Shopping {
1867
1879
  let price = 0;
1868
1880
  let show_understocking = false;
1869
1881
  let stock = Infinity;
1870
-
1871
1882
  if (prod.specs.length) {
1872
1883
  price = item.spec.reduce((total: number, spec: any, index: number) => {
1873
1884
  const dpe = prod.specs[index].option.find((dd: any) => dd.title === spec);
@@ -2813,14 +2824,20 @@ export class Shopping {
2813
2824
  // await fb.sendCustomerFB('auto-fb-order-create', carData.orderID, carData.customer_info.fb_id);
2814
2825
  // console.log('訂單FB訊息寄送成功');
2815
2826
  // }
2827
+ for (const email of new Set([carData.customer_info, carData.user_info].map((dd)=>{
2828
+ return dd && dd.email
2829
+ }))) {
2830
+ if (email) {
2831
+ AutoSendEmail.customerOrder(
2832
+ this.app,
2833
+ 'auto-email-order-create',
2834
+ carData.orderID,
2835
+ email,
2836
+ carData.language!!
2837
+ );
2838
+ }
2839
+ }
2816
2840
 
2817
- AutoSendEmail.customerOrder(
2818
- this.app,
2819
- 'auto-email-order-create',
2820
- carData.orderID,
2821
- carData.email,
2822
- carData.language!!
2823
- );
2824
2841
  await this.releaseVoucherHistory(carData.orderID, 1);
2825
2842
  checkPoint('default release checkout');
2826
2843
  return {
@@ -3571,13 +3588,20 @@ export class Shopping {
3571
3588
  if (prevStatus !== '-1' && orderData.orderStatus === '-1') {
3572
3589
 
3573
3590
  await this.resetStore(origin.orderData.lineItems);
3574
- await AutoSendEmail.customerOrder(
3575
- this.app,
3576
- 'auto-email-order-cancel-success',
3577
- orderData.orderID,
3578
- orderData.email,
3579
- orderData.language
3580
- );
3591
+
3592
+ for (const email of new Set([origin.orderData.customer_info, origin.orderData.user_info].map((dd)=>{
3593
+ return dd && dd.email
3594
+ }))) {
3595
+ if (email) {
3596
+ await AutoSendEmail.customerOrder(
3597
+ this.app,
3598
+ 'auto-email-order-cancel-success',
3599
+ orderData.orderID,
3600
+ email,
3601
+ orderData.language
3602
+ );
3603
+ }
3604
+ }
3581
3605
  //變成處理或已完成扣庫存
3582
3606
  } else if (prevStatus === '-1' && orderData.orderStatus !== '-1') {
3583
3607
  await this.resetStore(origin.orderData.lineItems, 'minus');
@@ -3802,14 +3826,17 @@ export class Shopping {
3802
3826
  const line = new LineMessage(this.app);
3803
3827
  messages.push(line.sendCustomerLine(`auto-line-${typeMap[type]}`, orderData.orderID, lineID));
3804
3828
  }
3805
- for (const data of [orderData.customer_info, orderData.user_info]) {
3806
- if (data.email) {
3829
+
3830
+ for (const email of new Set([orderData.customer_info, orderData.user_info].map((dd)=>{
3831
+ return dd && dd.email
3832
+ }))) {
3833
+ if (email) {
3807
3834
  messages.push(
3808
3835
  AutoSendEmail.customerOrder(
3809
3836
  this.app,
3810
3837
  `auto-email-${typeMap[type]}`,
3811
3838
  orderData.orderID,
3812
- data.email,
3839
+ email,
3813
3840
  orderData.language
3814
3841
  )
3815
3842
  );
@@ -3928,7 +3955,14 @@ export class Shopping {
3928
3955
 
3929
3956
  // 訂單待核款信件通知
3930
3957
  new ManagerNotify(this.app).uploadProof({ orderData: orderData });
3931
- await AutoSendEmail.customerOrder(this.app, 'proof-purchase', order_id, orderData.email, orderData.language);
3958
+ for (const email of new Set([orderData.customer_info, orderData.user_info].map((dd)=>{
3959
+ return dd && dd.email
3960
+ }))) {
3961
+ if (email) {
3962
+ await AutoSendEmail.customerOrder(this.app, 'proof-purchase', order_id, email, orderData.language);
3963
+ }
3964
+ }
3965
+
3932
3966
 
3933
3967
  if (orderData.customer_info.phone) {
3934
3968
  let sns = new SMS(this.app);
@@ -4427,14 +4461,20 @@ export class Shopping {
4427
4461
  orderData: cartData.orderData,
4428
4462
  status: status,
4429
4463
  });
4464
+ for (const email of new Set([cartData.orderData.customer_info, cartData.orderData.user_info].map((dd)=>{
4465
+ return dd && dd.email
4466
+ }))) {
4467
+ if (email) {
4468
+ await AutoSendEmail.customerOrder(
4469
+ this.app,
4470
+ 'auto-email-payment-successful',
4471
+ order_id,
4472
+ email,
4473
+ cartData.orderData.language
4474
+ );
4475
+ }
4476
+ }
4430
4477
 
4431
- await AutoSendEmail.customerOrder(
4432
- this.app,
4433
- 'auto-email-payment-successful',
4434
- order_id,
4435
- cartData.email,
4436
- cartData.orderData.language
4437
- );
4438
4478
 
4439
4479
  if (cartData.orderData.customer_info.phone) {
4440
4480
  let sns = new SMS(this.app);