@@ -69,7 +69,7 @@ async function fetchProductFromIntsch(
6969 const { field, value } = identifier
7070
7171 // Get locale from context (fallback)
72- const defaultLocale = ctx . vtex . tenant ?. locale || ctx . vtex . locale
72+ const defaultLocale = ctx . vtex . tenant ?. locale ?? ctx . vtex . locale
7373
7474 // Default salesChannel from args
7575 let finalSalesChannel = salesChannel ? `${ salesChannel } ` : undefined
@@ -170,9 +170,9 @@ export async function resolveProduct(
170170 const args =
171171 rawArgs && isValidProductIdentifier ( rawArgs . identifier )
172172 ? rawArgs
173- : { identifier : { field : 'slug' , value : rawArgs . slug ! } }
173+ : { identifier : { field : 'slug' , value : rawArgs . slug ?? '' } }
174174
175- if ( ! args . identifier ) {
175+ if ( ! args . identifier ?. value ) {
176176 throw new Error ( 'No product identifier provided' )
177177 }
178178
@@ -205,7 +205,7 @@ export async function resolveProduct(
205205 return null
206206 }
207207
208- const product = products [ 0 ]
208+ const [ product ] = products
209209
210210 return product
211211 } catch ( error ) {
@@ -266,7 +266,7 @@ async function fetchProductsByIdentifierFromIntsch(
266266 const { field, values, salesChannel, regionId } = args
267267
268268 // Get locale from context (fallback)
269- const defaultLocale = ctx . vtex . tenant ?. locale || ctx . vtex . locale
269+ const defaultLocale = ctx . vtex . tenant ?. locale ?? ctx . vtex . locale
270270
271271 // Default salesChannel from args
272272 let finalSalesChannel = salesChannel ? `${ salesChannel } ` : undefined
@@ -334,12 +334,20 @@ export async function resolveProductsByIdentifier(
334334
335335 // Check if current account should use intsch directly
336336 if ( shouldUseNewPDPEndpoint ) {
337- products = await fetchProductsByIdentifierFromIntsch ( ctx , args , vtexSegment )
337+ products = await fetchProductsByIdentifierFromIntsch (
338+ ctx ,
339+ args ,
340+ vtexSegment
341+ )
338342 } else {
339- products = await fetchProductsByIdentifierFromSearch ( ctx , args , vtexSegment )
343+ products = await fetchProductsByIdentifierFromSearch (
344+ ctx ,
345+ args ,
346+ vtexSegment
347+ )
340348 }
341349
342- return products
350+ return products
343351 } catch ( error ) {
344352 ctx . vtex . logger . error ( {
345353 message : 'Error fetching products by identifier' ,
0 commit comments