Class: Spree::Admin::OrderSummaryPresenter
- Inherits:
-
Object
- Object
- Spree::Admin::OrderSummaryPresenter
- 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
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #additional_tax_row ⇒ Object
- #channel_row ⇒ Object
- #currency_row ⇒ Object
- #custom_adjustment_rows ⇒ Object
- #included_tax_row ⇒ Object
-
#initialize(order) ⇒ OrderSummaryPresenter
constructor
A new instance of OrderSummaryPresenter.
- #locale_row ⇒ Object
- #manual_adjustments_row ⇒ Object
- #market_row ⇒ Object
- #metadata_rows ⇒ Object
- #outstanding_balance_row ⇒ Object
- #payment_total_row ⇒ Object
- #promo_row ⇒ Object
- #rows ⇒ Object
- #shipping_row ⇒ Object
- #subtotal_row ⇒ Object
- #total_row ⇒ Object
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
#order ⇒ Object (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_row ⇒ Object
181 182 183 184 185 186 187 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 181 def additional_tax_row { label: Spree.t(:tax), value: order.display_additional_tax_total, id: 'additional_tax_total' } end |
#channel_row ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 77 def channel_row return nil if order.channel.blank? { label: Spree.t(:channel), value: order.channel.name, id: 'channel', link: Spree::Core::Engine.routes.url_helpers.edit_admin_channel_path(order.channel) } end |
#currency_row ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 109 def currency_row { label: Spree.t(:currency), value: order.currency, id: 'currency', type: :code } end |
#custom_adjustment_rows ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 158 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_row ⇒ Object
173 174 175 176 177 178 179 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 173 def included_tax_row { label: Spree.t(:tax_included), value: order.display_included_tax_total, id: 'included_tax_total' } end |
#locale_row ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 98 def locale_row return nil if order.locale.blank? { label: Spree.t(:locale), value: order.locale, id: 'locale', type: :code } end |
#manual_adjustments_row ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 146 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_row ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 88 def market_row return nil if order.market.blank? { label: Spree.t(:market), value: order.market.name, id: 'market' } end |
#metadata_rows ⇒ Object
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 75 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 34 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_row ⇒ Object
207 208 209 210 211 212 213 214 215 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 207 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_row ⇒ Object
198 199 200 201 202 203 204 205 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 198 def payment_total_row { label: Spree.t(:payment_total), value: order.display_payment_total, id: 'payment_total', highlight: true } end |
#promo_row ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 136 def promo_row return nil if order.promo_total.zero? { label: Spree.t(:discount_amount), value: order.display_promo_total, id: 'promo_total' } end |
#rows ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 12 def rows [ *, :separator, channel_row, 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_row ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 126 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_row ⇒ Object
118 119 120 121 122 123 124 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 118 def subtotal_row { label: Spree.t(:subtotal), value: order.display_item_total, id: 'item_total' } end |
#total_row ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'app/presenters/spree/admin/order_summary_presenter.rb', line 189 def total_row { label: Spree.t(:total), value: order.display_total, id: 'order_total', bold: true } end |