Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

fix issue with mixing Properties and Price filters

Łukasz Adamczyk16584b987c9e
diff --git a/frontend/app/assets/javascripts/spree/frontend/views/spree/products/price_filters.es6 b/frontend/app/assets/javascripts/spree/frontend/views/spree/products/price_filters.es6
index 997a4e9f76..8485aff2cd 100644
--- a/frontend/app/assets/javascripts/spree/frontend/views/spree/products/price_filters.es6
+++ b/frontend/app/assets/javascripts/spree/frontend/views/spree/products/price_filters.es6
@@ -22,12 +22,10 @@ Spree.ready(function() {
updatePricesForFiltering(minPrice, maxPrice) {
const formattedPriceRange = `${minPrice}-${maxPrice}`
+ const url = new URL(this.filterButton.href)
- const dataParams = JSON.parse(this.filterButton.dataset.params)
- const urlParams = new URLSearchParams(dataParams)
-
- urlParams.set('price', formattedPriceRange)
- this.filterButton.href = decodeURIComponent(`${location.pathname}?${urlParams.toString()}`)
+ url.searchParams.set('price', formattedPriceRange)
+ this.filterButton.href = `${url.pathname}${url.search}`
}
}
diff --git a/frontend/spec/features/products_filtering_spec.rb b/frontend/spec/features/products_filtering_spec.rb
index 6ed858718d..1937a02b60 100644
--- a/frontend/spec/features/products_filtering_spec.rb
+++ b/frontend/spec/features/products_filtering_spec.rb
@@ -39,14 +39,16 @@ describe 'Products filtering', :js do
fill_in 'keywords', with: "#{text}\n"
end
- def click_on_filter(filter_name, value:)
+ def click_on_filter(filter_name, value: nil)
filter_element = find('.plp-filters-card', text: filter_name)
filter_header_element = filter_element.find('.plp-filters-card-header')
filter_header_element.click if filter_header_element[:class].include?('collapsed')
- filter_element.click_link(value)
- wait_for_turbolinks
+ if value.present?
+ filter_element.click_link(value)
+ wait_for_turbolinks
+ end
end
def wait_for_turbolinks
@@ -109,6 +111,12 @@ describe 'Products filtering', :js do
expect(page).to have_selected_filter_with(value: 'ZETA')
expect(page).to have_selected_filter_with(value: 'ALPHA')
+ click_on_filter 'Price'
+ fill_in "$ #{Spree.t(:min)}", with: '19'
+ fill_in "$ #{Spree.t(:max)}", with: '20'
+ click_on 'DONE'
+ expect(page).to have_content 'Second shirt'
+
expect_working_filters_clearing
click_on_filter 'Price', value: '$50 - $100'