@@ -48,7 +48,7 @@ const CartContents = () => {
48
48
} ) ;
49
49
50
50
const handleRemoveProductClick = ( cartKey : string , products : IProductRootObject [ ] ) => {
51
- if ( products . length ) {
51
+ if ( products ? .length ) {
52
52
const updatedItems = getUpdatedItems ( products , 0 , cartKey ) ;
53
53
updateCart ( {
54
54
variables : {
@@ -71,10 +71,15 @@ const CartContents = () => {
71
71
72
72
const cartTotal = data ?. cart ?. total || '0' ;
73
73
74
+ const getUnitPrice = ( subtotal : string , quantity : number ) => {
75
+ const numericSubtotal = parseFloat ( subtotal . replace ( / [ ^ 0 - 9 . - ] + / g, "" ) ) ;
76
+ return isNaN ( numericSubtotal ) ? 'N/A' : ( numericSubtotal / quantity ) . toFixed ( 2 ) ;
77
+ } ;
78
+
74
79
return (
75
80
< div className = "container mx-auto px-4 py-8" >
76
81
< h1 className = "text-3xl font-bold mb-8" > Handlekurv</ h1 >
77
- { data ?. cart ?. contents ?. nodes . length ? (
82
+ { data ?. cart ?. contents ?. nodes ? .length ? (
78
83
< >
79
84
< div className = "bg-white rounded-lg shadow-md p-6 mb-8" >
80
85
{ data . cart . contents . nodes . map ( ( item : IProductRootObject ) => (
@@ -90,13 +95,8 @@ const CartContents = () => {
90
95
</ div >
91
96
< div className = "flex-grow ml-4" >
92
97
< h2 className = "text-lg font-semibold" > { item . product . node . name } </ h2 >
93
- { /* Display the price if available, otherwise show a placeholder */ }
94
98
< p className = "text-gray-600" >
95
- { item . product . node . priceHtml ? (
96
- < span dangerouslySetInnerHTML = { { __html : item . product . node . priceHtml } } />
97
- ) : (
98
- 'Price not available'
99
- ) }
99
+ Enhetspris: kr { getUnitPrice ( item . subtotal , item . quantity ) }
100
100
</ p >
101
101
</ div >
102
102
< div className = "flex items-center" >
0 commit comments