Merge pull request #8555 from jibees/8507-fix-product-search-order-

Searching variants should order results by variant display name
This commit is contained in:
Filipe
2021-12-23 17:41:01 +00:00
committed by GitHub
2 changed files with 22 additions and 1 deletions

View File

@@ -34,7 +34,11 @@ module OpenFoodNetwork
def query_scope
Spree::Variant.where(is_master: false).
includes(option_values: :option_type).
ransack(search_params.merge(m: 'or')).result
ransack(search_params.merge(m: 'or')).
result.
order("spree_products.name, display_name, display_as, spree_products.variant_unit_name").
includes(:product).
joins(:product)
end
def distributor

View File

@@ -1,6 +1,7 @@
# frozen_string_literal: true
require 'open_food_network/scope_variants_for_search'
require 'spec_helper'
describe OpenFoodNetwork::ScopeVariantsForSearch do
let!(:p1) { create(:simple_product, name: 'Product 1') }
@@ -60,5 +61,21 @@ describe OpenFoodNetwork::ScopeVariantsForSearch do
expect(result).to_not include v1, v2, v3
end
end
context "searching products starting with the same 3 caracters" do
let(:params) { { q: "pro" } }
it "returns variants ordered by display_name" do
p1.name = "Product b"
p2.name = "Product a"
p3.name = "Product c"
p4.name = "Product 1"
p1.save!
p2.save!
p3.save!
p4.save!
expect(result.map(&:name)).
to eq(["Product 1", "Product a", "Product b", "Product c"])
end
end
end
end