Reset compare products counter after faceted search updates page content #1571
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This pull request implements a bug fix.
It requires "Product Filtering" to be turned on for the store.
When we select a faceted search filter, Cornerstone updates the page without reloading. It does an AJAX request and updates the URL using the History API. Some sections of contents are updated, with the HTML contents returned in the AJAX call response.
The problem is when we do this faceted search filter selection when we already have a few products selected for comparison, and the "Compare" link at the top header is appearing and active, with the number of selected products.
After the faceted search dynamic update described above is performed, the "Compare" link becomes out of sync with the updated contents. The "Compare" link keeps showing the same product count, and has the same URL. But... the updated contents contain no product selected for comparison, at all.
At this point, if we select another product for comparison (even the SAME previously selected product), the counter will be increased - although we are selecting the first product for comparison, among the filtered results.
This bug is very easy to reproduce, in unchanged Cornerstone theme, as long as we have Product Filtering turned on and some facets and products to play with.
This pull request simply resets the "compare products" counter / array, immediately after the page contents are updated with the faceted search results.
Tickets / Documentation
N/A
Screenshots (if appropriate)
N/A