Skip to content

Commit

Permalink
Variant search: Exclude template variants
Browse files Browse the repository at this point in the history
Currently, one can add template variants to one's cart, but that should
not be possible. This commit makes sure that the variant search won't
return template variants.
  • Loading branch information
mamhoff committed Oct 9, 2024
1 parent a639c06 commit cc441df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/lib/spree/core/search/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Variant

def initialize(query_string, scope: Spree::Variant.all)
@query_string = query_string
@scope = scope
@scope = scope.sellable
end

# Searches the variants table using the ransack 'search_terms' defined on the class.
Expand Down
10 changes: 10 additions & 0 deletions core/spec/lib/search/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def refute_found(query_string, variant)
it { refute_found("bca", variant) }
end

context "with a template variant" do
let!(:option_type) { create(:option_type, option_values: [option_value]) }
let(:option_value) { build(:option_value) }
let(:product) { create(:product, option_types: [option_type], sku: "TEMPLATE") }
let(:variant) { create(:variant, product: product, sku: "NOT_TEMPLATE") }

it { refute_found("TEMPLATE", product.master) }
it { assert_found("NOT_TEMPLATE", variant) }
end

context "by product" do
it { assert_found("My Special Product", variant) }
it { assert_found("My Spec", variant) }
Expand Down

0 comments on commit cc441df

Please sign in to comment.