Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storefront): BCTHEME-85 “Sort by” dropdown selection not reflected on search results page for News and Information tab #1910

Merged
merged 2 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions assets/js/theme/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<input/>').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]');
Expand Down
1 change: 0 additions & 1 deletion templates/components/category/sort-box.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
</select>
</div>
</fieldset>

2 changes: 1 addition & 1 deletion templates/components/products/filter.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<form class="actionBar" method="get" data-sort-by>
<form class="actionBar" method="get" data-sort-by="product">
{{> components/category/sort-box sort=sort}}
</form>
2 changes: 1 addition & 1 deletion templates/components/search/content-sort-box.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form class="actionBar" method="get" data-sort-by>
<form class="actionBar" method="get" data-sort-by="content">
<fieldset class="form-fieldset actionBar-section">
<div class="form-field">
<label class="form-label" for="sort">{{lang 'common.sorter.sort_by'}}</label>
Expand Down