@@ -60,31 +60,36 @@ export const getFormattedCart = (data) => {
60
60
61
61
let i = 0 ;
62
62
givenProducts . forEach ( ( ) => {
63
- const givenProduct = givenProducts [ parseInt ( i , 10 ) ] . product ;
63
+ const givenProduct = givenProducts [ parseInt ( i , 10 ) ] . product ;
64
64
const product = { } ;
65
65
// Convert price to a float value
66
- const convertedCurrency = givenProducts [ parseInt ( i , 10 ) ] . total . replace ( / [ ^ 0 - 9 . - ] + / g, '' ) ;
66
+ const convertedCurrency = givenProducts [ parseInt ( i , 10 ) ] . total . replace (
67
+ / [ ^ 0 - 9 . - ] + / g,
68
+ ''
69
+ ) ;
67
70
68
71
product . productId = givenProduct . productId ;
69
- product . cartKey = givenProducts [ parseInt ( i , 10 ) ] . key ;
72
+ product . cartKey = givenProducts [ parseInt ( i , 10 ) ] . key ;
70
73
product . name = givenProduct . name ;
71
- product . qty = givenProducts [ parseInt ( i , 10 ) ] . quantity ;
74
+ product . qty = givenProducts [ parseInt ( i , 10 ) ] . quantity ;
72
75
product . price = convertedCurrency / product . qty ;
73
- product . totalPrice = givenProducts [ parseInt ( i , 10 ) ] . total ;
76
+ product . totalPrice = givenProducts [ parseInt ( i , 10 ) ] . total ;
74
77
// Ensure we can add products without images to the cart
75
- givenProduct . image
76
- ? ( product . image = {
77
- sourceUrl : givenProduct . image . sourceUrl ,
78
- srcSet : givenProduct . image . srcSet ,
79
- title : givenProduct . image . title ,
80
- } )
81
- : ( product . image = {
82
- sourceUrl : WOO_CONFIG . PLACEHOLDER_SMALL_IMAGE_URL ,
83
- srcSet : WOO_CONFIG . PLACEHOLDER_SMALL_IMAGE_URL ,
84
- title : givenProduct . name ,
85
- } ) ;
86
-
87
- totalProductsCount += givenProducts [ parseInt ( i , 10 ) ] . quantity ;
78
+ if ( givenProduct . image ) {
79
+ product . image = {
80
+ sourceUrl : givenProduct . image . sourceUrl ,
81
+ srcSet : givenProduct . image . srcSet ,
82
+ title : givenProduct . image . title ,
83
+ } ;
84
+ } else {
85
+ product . image = {
86
+ sourceUrl : WOO_CONFIG . PLACEHOLDER_SMALL_IMAGE_URL ,
87
+ srcSet : WOO_CONFIG . PLACEHOLDER_SMALL_IMAGE_URL ,
88
+ title : givenProduct . name ,
89
+ } ;
90
+ }
91
+
92
+ totalProductsCount += givenProducts [ parseInt ( i , 10 ) ] . quantity ;
88
93
// Push each item into the products array.
89
94
formattedCart . products . push ( product ) ;
90
95
i ++ ;
0 commit comments