11import { v4 } from 'uuid' ;
22
3+ import { WOO_CONFIG } from 'utils/config/nextConfig' ;
4+
35/**
46 * Convert price from string to floating value and convert it to use two decimals
57 * @param {String } string
@@ -193,6 +195,8 @@ export const getFormattedCart = (data) => {
193195
194196 const givenProducts = data . cart . contents . nodes ;
195197
198+ console . log ( givenProducts ) ;
199+
196200 // Create an empty object.
197201 formattedCart = { } ;
198202 formattedCart . products = [ ] ;
@@ -211,11 +215,18 @@ export const getFormattedCart = (data) => {
211215 product . qty = givenProducts [ i ] . quantity ;
212216 product . price = convertedCurrency / product . qty ;
213217 product . totalPrice = givenProducts [ i ] . total ;
214- product . image = {
215- sourceUrl : givenProduct . image . sourceUrl ,
216- srcSet : givenProduct . image . srcSet ,
217- title : givenProduct . image . title ,
218- } ;
218+ // Ensure we can add products without images to the cart
219+ givenProduct . image
220+ ? ( product . image = {
221+ sourceUrl : givenProduct . image . sourceUrl ,
222+ srcSet : givenProduct . image . srcSet ,
223+ title : givenProduct . image . title ,
224+ } )
225+ : ( product . image = {
226+ sourceUrl : WOO_CONFIG . PLACEHOLDER_SMALL_IMAGE_URL ,
227+ srcSet : WOO_CONFIG . PLACEHOLDER_SMALL_IMAGE_URL ,
228+ title : givenProduct . name ,
229+ } ) ;
219230
220231 totalProductsCount += givenProducts [ i ] . quantity ;
221232 // Push each item into the products array.
0 commit comments