Class: Spree::Admin::OrderSummaryPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree/admin/order_summary_presenter.rb

Constant Summary collapse

SPREE_ADJUSTMENT_SOURCE_TYPES =
['Spree::PromotionAction', 'Spree::TaxRate'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ OrderSummaryPresenter

Returns a new instance of OrderSummaryPresenter.



8
9
10
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 8

def initialize(order)
  @order = order
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



6
7
8
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 6

def order
  @order
end

Instance Method Details

#additional_tax_rowObject



169
170
171
172
173
174
175
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 169

def additional_tax_row
  {
    label: Spree.t(:tax),
    value: order.display_additional_tax_total,
    id: 'additional_tax_total'
  }
end

#currency_rowObject



97
98
99
100
101
102
103
104
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 97

def currency_row
  {
    label: Spree.t(:currency),
    value: order.currency,
    id: 'currency',
    type: :code
  }
end

#custom_adjustment_rowsObject



146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 146

def custom_adjustment_rows
  custom_adjustments = order.all_adjustments.eligible.where.not(source_type: [nil, *SPREE_ADJUSTMENT_SOURCE_TYPES])

  custom_adjustments.group_by(&:source_type).map do |source_type, adjustments|
    total = adjustments.sum(&:amount)
    next nil if total.zero?

    {
      label: translate_source_type(source_type),
      value: Spree::Money.new(total, currency: order.currency),
      id: source_type.demodulize.underscore
    }
  end.compact
end

#included_tax_rowObject



161
162
163
164
165
166
167
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 161

def included_tax_row
  {
    label: Spree.t(:tax_included),
    value: order.display_included_tax_total,
    id: 'included_tax_total'
  }
end

#locale_rowObject



86
87
88
89
90
91
92
93
94
95
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 86

def locale_row
  return nil if order.locale.blank?

  {
    label: Spree.t(:locale),
    value: order.locale,
    id: 'locale',
    type: :code
  }
end

#manual_adjustments_rowObject



134
135
136
137
138
139
140
141
142
143
144
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 134

def manual_adjustments_row
  manual_adjustments = order.all_adjustments.eligible.where(source_type: nil)
  total = manual_adjustments.sum(:amount)
  return nil if total.zero?

  {
    label: Spree.t(:manual_adjustments),
    value: Spree::Money.new(total, currency: order.currency),
    id: 'manual_adjustments_total'
  }
end

#market_rowObject



76
77
78
79
80
81
82
83
84
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 76

def market_row
  return nil if order.market.blank?

  {
    label: Spree.t(:market),
    value: order.market.name,
    id: 'market'
  }
end

#metadata_rowsObject



33
34
35
36
37
38
39
40
41
42
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
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 33

def 
  rows = []

  if order.created_by.present?
    rows << {
      label: Spree.t(:created_by),
      value: order.created_by.name,
      link: Spree::Core::Engine.routes.url_helpers.admin_admin_user_path(order.created_by)
    }
  end

  rows << {
    label: Spree.t(:created_at),
    value: order.created_at,
    type: :datetime
  }

  if order.completed_at.present?
    rows << {
      label: I18n.t('activerecord.attributes.spree/order.completed_at'),
      value: order.completed_at,
      type: :datetime
    }
  end

  if order.canceled? && order.canceled_at.present?
    rows << {
      label: Spree.t(:canceled_at),
      value: order.canceled_at,
      type: :datetime
    }

    if order.canceler.present?
      rows << {
        label: Spree.t(:canceler),
        value: order.canceler.name
      }
    end
  end

  rows
end

#outstanding_balance_rowObject



195
196
197
198
199
200
201
202
203
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 195

def outstanding_balance_row
  {
    label: Spree.t(:outstanding_balance),
    value: order.display_outstanding_balance,
    id: 'outstanding_balance',
    highlight: true,
    danger: order.outstanding_balance > 0
  }
end

#payment_total_rowObject



186
187
188
189
190
191
192
193
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 186

def payment_total_row
  {
    label: Spree.t(:payment_total),
    value: order.display_payment_total,
    id: 'payment_total',
    highlight: true
  }
end

#promo_rowObject



124
125
126
127
128
129
130
131
132
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 124

def promo_row
  return nil if order.promo_total.zero?

  {
    label: Spree.t(:discount_amount),
    value: order.display_promo_total,
    id: 'promo_total'
  }
end

#rowsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 12

def rows
  [
    *,
    :separator,
    market_row,
    locale_row,
    currency_row,
    subtotal_row,
    shipping_row,
    promo_row,
    manual_adjustments_row,
    *custom_adjustment_rows,
    included_tax_row,
    additional_tax_row,
    total_row,
    :separator,
    payment_total_row,
    outstanding_balance_row
  ].compact
end

#shipping_rowObject



114
115
116
117
118
119
120
121
122
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 114

def shipping_row
  return nil unless order.checkout_steps.include?('delivery') && order.ship_total > 0

  {
    label: Spree.t(:ship_total),
    value: order.display_ship_total,
    id: 'ship_total'
  }
end

#subtotal_rowObject



106
107
108
109
110
111
112
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 106

def subtotal_row
  {
    label: Spree.t(:subtotal),
    value: order.display_item_total,
    id: 'item_total'
  }
end

#total_rowObject



177
178
179
180
181
182
183
184
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 177

def total_row
  {
    label: Spree.t(:total),
    value: order.display_total,
    id: 'order_total',
    bold: true
  }
end