@@ -85,13 +85,15 @@ export const getFormattedCart = (data) => {
85
85
return formattedCart ;
86
86
}
87
87
const givenProducts = data . cart . contents . nodes ;
88
+
88
89
// Create an empty object.
89
90
formattedCart = { } ;
90
91
formattedCart . products = [ ] ;
91
92
let totalProductsCount = 0 ;
92
93
let i = 0 ;
93
94
givenProducts . forEach ( ( ) => {
94
- const givenProduct = givenProducts [ parseInt ( i , 10 ) ] . product ;
95
+ const givenProduct = givenProducts [ parseInt ( i , 10 ) ] . product . node ;
96
+
95
97
const product = { } ;
96
98
// Convert price to a float value
97
99
const convertedCurrency = givenProducts [ parseInt ( i , 10 ) ] . total . replace (
@@ -101,12 +103,14 @@ export const getFormattedCart = (data) => {
101
103
102
104
product . productId = givenProduct . productId ;
103
105
product . cartKey = givenProducts [ parseInt ( i , 10 ) ] . key ;
106
+
104
107
product . name = givenProduct . name ;
108
+
105
109
product . qty = givenProducts [ parseInt ( i , 10 ) ] . quantity ;
106
110
product . price = convertedCurrency / product . qty ;
107
111
product . totalPrice = givenProducts [ parseInt ( i , 10 ) ] . total ;
108
112
// Ensure we can add products without images to the cart
109
- product . image = givenProduct . image
113
+ product . image = givenProduct . image . sourceUrl
110
114
? {
111
115
sourceUrl : givenProduct . image . sourceUrl ,
112
116
srcSet : givenProduct . image . srcSet ,
@@ -125,6 +129,7 @@ export const getFormattedCart = (data) => {
125
129
} ) ;
126
130
formattedCart . totalProductsCount = totalProductsCount ;
127
131
formattedCart . totalProductsPrice = data . cart . total ;
132
+
128
133
return formattedCart ;
129
134
} ;
130
135
0 commit comments