Skip to content

Commit 7e6c3d6

Browse files
committed
Fix products call
1 parent e744834 commit 7e6c3d6

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

node/clients/intsch/index.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { InstanceOptions, IOContext, JanusClient } from '@vtex/api'
1+
import type { InstanceOptions, IOContext } from '@vtex/api'
2+
import { JanusClient } from '@vtex/api'
23

3-
import {
4+
import type {
45
AutocompleteSuggestionsArgs,
56
AutocompleteSuggestionsResponse,
67
CorrectionArgs,
@@ -16,7 +17,7 @@ import {
1617
export class Intsch extends JanusClient implements IIntelligentSearchClient {
1718
private locale: string | undefined
1819

19-
public constructor(ctx: IOContext, options?: InstanceOptions) {
20+
constructor(ctx: IOContext, options?: InstanceOptions) {
2021
const env = ctx.production ? 'stable' : 'beta'
2122

2223
super(ctx, options, env)
@@ -25,20 +26,18 @@ export class Intsch extends JanusClient implements IIntelligentSearchClient {
2526

2627
this.locale = locale ?? tenant?.locale
2728
}
29+
2830
public fetchProduct(args: FetchProductArgs): Promise<FetchProductResponse> {
29-
return this.http.get(
30-
'/api/intelligent-search/v1/products',
31-
{
32-
params: {
33-
field: args.field,
34-
value: args.value,
35-
salesChannel: args.salesChannel,
36-
regionId: args.regionId,
37-
locale: args.locale,
38-
},
39-
metric: 'search-product-new',
40-
}
41-
)
31+
return this.http.get('/api/intelligent-search/v1/products', {
32+
params: {
33+
field: args.field,
34+
value: args.value,
35+
sc: args.salesChannel ?? 1,
36+
regionId: args.regionId,
37+
locale: args.locale,
38+
},
39+
metric: 'search-product-new',
40+
})
4241
}
4342

4443
public fetchAutocompleteSuggestions(

node/services/product.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@ async function fetchProductFromSearch(
3131
switch (field) {
3232
case 'id':
3333
return search.productById(value, vtexSegment, salesChannel)
34+
3435
case 'slug':
3536
return search.product(value, vtexSegment, salesChannel)
37+
3638
case 'ean':
3739
return search.productByEan(value, vtexSegment, salesChannel)
40+
3841
case 'reference':
3942
return search.productByReference(value, vtexSegment, salesChannel)
43+
4044
case 'sku':
4145
return search.productBySku(value, vtexSegment, salesChannel)
46+
4247
default:
4348
throw new Error(`Unsupported product identifier field: ${field}`)
4449
}
@@ -75,13 +80,13 @@ async function fetchProductFromIntsch(
7580
* Builds vtex segment token for product fetching
7681
*/
7782

78-
export function buildVtexSegment (
83+
export function buildVtexSegment(
7984
vtexSegment?: SegmentData,
8085
tradePolicy?: number,
8186
regionId?: string | null
8287
): string {
8388
const cookie = {
84-
regionId: regionId,
89+
regionId,
8590
channel: tradePolicy,
8691
utm_campaign: vtexSegment?.utm_campaign || '',
8792
utm_source: vtexSegment?.utm_source || '',
@@ -111,7 +116,7 @@ export async function fetchProduct(
111116
COMPARISON_SAMPLE_RATE,
112117
ctx.vtex.logger,
113118
{
114-
logPrefix: 'Product Fetching Comparison',
119+
logPrefix: 'Product Details',
115120
args: {
116121
identifier: args.identifier,
117122
salesChannel: args.salesChannel,
@@ -148,7 +153,7 @@ export async function resolveProduct(
148153
throw new Error('No product identifier provided')
149154
}
150155

151-
let cookie: SegmentData | undefined = ctx.vtex.segment
156+
const cookie: SegmentData | undefined = ctx.vtex.segment
152157
const salesChannel = rawArgs.salesChannel || cookie?.channel || 1
153158

154159
const vtexSegment =

0 commit comments

Comments
 (0)