Skip to content

Feature: use settings to determine whether or not to fetch ads #646

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

Merged
merged 7 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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

- Use the advanced setting `fetchSponsoredProductsOnSearch` to determine whether or not to fetch sponsored products.

## [3.127.1] - 2023-10-24

### Changed
Expand Down
4 changes: 1 addition & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"title": "VTEX Search Result",
"description": "A search result wrapper component",
"mustUpdateAt": "2019-04-25",
"registries": [
"smartcheckout"
],
"registries": ["smartcheckout"],
"scripts": {
"postreleasy": "vtex publish --verbose"
},
Expand Down
13 changes: 10 additions & 3 deletions react/components/SearchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ const useCorrectSearchStateVariables = (
return result
}

const skipSponsoredProducts = ({ sponsoredProductsBehavior, settings }) => {
const fetchSponsoredProductsConfig = settings?.fetchSponsoredProductsOnSearch

return !fetchSponsoredProductsConfig && sponsoredProductsBehavior === 'skip'
}

const sponsoredProductsResult = (
sponsoredProductsLoading,
sponsoredProductsError,
Expand All @@ -191,8 +197,9 @@ const useQueries = (
sponsoredProductsBehavior = 'skip'
) => {
const { getSettings, query: runtimeQuery } = useRuntime()
const isLazyFacetsFetchEnabled =
getSettings('vtex.store')?.enableFiltersFetchOptimization
const settings = getSettings('vtex.store')

const isLazyFacetsFetchEnabled = settings?.enableFiltersFetchOptimization

const productSearchResult = useQuery(productSearchQuery, {
ssr: false,
Expand All @@ -209,7 +216,7 @@ const useQueries = (
error: sponsoredProductsError,
} = useQuery(sponsoredProductsQuery, {
variables,
skip: sponsoredProductsBehavior === 'skip',
skip: skipSponsoredProducts({ sponsoredProductsBehavior, settings }),
})

const sponsoredProductsReturn = sponsoredProductsResult(
Expand Down