Skip to content

Commit e4999c6

Browse files
committed
LTRAC-955: feat - respect control panel default search sorting
1 parent bf58b13 commit e4999c6

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

core/app/[locale]/(default)/(faceted)/search/page-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const SearchPageQuery = graphql(`
2727
tax {
2828
plp
2929
}
30+
search {
31+
defaultSearchProductSort
32+
}
3033
}
3134
}
3235
}

core/app/[locale]/(default)/(faceted)/search/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ export default async function Search(props: Props) {
8585

8686
const taxDisplay = settings?.tax?.plp;
8787

88+
const defaultProductSort = settings?.search.defaultSearchProductSort;
89+
8890
const streamableFacetedSearch = Streamable.from(async () => {
8991
const searchParams = await props.searchParams;
9092
const customerAccessToken = await getSessionCustomerAccessToken();
@@ -95,11 +97,13 @@ export default async function Search(props: Props) {
9597
customerAccessToken,
9698
);
9799
const parsedSearchParams = loadSearchParams?.(searchParams) ?? {};
100+
const sort = typeof searchParams.sort === 'string' ? searchParams.sort : defaultProductSort;
98101

99102
const search = await fetchFacetedSearch(
100103
{
101104
...searchParams,
102105
...parsedSearchParams,
106+
sort,
103107
},
104108
currencyCode,
105109
customerAccessToken,
@@ -258,7 +262,7 @@ export default async function Search(props: Props) {
258262
resetFiltersLabel={t('FacetedSearch.resetFilters')}
259263
showCompare={productComparisonsEnabled}
260264
showRating={showRating}
261-
sortDefaultValue="featured"
265+
sortDefaultValue={defaultProductSort?.toLowerCase() ?? 'featured'}
262266
sortLabel={t('SortBy.sortBy')}
263267
sortOptions={[
264268
{ value: 'featured', label: t('SortBy.featuredItems') },

0 commit comments

Comments
 (0)