diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f0f023d..dcd12986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +- Always send `showSponsored` as true to the backend. +- Remove explicit call for `sponsoredProduct`, always relying on the backend return value. + ## [3.130.2] - 2024-03-08 ## [3.130.1] - 2024-03-08 diff --git a/react/SearchContent.js b/react/SearchContent.js index 12dff726..edcaffcb 100644 --- a/react/SearchContent.js +++ b/react/SearchContent.js @@ -10,14 +10,9 @@ const SearchContent = () => { const { searchQuery, showFacets, lazyItemsRemaining } = useSearchPage() const { mobileLayout, showContentLoader } = useSearchPageState() - const searchProducts = + const products = path(['data', 'productSearch', 'products'], searchQuery) || [] - const sponsoredProducts = - path(['data', 'sponsoredProducts'], searchQuery) || [] - - const products = sponsoredProducts.concat(searchProducts) - const redirect = path(['data', 'productSearch', 'redirect'], searchQuery) /* No need to show the spinner if it is loading because diff --git a/react/components/SearchQuery.js b/react/components/SearchQuery.js index cadb8e96..f57a2ef8 100644 --- a/react/components/SearchQuery.js +++ b/react/components/SearchQuery.js @@ -4,7 +4,6 @@ import { useRuntime } from 'vtex.render-runtime' import productSearchQuery from 'vtex.store-resources/QueryProductSearchV3' import searchMetadataQuery from 'vtex.store-resources/QuerySearchMetadataV2' import facetsQuery from 'vtex.store-resources/QueryFacetsV2' -import sponsoredProductsQuery from 'vtex.store-resources/QuerySponsoredProducts' import { equals } from 'ramda' import { canUseDOM } from 'exenv' @@ -13,7 +12,6 @@ import { detachFiltersByType, buildQueryArgsFromSelectedFacets, } from '../utils/compatibilityLayer' -import shouldSkipSponsoredProducts from '../utils/shouldSkipSponsoredProducts' import { FACETS_RENDER_THRESHOLD } from '../constants/filterConstants' import useRedirect from '../hooks/useRedirect' import useSession from '../hooks/useSession' @@ -170,27 +168,7 @@ const useCorrectSearchStateVariables = ( return result } -const sponsoredProductsResult = ( - sponsoredProductsLoading, - sponsoredProductsError, - sponsoredProducts -) => { - const showSponsoredProducts = - !sponsoredProductsLoading && !sponsoredProductsError - - const sponsoredProductsResponse = showSponsoredProducts - ? sponsoredProducts - : [] - - return sponsoredProductsResponse -} - -const useQueries = ( - variables, - facetsArgs, - price, - sponsoredProductsBehavior = 'sync' -) => { +const useQueries = (variables, facetsArgs, price) => { const { getSettings, query: runtimeQuery } = useRuntime() const settings = getSettings('vtex.store') @@ -199,31 +177,11 @@ const useQueries = ( const productSearchResult = useQuery(productSearchQuery, { variables: { ...variables, - showSponsored: - settings?.fetchSponsoredProductsOnSearch && - sponsoredProductsBehavior === 'sync', + showSponsored: true, variant: getCookie('sp-variant'), }, }) - const { - data: { sponsoredProducts } = [], - loading: sponsoredProductLoading, - error: sponsoredProductsError, - } = useQuery(sponsoredProductsQuery, { - variables: { - ...variables, - anonymousId: getCookie('biggy-anonymous'), - }, - skip: shouldSkipSponsoredProducts(sponsoredProductsBehavior, settings), - }) - - const sponsoredProductsReturn = sponsoredProductsResult( - sponsoredProductLoading, - sponsoredProductsError, - sponsoredProducts - ) - const { refetch: searchRefetch, loading: searchLoading, @@ -313,7 +271,6 @@ const useQueries = ( sampling: facets?.sampling, }, searchMetadata, - sponsoredProducts: sponsoredProductsReturn, }, productSearchResult, refetch, diff --git a/react/utils/shouldSkipSponsoredProducts.ts b/react/utils/shouldSkipSponsoredProducts.ts deleted file mode 100644 index 1b3135df..00000000 --- a/react/utils/shouldSkipSponsoredProducts.ts +++ /dev/null @@ -1,26 +0,0 @@ -type SponsoredProductsBehavior = 'skip' | 'sync' | 'async' - -type Settings = { - fetchSponsoredProductsOnSearch: boolean -} & Record - -/** - * This function checks the store's settings, as well as the passed value of - * `sponsoredProductsBehavior` passed in the store-theme, to determine if the - * sponsored products request should be skipped or not. - * Some accounts may not have configured the store's settings, so we need to check if the - * `sponsoredProductsBehavior` parameter for compatibility. - */ -const shouldSkipSponsoredProducts = ( - sponsoredProductsBehavior: SponsoredProductsBehavior, - settings: Settings -) => { - const fetchSponsoredProductsConfig = settings?.fetchSponsoredProductsOnSearch - - return ( - (!fetchSponsoredProductsConfig && sponsoredProductsBehavior === 'skip') || - sponsoredProductsBehavior === 'sync' - ) -} - -export default shouldSkipSponsoredProducts