Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add sponsored products on autocomplete #197

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading