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

SAX-53 Get sponsored products in productSearch #658

Merged
merged 1 commit into from
Mar 7, 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]

### Changed

- Get sponsored products within the `productSearch` query

## [3.129.8] - 2024-03-06

### Fixed
Expand Down
5 changes: 4 additions & 1 deletion react/components/SearchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

const isCurrentDifferent = (ref, currentVal) => ref.current !== currentVal

const useShouldResetPage = (query, map, orderBy, priceRange) => {

Check warning on line 129 in react/components/SearchQuery.js

View workflow job for this annotation

GitHub Actions / Lint

Arrow function has too many parameters (4). Maximum allowed is 3
const queryRef = useRef(query)
const mapRef = useRef(map)
const orderByRef = useRef(orderBy)
Expand Down Expand Up @@ -155,7 +155,7 @@
operator,
searchState,
fullText
) => {

Check warning on line 158 in react/components/SearchQuery.js

View workflow job for this annotation

GitHub Actions / Lint

Arrow function has too many parameters (4). Maximum allowed is 3
const fullTextRef = useRef(fullText)
const shouldReset = isCurrentDifferent(fullTextRef, fullText)

Expand Down Expand Up @@ -189,8 +189,8 @@
variables,
facetsArgs,
price,
sponsoredProductsBehavior = 'skip'
sponsoredProductsBehavior = 'sync'
) => {

Check warning on line 193 in react/components/SearchQuery.js

View workflow job for this annotation

GitHub Actions / Lint

Arrow function has too many parameters (4). Maximum allowed is 3
const { getSettings, query: runtimeQuery } = useRuntime()
const settings = getSettings('vtex.store')

Expand All @@ -199,6 +199,9 @@
const productSearchResult = useQuery(productSearchQuery, {
variables: {
...variables,
showSponsored:
settings?.fetchSponsoredProductsOnSearch &&
sponsoredProductsBehavior === 'sync',
variant: getCookie('sp-variant'),
},
})
Expand Down
7 changes: 5 additions & 2 deletions react/utils/shouldSkipSponsoredProducts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type SponsoredProductsBehavior = 'skip' | string
type SponsoredProductsBehavior = 'skip' | 'sync' | 'async'

type Settings = {
fetchSponsoredProductsOnSearch: boolean
Expand All @@ -17,7 +17,10 @@ const shouldSkipSponsoredProducts = (
) => {
const fetchSponsoredProductsConfig = settings?.fetchSponsoredProductsOnSearch

return !fetchSponsoredProductsConfig && sponsoredProductsBehavior === 'skip'
return (
(!fetchSponsoredProductsConfig && sponsoredProductsBehavior === 'skip') ||
sponsoredProductsBehavior === 'sync'
)
}

export default shouldSkipSponsoredProducts
Loading