add search by fullname with comma

This commit is contained in:
Dung Bui
2023-12-03 14:10:12 +07:00
parent f94d2c386c
commit febda2ce12
4 changed files with 35 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
"order_bill_address_firstname",
"order_bill_address_lastname",
"order_bill_address_full_name",
"order_bill_address_full_name_with_comma",
"variant_product_supplier_name",
"order_email",
"order_number",

View File

@@ -6,7 +6,7 @@ module Spree
self.belongs_to_required_by_default = false
searchable_attributes :firstname, :lastname, :phone, :full_name
searchable_attributes :firstname, :lastname, :phone, :full_name, :full_name_with_comma
searchable_associations :country, :state
belongs_to :country, class_name: "Spree::Country"
@@ -36,6 +36,12 @@ module Spree
)
end
ransacker :full_name_with_comma, formatter: proc { |value| value.to_s } do |parent|
Arel::Nodes::SqlLiteral.new(
"CONCAT(#{parent.table_name}.firstname, ', ', #{parent.table_name}.lastname)"
)
end
def self.default
new(country: DefaultCountry.country)
end

View File

@@ -203,4 +203,19 @@ describe Spree::Address do
expect(result2).not_to include(address1)
end
end
describe "ransacker :full_name_with_comma" do
it "searches for records with matching full names with comma" do
address1 = create(:address, firstname: 'John', lastname: 'Doe')
address2 = create(:address, firstname: 'Jane', lastname: 'Smith')
result1 = described_class.ransack(full_name_with_comma_cont: 'John, Doe').result
expect(result1).to include(address1)
expect(result1).not_to include(address2)
result2 = described_class.ransack(full_name_with_comma_cont: 'Jane, Smith').result
expect(result2).to include(address2)
expect(result2).not_to include(address1)
end
end
end

View File

@@ -240,6 +240,18 @@ describe '
expect_line_items_results [li1], [li2, li3]
end
it "by customer fullname with comma" do
fill_in "quick_filter", with: o1.bill_address.firstname + ', ' + o1.bill_address.lastname
page.find('.filter-actions .button.icon-search').click
expect_line_items_results [li1], [li2, li3]
fill_in "quick_filter", with: o2.bill_address.firstname + ', ' + o2.bill_address.lastname
page.find('.filter-actions .button.icon-search').click
expect_line_items_results [li2, li3], [li1]
end
end
context "displaying individual columns" do