@@ -39,7 +39,7 @@ export const useCart = defineStore("cartState", {
3939 ) ;
4040
4141 if ( foundProductInCartIndex > - 1 ) {
42- this . cart [ foundProductInCartIndex ] . quantity += newCartItem . quantity ;
42+ this . cart [ foundProductInCartIndex ] . quantity += 1 ;
4343 } else {
4444 // We need to construct a cart item that matches the expected structure in `this.cart`
4545 const productCopy = {
@@ -48,6 +48,7 @@ export const useCart = defineStore("cartState", {
4848 price : newCartItem . total , // Assuming 'total' is the price for one item
4949 slug : newCartItem . product . node . slug ,
5050 } ;
51+
5152 this . cart . push ( productCopy ) ;
5253 }
5354 } else {
@@ -80,12 +81,22 @@ export const useCart = defineStore("cartState", {
8081 getCartTotal ( ) {
8182 const currencySymbol = useRuntimeConfig ( ) . public . currencySymbol || "kr" ;
8283
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 ) } ` ;
89100 } ,
90101 } ,
91102 persist : true ,
0 commit comments