Skip to content

Commit 92cb3c6

Browse files
committed
Fix cart
1 parent bf3850a commit 92cb3c6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

utils/functions/functions.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ export const getFormattedCart = (data) => {
8585
return formattedCart;
8686
}
8787
const givenProducts = data.cart.contents.nodes;
88+
8889
// Create an empty object.
8990
formattedCart = {};
9091
formattedCart.products = [];
9192
let totalProductsCount = 0;
9293
let i = 0;
9394
givenProducts.forEach(() => {
94-
const givenProduct = givenProducts[parseInt(i, 10)].product;
95+
const givenProduct = givenProducts[parseInt(i, 10)].product.node;
96+
9597
const product = {};
9698
// Convert price to a float value
9799
const convertedCurrency = givenProducts[parseInt(i, 10)].total.replace(
@@ -101,12 +103,14 @@ export const getFormattedCart = (data) => {
101103

102104
product.productId = givenProduct.productId;
103105
product.cartKey = givenProducts[parseInt(i, 10)].key;
106+
104107
product.name = givenProduct.name;
108+
105109
product.qty = givenProducts[parseInt(i, 10)].quantity;
106110
product.price = convertedCurrency / product.qty;
107111
product.totalPrice = givenProducts[parseInt(i, 10)].total;
108112
// Ensure we can add products without images to the cart
109-
product.image = givenProduct.image
113+
product.image = givenProduct.image.sourceUrl
110114
? {
111115
sourceUrl: givenProduct.image.sourceUrl,
112116
srcSet: givenProduct.image.srcSet,
@@ -125,6 +129,7 @@ export const getFormattedCart = (data) => {
125129
});
126130
formattedCart.totalProductsCount = totalProductsCount;
127131
formattedCart.totalProductsPrice = data.cart.total;
132+
128133
return formattedCart;
129134
};
130135

0 commit comments

Comments
 (0)