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.

display prices after filtering correctly

Łukasz Adamczyk5e5be849af97
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 45646cd779..65eeb78499 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
@@ -21,6 +21,6 @@ Spree.ready(function() {
const urlParams = new URLSearchParams(dataParams)
urlParams.set('price', formattedPriceRange)
- priceRangeSubmitButton.href = `${location.pathname}?${decodeURIComponent(urlParams.toString())}`
+ priceRangeSubmitButton.href = decodeURIComponent(`${location.pathname}?${urlParams.toString()}`)
}
});
diff --git a/frontend/app/helpers/spree/products_filters_helper.rb b/frontend/app/helpers/spree/products_filters_helper.rb
index 2997b9172c..101338f677 100644
--- a/frontend/app/helpers/spree/products_filters_helper.rb
+++ b/frontend/app/helpers/spree/products_filters_helper.rb
@@ -1,15 +1,16 @@
module Spree
module ProductsFiltersHelper
def min_price_filter_input
- price_filter_input(name: :min_price, value: prices.min, placeholder: Spree.t(:min))
+ price_filter_input(name: :min_price, value: prices.first, placeholder: Spree.t(:min))
end
def max_price_filter_input
- price_filter_input(name: :max_price, value: prices.max, placeholder: Spree.t(:max))
+ price_filter_input(name: :max_price, value: prices.last, placeholder: Spree.t(:max))
end
def price_filter_input(name:, value:, placeholder:)
- number_field_tag(name, value, min: 0, step: 1, placeholder: placeholder)
+ price_value = value&.zero? ? '' : value
+ number_field_tag(name, price_value, min: 0, step: 1, placeholder: placeholder)
end
private
@@ -17,7 +18,7 @@ module Spree
def prices
price_param = params[:price].to_s
split_prices = price_param.split('-')
- split_prices.map(&:to_i)
+ split_prices.map { |price| price.to_money.to_i }
end
end
end
diff --git a/frontend/spec/features/products_spec.rb b/frontend/spec/features/products_spec.rb
index 03e423fede..55163a4c89 100644
--- a/frontend/spec/features/products_spec.rb
+++ b/frontend/spec/features/products_spec.rb
@@ -309,6 +309,9 @@ describe 'Visiting Products', type: :feature, inaccessible: true do
'Ruby on Rails Mug',
'Ruby on Rails Tote'
)
+
+ expect(page).to have_field(Spree.t(:min), with: '55')
+ expect(page).to have_field(Spree.t(:max), with: '103')
end
it 'is able to display products when providing only min amount of 55 dollars' do
@@ -331,6 +334,9 @@ describe 'Visiting Products', type: :feature, inaccessible: true do
'Ruby Baseball Jersey',
'Apache Baseball Jersey'
)
+
+ expect(page).to have_field(Spree.t(:min), with: '56')
+ expect(page).to have_field(Spree.t(:max), with: '')
end
it 'is able to display products when providing only max amount of 56 dollars' do
@@ -348,6 +354,9 @@ describe 'Visiting Products', type: :feature, inaccessible: true do
'Ruby on Rails Mug',
'Ruby on Rails Tote'
)
+
+ expect(page).to have_field(Spree.t(:min), with: '')
+ expect(page).to have_field(Spree.t(:max), with: '56')
end
end