@@ -154,9 +154,15 @@ export const getFormattedCart = (data: IFormattedCartProps) => {
154154 return ;
155155 }
156156
157+ // Add console logs to debug the data
158+ console . log ( 'Raw cart data:' , data ) ;
159+ console . log ( 'Given products:' , givenProducts ) ;
160+
157161 // Map products to the correct format
158162 formattedCart . products = givenProducts . map ( ( item ) => {
163+ console . log ( 'Processing item:' , item ) ;
159164 const givenProduct = item . product . node ;
165+ console . log ( 'Product node:' , givenProduct ) ;
160166
161167 // Convert price to a float value
162168 const convertedCurrency = item . total . replace ( / [ ^ 0 - 9 . - ] + / g, '' ) ;
@@ -165,14 +171,14 @@ export const getFormattedCart = (data: IFormattedCartProps) => {
165171 totalProductsCount += item . quantity ;
166172
167173 // Create a new product object for each item
168- return {
169- productId : givenProduct . productId ,
174+ const formattedProduct = {
175+ productId : givenProduct . databaseId , // Changed from productId to databaseId
170176 cartKey : item . key ,
171177 name : givenProduct . name ,
172178 qty : item . quantity ,
173179 price : Number ( convertedCurrency ) / item . quantity ,
174180 totalPrice : item . total ,
175- image : givenProduct . image . sourceUrl
181+ image : givenProduct . image ? .sourceUrl
176182 ? {
177183 sourceUrl : givenProduct . image . sourceUrl ,
178184 srcSet : givenProduct . image . srcSet ,
@@ -182,9 +188,13 @@ export const getFormattedCart = (data: IFormattedCartProps) => {
182188 sourceUrl : process . env . NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL ,
183189 srcSet : process . env . NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL ,
184190 title : givenProduct . name ,
185- } ,
191+ }
186192 } ;
193+ console . log ( 'Formatted product:' , formattedProduct ) ;
194+ return formattedProduct ;
187195 } ) ;
196+
197+ console . log ( 'Final formatted cart:' , formattedCart ) ;
188198 formattedCart . totalProductsCount = totalProductsCount ;
189199 formattedCart . totalProductsPrice = data . cart . total ;
190200
0 commit comments