@@ -39,7 +39,7 @@ export const useCart = defineStore("cartState", {
39
39
) ;
40
40
41
41
if ( foundProductInCartIndex > - 1 ) {
42
- this . cart [ foundProductInCartIndex ] . quantity += newCartItem . quantity ;
42
+ this . cart [ foundProductInCartIndex ] . quantity += 1 ;
43
43
} else {
44
44
// We need to construct a cart item that matches the expected structure in `this.cart`
45
45
const productCopy = {
@@ -48,6 +48,7 @@ export const useCart = defineStore("cartState", {
48
48
price : newCartItem . total , // Assuming 'total' is the price for one item
49
49
slug : newCartItem . product . node . slug ,
50
50
} ;
51
+
51
52
this . cart . push ( productCopy ) ;
52
53
}
53
54
} else {
@@ -80,12 +81,22 @@ export const useCart = defineStore("cartState", {
80
81
getCartTotal ( ) {
81
82
const currencySymbol = useRuntimeConfig ( ) . public . currencySymbol || "kr" ;
82
83
83
- return this . cart . reduce (
84
- ( total , product ) =>
85
- total +
86
- Number ( product . price . replace ( currencySymbol , "" ) ) * product . quantity ,
87
- 0
88
- ) ;
84
+ const total = this . cart . reduce ( ( total , product ) => {
85
+ // Assuming product.price is a string that includes the currency symbol
86
+ const numericPrice = product . price
87
+ . replace ( currencySymbol , "" )
88
+ . replace ( / [ ^ 0 - 9 . ] + / g, "" ) ;
89
+
90
+ // Convert the cleaned string to a floating-point number
91
+ const price = parseFloat ( numericPrice ) ;
92
+
93
+ const productTotal = price * product . quantity ;
94
+
95
+ return total + productTotal ;
96
+ } , 0 ) ;
97
+
98
+ // Format the total with the currency symbol and return it
99
+ return `${ currencySymbol } ${ total . toFixed ( 2 ) } ` ;
89
100
} ,
90
101
} ,
91
102
persist : true ,
0 commit comments