-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #646 from vtex-apps/feat/fetch-ads-if-in-settings
Feature: use settings to determine whether or not to fetch ads
- Loading branch information
Showing
3 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
type SponsoredProductsBehavior = 'skip' | string | ||
|
||
type Settings = { | ||
fetchSponsoredProductsOnSearch: boolean | ||
} & Record<string, unknown> | ||
|
||
/** | ||
* 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' | ||
} | ||
|
||
export default shouldSkipSponsoredProducts |