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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Use filterable option types only to display PLP filters
Nathaniel Nande8e349bf93f27
diff --git a/backend/app/views/spree/admin/option_types/_form.html.erb b/backend/app/views/spree/admin/option_types/_form.html.erbindex d2d8968d88..fd899fbf84 100644--- a/backend/app/views/spree/admin/option_types/_form.html.erb+++ b/backend/app/views/spree/admin/option_types/_form.html.erb@@ -14,4 +14,13 @@<%= f.error_message_on :presentation %><% end %></div>++ <div class="col-12 col-md-6">+ <%= f.field_container :filterable, class: ['form-group'] do %>+ <%= label_tag :option_type_filterable do %>+ <%= f.check_box :filterable %>+ <%= Spree.t(:filterable) %>+ <% end %>+ <% end %>+ </div></div>diff --git a/backend/app/views/spree/admin/option_types/index.html.erb b/backend/app/views/spree/admin/option_types/index.html.erbindex 6675902707..133a138054 100644--- a/backend/app/views/spree/admin/option_types/index.html.erb+++ b/backend/app/views/spree/admin/option_types/index.html.erb@@ -18,6 +18,7 @@<th class="no-border handel-head"></th><th><%= Spree.t(:name) %></th><th><%= Spree.t(:presentation) %></th>+ <th><%= Spree.t(:filterable) %></th><th class="actions"></th></tr></thead>@@ -29,6 +30,7 @@</td><td><%= option_type.name %></td><td class="presentation"><%= option_type.presentation %></td>+ <td><%= option_type.filterable %></td><td class="actions actions-2 text-right"><%= link_to_edit(option_type, class: 'admin_edit_option_type', no_text: true) if can?(:edit, option_type) %><%= link_to_delete(option_type, no_text: true) if can?(:delete, option_type) %>diff --git a/backend/spec/features/admin/option_types/edit_option_type_spec.rb b/backend/spec/features/admin/option_types/edit_option_type_spec.rbnew file mode 100644index 0000000000..bf93ee694a--- /dev/null+++ b/backend/spec/features/admin/option_types/edit_option_type_spec.rb@@ -0,0 +1,25 @@+require 'spec_helper'++describe 'Option Type edit spec', type: :feature, js: true do+ stub_authorization!++ let(:option_type) { create(:option_type, filterable: false) }++ context 'editing option type' do+ before do+ visit spree.edit_admin_option_type_path(option_type)+ end++ it 'allows to update filtering attribute of option type' do+ expect(page).to have_unchecked_field('option_type_filterable')++ check('option_type_filterable')+ click_button 'Update'++ expect(page).to have_content 'successfully updated!'++ within("#spree_option_type_#{option_type.id}") { click_icon(:edit) }+ expect(page).to have_checked_field('option_type_filterable')+ end+ end+enddiff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex 6a5d3645af..e4dd155eeb 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -52,6 +52,7 @@ en:spree/option_type:name: Namepresentation: Presentation+ filterable: Filterablespree/order:checkout_complete: Checkout Completecompleted_at: Completed At@@ -889,6 +890,7 @@ en:filename: Filenamefill_in_customer_info: Please fill in customer infofilter: Filter+ filterable: Filterablefilter_results: Filter Resultsfinalize: Finalizefind_a_taxon: Find a Taxondiff --git a/frontend/app/helpers/spree/frontend_helper.rb b/frontend/app/helpers/spree/frontend_helper.rbindex a6764fb9f7..e897c11fda 100644--- a/frontend/app/helpers/spree/frontend_helper.rb+++ b/frontend/app/helpers/spree/frontend_helper.rb@@ -274,12 +274,12 @@ module Spreeenddef available_option_types_cache_key- @available_option_types_cache_key ||= Spree::OptionType.maximum(:updated_at)&.utc&.to_i+ @available_option_types_cache_key ||= Spree::OptionType.filterable.maximum(:updated_at)&.utc&.to_ienddef available_option_types@available_option_types ||= Rails.cache.fetch("available-option-types/#{available_option_types_cache_key}") do- Spree::OptionType.includes(:option_values).to_a+ Spree::OptionType.includes(:option_values).filterable.to_aend@available_option_typesenddiff --git a/frontend/spec/features/products_filtering_spec.rb b/frontend/spec/features/products_filtering_spec.rbindex 3e88137dc5..0d06d02987 100644--- a/frontend/spec/features/products_filtering_spec.rb+++ b/frontend/spec/features/products_filtering_spec.rb@@ -7,6 +7,9 @@ describe 'Products filtering', :js, :caching dolet!(:option_value_1_1) { create :option_value, option_type: option_type_1, name: 's', presentation: 'S' }let!(:option_value_1_2) { create :option_value, option_type: option_type_1, name: 'm', presentation: 'M' }+ let!(:option_type_2) { create :option_type, name: 'color', presentation: 'Color' }+ let!(:option_value_2_1) { create :option_value, option_type: option_type_2, name: 'green', presentation: 'Green' }+let!(:product_1) { create :product, name: 'First shirt', option_types: [option_type_1] }let!(:variant_1_1) { create :variant, product: product_1, option_values: [option_value_1_1] }@@ -33,6 +36,10 @@ describe 'Products filtering', :js, :caching dohave_css '.plp-overlay-card-item--selected', text: valueend+ def filters+ find('#plp-filters-accordion')+ end+it 'correctly filters Products' dovisit spree.nested_taxons_path(taxon)@@ -49,4 +56,21 @@ describe 'Products filtering', :js, :caching doexpect(page).to have_selected_filter_with(value: 'S')expect(current_path).to eq spree.products_pathend++ context 'option type filters' do+ it 'displays filterable option types' do+ visit spree.nested_taxons_path(taxon)++ %w[Size Color].each do |option_type_name|+ expect(filters).to have_content(option_type_name)+ end+ end++ it 'does not display unfilterable option types' do+ option_type_2.update!(filterable: false)+ visit spree.nested_taxons_path(taxon)++ expect(filters).not_to have_content('Color')+ end+ endend