Module: Spree::Admin::Orders::CustomerDetailsControllerDecorator
- Defined in:
- app/controllers/spree/admin/orders/customer_details_controller_decorator.rb
Instance Method Summary collapse
-
#assign_customer ⇒ Object
Persists the customer found by
search_for_customerright away — no separate "Update" click, no manual Guest Checkout toggle. -
#edit ⇒ Object
Override.
-
#load_user ⇒ Object
Override.
- #order_params ⇒ Object
Instance Method Details
#assign_customer ⇒ Object
Persists the customer found by search_for_customer right away — no separate
"Update" click, no manual Guest Checkout toggle. associate_user! only backfills
bill/ship address when the order doesn't already have one (||=), so an order's
existing addresses are left as-is; this is a user swap only.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/spree/admin/orders/customer_details_controller_decorator.rb', line 15 def assign_customer user = tenant_user_scope.find_by(id: params[:user_id]) if user.nil? flash[:error] = Spree.t(:user_not_found) elsif user.id == @order.user_id flash[:notice] = Spree.t('admin.orders.customer_details.user_already_assigned', email: user.email) else @order.associate_user!(user) flash[:success] = Spree.t('admin.orders.customer_details.user_assigned', email: user.email) end redirect_to spree.edit_admin_order_customer_path(@order) end |
#edit ⇒ Object
Override
6 7 8 9 |
# File 'app/controllers/spree/admin/orders/customer_details_controller_decorator.rb', line 6 def edit super search_for_customer end |
#load_user ⇒ Object
Override
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/spree/admin/orders/customer_details_controller_decorator.rb', line 31 def load_user scope = tenant_user_scope @user = scope.find_by(id: order_params[:user_id]) || (scope.find_by(email: order_params[:email]) if order_params[:email].present?) || (scope.find_by(phone_number: order_params[:phone_number]) if order_params[:phone_number].present?) return if @user flash.now[:error] = Spree.t(:user_not_found) render action: :edit, status: :unprocessable_entity end |
#order_params ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/controllers/spree/admin/orders/customer_details_controller_decorator.rb', line 43 def order_params params.require(:order).permit( :email, :user_id, :use_billing, :phone_number, bill_address_attributes: permitted_address_attributes, ship_address_attributes: permitted_address_attributes ) end |