Skip to content

Commit ccfd78d

Browse files
Added integration between shouldUseNewPDPEndpoint flag and productRecommendations
1 parent 60815bc commit ccfd78d

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

node/clients/search.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import {
22
AppClient,
3+
CacheType,
34
InstanceOptions,
45
IOContext,
56
RequestConfig,
67
SegmentData,
7-
CacheType,
88
} from '@vtex/api'
99
import { stringify } from 'qs'
1010

1111
import {
12-
searchEncodeURI,
1312
SearchCrossSellingTypes,
13+
searchEncodeURI,
1414
} from '../resolvers/search/utils'
1515

1616
interface AutocompleteArgs {
@@ -308,11 +308,13 @@ export class Search extends AppClient {
308308
metric: 'search-category',
309309
})
310310

311-
public crossSelling = (id: string, type: SearchCrossSellingTypes, groupByProduct = true) =>
311+
public crossSelling = (id: string, type: SearchCrossSellingTypes, groupByProduct = true, acceptLanguage?: string) =>
312312
this.get<SearchProduct[]>(
313313
`/pub/products/crossselling/${type}/${id}?groupByProduct=${groupByProduct}`,
314314
{
315315
metric: 'search-crossSelling',
316+
// This Accept Language header is used to request the cross selling products in the desired language from new dataplane endpoint
317+
headers: acceptLanguage ? { 'Accept-Language': acceptLanguage } : {}
316318
}
317319
)
318320

node/resolvers/search/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ import {
77
} from '../../commons/compatibility-layer'
88
import { getWorkspaceSearchParamsFromStorage } from '../../routes/workspaceSearchParams'
99
import {
10-
buildVtexSegment,
10+
fetchAutocompleteSuggestions,
11+
fetchCorrection,
12+
fetchSearchSuggestions,
13+
fetchTopSearches,
14+
} from '../../services/autocomplete'
15+
import { fetchBanners } from '../../services/banners'
16+
import {
1117
ProductArgs,
1218
ProductIdentifier,
19+
buildVtexSegment,
1320
resolveProduct,
1421
} from '../../services/product'
22+
import { fetchAppSettings } from '../../services/settings'
23+
import { AdvertisementOptions, FacetsInput, ProductSearchInput, ProductsInput, SegmentData, SuggestionProductsArgs } from '../../typings/Search'
1524
import { shouldTranslateToTenantLocale } from '../../utils/i18n'
1625
import { resolvers as assemblyOptionResolvers } from './assemblyOption'
1726
import { resolvers as autocompleteResolvers } from './autocomplete'
@@ -39,14 +48,6 @@ import {
3948
getShippingOptionsFromSelectedFacets,
4049
validMapAndQuery,
4150
} from './utils'
42-
import {
43-
fetchAutocompleteSuggestions,
44-
fetchTopSearches,
45-
fetchSearchSuggestions,
46-
fetchCorrection,
47-
} from '../../services/autocomplete'
48-
import { fetchBanners } from '../../services/banners'
49-
import { AdvertisementOptions, FacetsInput, ProductSearchInput, ProductsInput, SegmentData, SuggestionProductsArgs } from '../../typings/Search'
5051

5152
enum CrossSellingInput {
5253
view = 'view',
@@ -597,6 +598,8 @@ export const queries = {
597598
if (identifier == null || type == null) {
598599
throw new UserInputError('Wrong input provided')
599600
}
601+
602+
const { shouldUseNewPDPEndpoint } = await fetchAppSettings(ctx)
600603
const searchType = inputToSearchCrossSelling[type]
601604
let productId = identifier.value
602605
if (identifier.field !== 'id') {
@@ -607,10 +610,15 @@ export const queries = {
607610
const groupByProduct =
608611
groupBy === CrossSellingGroupByInput.PRODUCT ? true : false
609612

613+
if (shouldUseNewPDPEndpoint) {
614+
ctx.translated = true
615+
}
616+
610617
const products = await ctx.clients.search.crossSelling(
611618
productId,
612619
searchType,
613-
groupByProduct
620+
groupByProduct,
621+
shouldUseNewPDPEndpoint ? ctx.vtex.locale : undefined
614622
)
615623

616624
searchFirstElements(products, 0, ctx.clients.search)

0 commit comments

Comments
 (0)