mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user