From 99284446233a46b66c5d63ec8f8a7ba1d2c1cb76 Mon Sep 17 00:00:00 2001 From: Yurii Zusik Date: Fri, 20 Nov 2020 10:23:39 +0200 Subject: [PATCH] =?UTF-8?q?fix(storefront):=20BCTHEME-85=20=E2=80=9CSort?= =?UTF-8?q?=20by=E2=80=9D=20dropdown=20selection=20not=20reflected=20on=20?= =?UTF-8?q?search=20results=20page=20for=20News=20and=20Information=20tab?= =?UTF-8?q?=20(#1910)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + assets/js/theme/search.js | 29 +++++++++++++++++++ templates/components/category/sort-box.html | 1 - templates/components/products/filter.html | 2 +- .../components/search/content-sort-box.html | 2 +- 5 files changed, 32 insertions(+), 3 deletions(-) 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 @@ -
+