Class: SolidusAdmin::Orders::Index::Component

Inherits:
UI::Pages::Index::Component
  • Object
show all
Defined in:
app/components/solidus_admin/orders/index/component.rb

Instance Method Summary collapse

Instance Method Details

#columnsObject



91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/components/solidus_admin/orders/index/component.rb', line 91

def columns
  [
    number_column,
    state_column,
    date_column,
    customer_column,
    total_column,
    items_column,
    payment_column,
    shipment_column,
  ]
end

#customer_columnObject



141
142
143
144
145
146
147
148
149
150
# File 'app/components/solidus_admin/orders/index/component.rb', line 141

def customer_column
  {
    col: { class: "w-[400px]" },
    header: :customer,
    data: ->(order) do
      customer_email = order.user&.email
       :div, String(customer_email)
    end
  }
end

#date_columnObject



132
133
134
135
136
137
138
139
# File 'app/components/solidus_admin/orders/index/component.rb', line 132

def date_column
  {
    header: :date,
    data: ->(order) do
       :div, l(order.created_at, format: :short)
    end
  }
end

#filtersObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/components/solidus_admin/orders/index/component.rb', line 43

def filters
  [
    {
      label: t('.filters.status'),
      combinator: 'or',
      attribute: "state",
      predicate: "eq",
      options: Spree::Order.state_machines[:state].states.map do |state|
        [
          state.value.titleize,
          state.value
        ]
      end
    },
    {
      label: t('.filters.shipment_state'),
      combinator: 'or',
      attribute: "shipment_state",
      predicate: "eq",
      options: %i[backorder canceled partial pending ready shipped].map do |option|
        [
          option.to_s.capitalize,
          option
        ]
      end
    },
    {
      label: t('.filters.payment_state'),
      combinator: 'or',
      attribute: "payment_state",
      predicate: "eq",
      options: %i[balance_due checkout completed credit_owed invalid paid pending processing void].map do |option|
        [
          option.to_s.titleize,
          option
        ]
      end
    },
    {
      label: t('.filters.store'),
      combinator: 'or',
      attribute: "store_id",
      predicate: "eq",
      options: Spree::Store.all.pluck(:name, :id)
    }
  ]
end

#items_columnObject



161
162
163
164
165
166
167
168
# File 'app/components/solidus_admin/orders/index/component.rb', line 161

def items_column
  {
    header: :items,
    data: ->(order) do
       :div, t('.columns.items', count: order.line_items.sum(:quantity))
    end
  }
end

#model_classObject



4
5
6
# File 'app/components/solidus_admin/orders/index/component.rb', line 4

def model_class
  Spree::Order
end

#number_columnObject



104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/components/solidus_admin/orders/index/component.rb', line 104

def number_column
  {
    header: :order,
    data: ->(order) do
      if !row_fade(order)
         :div, order.number, class: 'font-semibold'
      else
         :div, order.number
      end
    end
  }
end

#page_actionsObject



24
25
26
27
28
29
30
31
# File 'app/components/solidus_admin/orders/index/component.rb', line 24

def page_actions
  render component("ui/button").new(
    tag: :a,
    text: t('.add'),
    href: spree.new_admin_order_path,
    icon: "add-line",
  )
end

#payment_columnObject



170
171
172
173
174
175
176
177
# File 'app/components/solidus_admin/orders/index/component.rb', line 170

def payment_column
  {
    header: :payment,
    data: ->(order) do
      component('ui/badge').new(name: order.payment_state.humanize, color: order.paid? ? :green : :yellow) if order.payment_state?
    end
  }
end

#row_fade(order) ⇒ Object



20
21
22
# File 'app/components/solidus_admin/orders/index/component.rb', line 20

def row_fade(order)
  order.paid? && order.shipped?
end

#row_url(order) ⇒ Object



16
17
18
# File 'app/components/solidus_admin/orders/index/component.rb', line 16

def row_url(order)
  spree.edit_admin_order_path(order)
end

#scopesObject



33
34
35
36
37
38
39
40
41
# File 'app/components/solidus_admin/orders/index/component.rb', line 33

def scopes
  [
    { label: t('.scopes.complete'), name: 'completed', default: true },
    { label: t('.scopes.in_progress'), name: 'in_progress' },
    { label: t('.scopes.returned'), name: 'returned' },
    { label: t('.scopes.canceled'), name: 'canceled' },
    { label: t('.scopes.all_orders'), name: 'all' },
  ]
end

#search_keyObject



8
9
10
# File 'app/components/solidus_admin/orders/index/component.rb', line 8

def search_key
  :number_or_shipments_number_or_bill_address_name_or_email_cont
end

#search_urlObject



12
13
14
# File 'app/components/solidus_admin/orders/index/component.rb', line 12

def search_url
  solidus_admin.orders_path(scope: params[:scope])
end

#shipment_columnObject



179
180
181
182
183
184
185
186
# File 'app/components/solidus_admin/orders/index/component.rb', line 179

def shipment_column
  {
    header: :shipment,
    data: ->(order) do
      component('ui/badge').new(name: order.shipment_state.humanize, color: order.shipped? ? :green : :yellow) if order.shipment_state?
    end
  }
end

#state_columnObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/components/solidus_admin/orders/index/component.rb', line 117

def state_column
  {
    header: :state,
    data: ->(order) do
      color = {
        'complete' => :green,
        'returned' => :red,
        'canceled' => :blue,
        'cart' => :graphite_light,
      }[order.state] || :yellow
      component('ui/badge').new(name: order.state.humanize, color:)
    end
  }
end

#total_columnObject



152
153
154
155
156
157
158
159
# File 'app/components/solidus_admin/orders/index/component.rb', line 152

def total_column
  {
    header: :total,
    data: ->(order) do
       :div, number_to_currency(order.total)
    end
  }
end