Fix searching issue with full name on bulk order management

This commit is contained in:
saunmanoj888
2023-05-09 16:36:19 +05:30
committed by Konrad
parent 02873d7596
commit aee7645e29
4 changed files with 35 additions and 2 deletions

View File

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

View File

@@ -4,7 +4,7 @@ module Spree
class Address < ApplicationRecord
include AddressDisplay
searchable_attributes :firstname, :lastname, :phone
searchable_attributes :firstname, :lastname, :phone, :full_name
searchable_associations :country, :state
belongs_to :country, class_name: "Spree::Country"
@@ -28,6 +28,12 @@ module Spree
alias_attribute :last_name, :lastname
delegate :name, to: :state, prefix: true, allow_nil: true
ransacker :full_name, 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

@@ -187,4 +187,19 @@ describe Spree::Address do
specify { expect(address.state_text).to eq 'virginia' }
end
end
describe "ransacker :full_name" do
it "searches for records with matching full names" do
address1 = create(:address, firstname: 'John', lastname: 'Doe')
address2 = create(:address, firstname: 'Jane', lastname: 'Smith')
result1 = described_class.ransack(full_name_cont: 'John Doe').result
expect(result1).to include(address1)
expect(result1).not_to include(address2)
result2 = described_class.ransack(full_name_cont: 'Jane Smith').result
expect(result2).to include(address2)
expect(result2).not_to include(address1)
end
end
end

View File

@@ -158,7 +158,7 @@ distributors: [distributor4, distributor5]) }
# filtering by first name
fill_in "First name begins with", with: billing_address2.firstname
page.find('.filter-actions .button.icon-search').click
# Order 3 should show, but not 2 and 4
# Order 2 should show, but not 3 and 4
expect(page).to have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to_not have_content order4.number
@@ -172,6 +172,17 @@ distributors: [distributor4, distributor5]) }
expect(page).to_not have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to have_content order4.number
find("a#clear_filters_button").click
# filtering by first and last name together
fill_in "First name begins with", with: billing_address3.firstname
fill_in "Last name begins with", with: billing_address3.lastname
page.find('.filter-actions .button.icon-search').click
# Order 3 should show, but not 2 and 4
expect(page).not_to have_content order2.number
expect(page).to have_content order3.number
expect(page).not_to have_content order4.number
end
it "filter by shipping methods" do