Merge pull request #9686 from jibees/9684-fix-search-customer-in-order-creation-for-super-admin

Admin, New Order, Search customer: As a super admin, search for customer within all enterprises
This commit is contained in:
Rachel Arnould
2022-09-29 14:35:18 +02:00
committed by GitHub
2 changed files with 18 additions and 10 deletions

View File

@@ -18,19 +18,28 @@ module Spree
end
def customers
@customers = []
if spree_current_user.enterprises.pluck(:id).include? search_params[:distributor_id].to_i
@customers = Customer.
ransack(m: 'or', email_start: search_params[:q], first_name_start: search_params[:q],
last_name_start: search_params[:q]).
result.
where(enterprise_id: search_params[:distributor_id].to_i)
end
render json: @customers, each_serializer: ::Api::Admin::CustomerSerializer
render json: load_customers, each_serializer: ::Api::Admin::CustomerSerializer
end
private
def load_customers
return [] unless valid_enterprise_given?
Customer.ransack(
m: 'or', email_start: search_params[:q],
first_name_start: search_params[:q], last_name_start: search_params[:q]
).result.where(enterprise_id: search_params[:distributor_id].to_i)
end
def valid_enterprise_given?
return true if spree_current_user.admin?
spree_current_user.enterprises.where(
id: search_params[:distributor_id].to_i
).present?
end
def ransack_hash
{
m: 'or',

View File

@@ -755,7 +755,6 @@ describe '
end
it "finds a customer by name" do
pending("issue #9684")
serching_for_customers
end
end