Skip to content

Commit

Permalink
Merge pull request #197 from vtex-apps/feat/sponsored-products-on-aut…
Browse files Browse the repository at this point in the history
…ocomplete

Feature: add sponsored products on autocomplete
  • Loading branch information
hiagolcm authored Aug 20, 2024
2 parents ccaf585 + 6e5f32d commit c11ada3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Passes advertisement options on products suggestion query.

## [2.17.0] - 2024-05-06

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ interface TileListProps {
onSeeAllClick: (term: string) => void
HorizontalProductSummary?: React.ComponentType<{
product: Product
placement: string
actionOnClick: () => void
}>
}

const AUTOCOMPLETE_PLACEMENT = 'autocomplete'

const TileList: FC<TileListProps> = ({
term,
title,
Expand Down Expand Up @@ -72,6 +75,7 @@ const TileList: FC<TileListProps> = ({
HorizontalProductSummary ? (
<HorizontalProductSummary
product={productSummary}
placement={AUTOCOMPLETE_PLACEMENT}
actionOnClick={() => {
onProductClick(productSummary.productId, index, term)
}}
Expand All @@ -88,6 +92,7 @@ const TileList: FC<TileListProps> = ({
<ExtensionPoint
id="product-summary"
product={productSummary}
placement={AUTOCOMPLETE_PLACEMENT}
actionOnClick={() => {
onProductClick(productSummary.productId, index, term)
}}
Expand Down
10 changes: 9 additions & 1 deletion react/components/Autocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ interface AutoCompleteProps {
push: (data: any) => void
HorizontalProductSummary?: React.ComponentType<{
product: Product
placement: string
actionOnClick: () => void
}>
customPage?: string
Expand Down Expand Up @@ -309,6 +310,12 @@ class AutoComplete extends React.Component<
const session = await getSession(this.props.runtime.rootPath)
const shippingOptions =
session?.map((item: Record<string, string>) => item.value) ?? []
const advertisementOptions: AdvertisementOptions = {
showSponsored: true,
sponsoredCount: 2,
repeatSponsoredProducts: false,
advertisementPlacement: 'autocomplete',
}

const result = await this.client.suggestionProducts(
term,
Expand All @@ -319,7 +326,8 @@ class AutoComplete extends React.Component<
hideUnavailableItems,
orderBy,
this.props.maxSuggestedProducts || MAX_SUGGESTED_PRODUCTS_DEFAULT,
shippingOptions
shippingOptions,
advertisementOptions
)

if (!queryFromHover) {
Expand Down
7 changes: 7 additions & 0 deletions react/typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ declare global {
TotalValuePlusInterestRate: number
Value: number
}

interface AdvertisementOptions {
showSponsored?: boolean
sponsoredCount?: number
repeatSponsoredProducts?: boolean
advertisementPlacement?: string
}
}

export {}
4 changes: 3 additions & 1 deletion react/utils/biggy-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ export default class BiggyClient {
hideUnavailableItems = false,
orderBy?: string,
count?: number,
shippingOptions?: string[]
shippingOptions?: string[],
advertisementOptions?: AdvertisementOptions
): Promise<ApolloQueryResult<{ productSuggestions: IProductsOutput }>> {
return this.client.query({
query: suggestionProducts,
variables: {
simulationBehavior,
advertisementOptions,
hideUnavailableItems,
orderBy,
fullText: term,
Expand Down

0 comments on commit c11ada3

Please sign in to comment.