Class: SolidusAdmin::OrdersController

Inherits:
BaseController
  • Object
show all
Includes:
ControllerHelpers::Search, Spree::Core::ControllerHelpers::StrongParameters
Defined in:
app/controllers/solidus_admin/orders_controller.rb

Instance Method Summary collapse

Methods included from ComponentsHelper

#component

Instance Method Details

#customers_forObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/solidus_admin/orders_controller.rb', line 95

def customers_for
  load_order

  @users = Spree.user_class
    .where.not(id: @order.user_id)
    .order(created_at: :desc, id: :desc)
    .ransack(params[:q])
    .result(distinct: true)
    .includes(:default_user_bill_address, :default_user_ship_address)
    .limit(10)

  respond_to do |format|
    format.html { render component('orders/show/customer_search/result').with_collection(@users, order: @order), layout: false }
  end
end

#editObject



64
65
66
# File 'app/controllers/solidus_admin/orders_controller.rb', line 64

def edit
  redirect_to action: :show
end

#indexObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/solidus_admin/orders_controller.rb', line 14

def index
  orders = apply_search_to(
    Spree::Order.order(created_at: :desc, id: :desc),
    param: :q,
  )

  set_page_and_extract_portion_from(orders)

  respond_to do |format|
    format.html { render component('orders/index').new(page: @page) }
  end
end

#newObject



27
28
29
30
31
32
33
34
35
# File 'app/controllers/solidus_admin/orders_controller.rb', line 27

def new
  order = Spree::Order.create!(
    created_by: current_solidus_admin_user,
    frontend_viewable: false,
    store_id: current_store.try(:id)
  )

  redirect_to order_url(order), status: :see_other
end

#showObject



37
38
39
40
41
42
43
# File 'app/controllers/solidus_admin/orders_controller.rb', line 37

def show
  load_order

  respond_to do |format|
    format.html { render component('orders/show').new(order: @order) }
  end
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/solidus_admin/orders_controller.rb', line 45

def update
  load_order

  @order.assign_attributes(order_params)
  @order.email ||= @order.user.email if @order.user && @order.user.changed?

  if @order.save
    flash[:notice] = t('.success')
  else
    flash[:error] = t('.error')
  end

  respond_to do |format|
    format.html { redirect_to spree.edit_admin_order_path(@order) }

    format.turbo_stream { render turbo_stream: '<turbo-stream action="refresh" />' }
  end
end

#variants_forObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/solidus_admin/orders_controller.rb', line 68

def variants_for
  load_order

  # We need to eager load active storage attachments when using it
  if Spree::Image.include?(Spree::Image::ActiveStorageAttachment)
    image_includes = {
      attachment_attachment: { blob: { variant_records: { image_attachment: :blob } } }
    }
  end

  @variants = Spree::Variant
    .where.not(id: @order.line_items.select(:variant_id))
    .order(created_at: :desc, id: :desc)
    .where(product_id: Spree::Product.ransack(params[:q]).result.select(:id))
    .limit(10)
    .eager_load(
      :prices,
      images: image_includes || {},
      option_values: :option_type,
      stock_items: :stock_location,
    )

  respond_to do |format|
    format.html { render component('orders/cart/result').with_collection(@variants, order: @order), layout: false }
  end
end