Update ScopeVariantsForSearch logic to match both product and variant SKUs

This commit is contained in:
Matt-Yorkley
2023-06-09 12:46:28 +01:00
parent 0f253bb2a0
commit ae24b2d688
3 changed files with 13 additions and 4 deletions

View File

@@ -28,7 +28,7 @@ module Spree
acts_as_paranoid
searchable_attributes :supplier_id, :primary_taxon_id, :meta_keywords
searchable_attributes :supplier_id, :primary_taxon_id, :meta_keywords, :sku
searchable_associations :supplier, :properties, :primary_taxon, :variants
searchable_scopes :active, :with_properties

View File

@@ -29,7 +29,7 @@ module OpenFoodNetwork
attr_reader :params
def search_params
{ product_name_cont: params[:q], sku_cont: params[:q] }
{ product_name_cont: params[:q], sku_cont: params[:q], product_sku_cont: params[:q] }
end
def query_scope

View File

@@ -30,8 +30,17 @@ describe OpenFoodNetwork::ScopeVariantsForSearch do
let(:params) { { q: "product 1" } }
it "returns all products whose names or SKUs match the query" do
expect(result).to include v1
expect(result).to_not include v2, v3, v4
expect(result).to include v1, v2
expect(result).to_not include v3, v4
end
context "matching both product SKUs and variant SKUs" do
let!(:v5) { create(:variant, sku: "Product 1b") }
it "returns all variants whose SKU or product's SKU match the query" do
expect(result).to include v1, v2, v5
expect(result).to_not include v3, v4
end
end
end