diff --git a/CHANGELOG.md b/CHANGELOG.md index 057324e55e..5ae0592e70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - HTML Entity displayed as is via system/error message on a Storefront. [#1888](https://github.com/bigcommerce/cornerstone/pull/1888) ## Draft +- “Sort by” dropdown selection not reflected on search results page for News and Information tab. [#1910](https://github.com/bigcommerce/cornerstone/pull/1910) - Shoppers are not anchor-linked to reviews on PDPs if product description tabs are enabled. [#1883](https://github.com/bigcommerce/cornerstone/pull/1883) - Fixed text contrast for brand name on Cart page. [#1882](https://github.com/bigcommerce/cornerstone/pull/1882) - Add sufficient contrast for Upsell Banners in Cornerstone Theme according to AA Standard. [#1891](https://github.com/bigcommerce/cornerstone/pull/1891) diff --git a/assets/js/theme/search.js b/assets/js/theme/search.js index e4b16ca1a5..d9ddaadcbf 100644 --- a/assets/js/theme/search.js +++ b/assets/js/theme/search.js @@ -132,8 +132,37 @@ export default class Search extends CatalogPage { $($tabsCollection.get(nextTabIdx)).focus().trigger('click'); } + getUrlParameter(queryParam) { + const regex = new RegExp(`[\\?&]${queryParam}=([^&#]*)`); + const results = regex.exec(window.location.search); + return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); + } + + setupSortByQuerySearchParam() { + const searchQuery = this.getUrlParameter('search_query'); + + if (searchQuery.length === 0) return; + + const $baseInput = $('').attr('type', 'hidden'); + + $('[data-sort-by]').each((idx, form) => { + const $form = $(form); + $form.append( + $baseInput.clone().attr({ + name: 'search_query', + value: searchQuery, + }), + $baseInput.clone().attr({ + name: 'section', + value: $form.data('sort-by'), + }), + ); + }); + } + onReady() { compareProducts(this.context.urls); + this.setupSortByQuerySearchParam(); const $searchForm = $('[data-advanced-search-form]'); const $categoryTreeContainer = $searchForm.find('[data-search-category-tree]'); diff --git a/templates/components/category/sort-box.html b/templates/components/category/sort-box.html index 517e0fd4b1..1cfe6dc8a4 100644 --- a/templates/components/category/sort-box.html +++ b/templates/components/category/sort-box.html @@ -16,4 +16,3 @@ - diff --git a/templates/components/products/filter.html b/templates/components/products/filter.html index f1042af5b3..300564334f 100644 --- a/templates/components/products/filter.html +++ b/templates/components/products/filter.html @@ -1,3 +1,3 @@ -
+ {{> components/category/sort-box sort=sort}}
diff --git a/templates/components/search/content-sort-box.html b/templates/components/search/content-sort-box.html index 79db88d149..4d4b854d62 100644 --- a/templates/components/search/content-sort-box.html +++ b/templates/components/search/content-sort-box.html @@ -1,4 +1,4 @@ -
+