@@ -7,6 +7,7 @@ import getFullName from "../../../Lib/Customers/getFullName";
7
7
import getProductById from "../../../Lib/Products/getProductById" ;
8
8
import UseStyles from "../General/UseStyles" ;
9
9
import printOrderProductTable from "../Methods/OrderProducts.print" ;
10
+ import { convertCurrency } from "../../../Lib/Currencies" ;
10
11
11
12
export default async ( order : IOrder , customer : ICustomer ) => await UseStyles ( stripIndents `
12
13
<div>
@@ -18,7 +19,7 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
18
19
<strong>Order number:</strong> ${ order . id }
19
20
</p>
20
21
21
- ${ await printOrderProductTable ( order ) }
22
+ ${ await printOrderProductTable ( order , customer ) }
22
23
23
24
<p>
24
25
<strong>
@@ -27,6 +28,10 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
27
28
${ ( await Promise . all ( order . products . map ( async ( product ) =>
28
29
{
29
30
const p = await getProductById ( product . product_id as any ) ;
31
+ if ( ! p ) return 0 ;
32
+
33
+ if ( p ?. currency . toUpperCase ( ) !== customer . currency . toUpperCase ( ) )
34
+ p . price = await convertCurrency ( p ?. price , p ?. currency , order . currency ) ;
30
35
// check if configurable options are added
31
36
const p_c = [ ] ;
32
37
for await ( const conf of product ?. configurable_options ?? [ ] )
@@ -35,10 +40,15 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
35
40
id : conf . id ,
36
41
} ) ;
37
42
if ( c )
43
+ {
44
+ // Check if same currency
45
+ if ( p ?. currency . toUpperCase ( ) !== customer . currency . toUpperCase ( ) )
46
+ // Convert to customer currency
47
+ c . options [ conf . option_index ] . price = await convertCurrency ( c . options [ conf . option_index ] . price , p ?. currency , customer . currency ) ;
38
48
p_c . push ( c . options [ conf . option_index ] . price ) ;
49
+ }
39
50
}
40
51
41
-
42
52
if ( ! p )
43
53
return 0 ;
44
54
@@ -47,7 +57,7 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
47
57
total += p_c . reduce ( ( a , b ) => a + b ) ;
48
58
49
59
return total ;
50
- } ) ) ) . reduce ( ( acc , cur ) => acc + cur , 0 ) } ${ ( order . currency ) . toLocaleUpperCase ( ) }
60
+ } ) ) ) . reduce ( ( acc , cur ) => acc + cur , 0 ) . toFixed ( 2 ) } ${ ( order . currency ) . toLocaleUpperCase ( ) }
51
61
</p>
52
62
53
63
${ CPG_Customer_Panel_Domain ? `
0 commit comments