From a7908086f60f4f1e26c09f344eb33980a96988f7 Mon Sep 17 00:00:00 2001 From: Thalyta Fabrine Date: Mon, 4 Mar 2024 13:59:05 +0100 Subject: [PATCH] Get sponsored products in productSearch --- CHANGELOG.md | 4 ++++ react/components/SearchQuery.js | 5 ++++- react/utils/shouldSkipSponsoredProducts.ts | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f98a01ff..bb6cdc42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/react/components/SearchQuery.js b/react/components/SearchQuery.js index 80bfba30..cadb8e96 100644 --- a/react/components/SearchQuery.js +++ b/react/components/SearchQuery.js @@ -189,7 +189,7 @@ const useQueries = ( variables, facetsArgs, price, - sponsoredProductsBehavior = 'skip' + sponsoredProductsBehavior = 'sync' ) => { const { getSettings, query: runtimeQuery } = useRuntime() const settings = getSettings('vtex.store') @@ -199,6 +199,9 @@ const useQueries = ( const productSearchResult = useQuery(productSearchQuery, { variables: { ...variables, + showSponsored: + settings?.fetchSponsoredProductsOnSearch && + sponsoredProductsBehavior === 'sync', variant: getCookie('sp-variant'), }, }) diff --git a/react/utils/shouldSkipSponsoredProducts.ts b/react/utils/shouldSkipSponsoredProducts.ts index 5f496ed7..1b3135df 100644 --- a/react/utils/shouldSkipSponsoredProducts.ts +++ b/react/utils/shouldSkipSponsoredProducts.ts @@ -1,4 +1,4 @@ -type SponsoredProductsBehavior = 'skip' | string +type SponsoredProductsBehavior = 'skip' | 'sync' | 'async' type Settings = { fetchSponsoredProductsOnSearch: boolean @@ -17,7 +17,10 @@ const shouldSkipSponsoredProducts = ( ) => { const fetchSponsoredProductsConfig = settings?.fetchSponsoredProductsOnSearch - return !fetchSponsoredProductsConfig && sponsoredProductsBehavior === 'skip' + return ( + (!fetchSponsoredProductsConfig && sponsoredProductsBehavior === 'skip') || + sponsoredProductsBehavior === 'sync' + ) } export default shouldSkipSponsoredProducts