Module: EffectiveOrdersHelper
- Defined in:
- app/helpers/effective_orders_helper.rb
Instance Method Summary collapse
-
#acts_as_purchasable_path(purchasable, action = :show) ⇒ Object
This is called on the My Sales Page and is intended to be overridden in the app if needed.
- #checkout_step1_form_url(order, namespace = nil) ⇒ Object
- #link_to_my_purchases(opts = {}) ⇒ Object (also: #link_to_order_history)
- #order_checkout_label(processor = nil) ⇒ Object
- #order_item_summary(order_item) ⇒ Object
- #order_payment_to_html(order) ⇒ Object
- #order_summary(order) ⇒ Object
- #payment_card_label(card) ⇒ Object
- #price_to_currency(price) ⇒ Object
- #render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil) ⇒ Object (also: #render_checkout)
- #render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil) ⇒ Object
- #render_order(order) ⇒ Object
- #render_orders(obj, opts = {}) ⇒ Object (also: #render_purchases, #render_my_purchases, #render_order_history)
- #tax_rate_to_percentage(tax_rate, options = {}) ⇒ Object
Instance Method Details
#acts_as_purchasable_path(purchasable, action = :show) ⇒ Object
This is called on the My Sales Page and is intended to be overridden in the app if needed
61 62 63 |
# File 'app/helpers/effective_orders_helper.rb', line 61 def acts_as_purchasable_path(purchasable, action = :show) polymorphic_path(purchasable) end |
#checkout_step1_form_url(order, namespace = nil) ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'app/helpers/effective_orders_helper.rb', line 116 def checkout_step1_form_url(order, namespace = nil) raise 'expected an order' unless order raise 'invalid namespace, expecting nil or :admin' unless [nil, :admin].include?(namespace) if order.new_record? namespace == nil ? effective_orders.orders_path : effective_orders.admin_orders_path else namespace == nil ? effective_orders.order_path(order) : effective_orders.checkout_admin_order_path(order) end end |
#link_to_my_purchases(opts = {}) ⇒ Object Also known as: link_to_order_history
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/helpers/effective_orders_helper.rb', line 127 def link_to_my_purchases(opts = {}) = { label: 'My Purchases', class: 'btn btn-default', rel: :nofollow }.merge(opts) label = .delete(:label) [:class] = (([:class] || '') + ' btn-my-purchases') link_to(label, effective_orders.my_purchases_orders_path, ) end |
#order_checkout_label(processor = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/effective_orders_helper.rb', line 35 def order_checkout_label(processor = nil) return 'Checkout' if (EffectiveOrders.single_payment_processor? && ![:pretend, :mark_as_paid, :free, :refund].include?(processor)) case processor when :mark_as_paid 'Mark as paid' when :free 'Checkout free' when :refund 'Complete refund' when :moneris, :stripe, :ccbill 'Checkout with credit card' when :paypal 'Checkout with PayPal' when :pretend EffectiveOrders.allow_pretend_purchase_in_production ? 'Purchase Order' : 'Purchase Order (development only)' when :cheque 'Pay by cheque' when :app_checkout EffectiveOrders.app_checkout[:checkout_label].presence || 'Checkout' else 'Checkout' end end |
#order_item_summary(order_item) ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/helpers/effective_orders_helper.rb', line 27 def order_item_summary(order_item) if order_item.quantity > 1 content_tag(:p, "#{price_to_currency(order_item.total)} total for #{pluralize(order_item.quantity, 'item')}") else content_tag(:p, "#{price_to_currency(order_item.total)} total") end end |
#order_payment_to_html(order) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/effective_orders_helper.rb', line 65 def order_payment_to_html(order) payment = order.payment if order.purchased?(:stripe_connect) && order.payment.kind_of?(Hash) payment = Hash[ order.payment.map do |seller_id, v| if (user = Effective::Customer.find(seller_id).try(:user)) [link_to(user, admin_user_path(user)), order.payment[seller_id]] else [seller_id, order.payment[seller_id]] end end ] end content_tag(:pre) do raw JSON.pretty_generate(payment).html_safe .gsub('\"', '') .gsub("[\n\n ]", '[]') .gsub("{\n }", '{}') end end |
#order_summary(order) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/effective_orders_helper.rb', line 13 def order_summary(order) order_item_list = content_tag(:ul) do order.order_items.map do |item| content_tag(:li) do title = item.title.split('<br>') "#{item.quantity}x #{title.first} for #{price_to_currency(item.price)}".tap do |output| title[1..-1].each { |line| output << "<br>#{line}" } end.html_safe end end.join.html_safe end content_tag(:p, "#{price_to_currency(order.total)} total for #{pluralize(order.num_items, 'item')}:") + order_item_list end |
#payment_card_label(card) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/helpers/effective_orders_helper.rb', line 156 def payment_card_label(card) card = card.to_s.downcase.gsub(' ', '').strip case card when '' 'None' when 'v', 'visa' 'Visa' when 'm', 'mc', 'master', 'mastercard' 'MasterCard' when 'a', 'ax', 'american', 'americanexpress' 'American Express' when 'd', 'discover' 'Discover' else card.to_s end end |
#price_to_currency(price) ⇒ Object
2 3 4 5 6 |
# File 'app/helpers/effective_orders_helper.rb', line 2 def price_to_currency(price) price = price || 0 raise 'price_to_currency expects an Integer representing the number of cents' unless price.kind_of?(Integer) number_to_currency(price / 100.0) end |
#render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil) ⇒ Object Also known as: render_checkout
92 93 94 95 96 97 98 |
# File 'app/helpers/effective_orders_helper.rb', line 92 def render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil) raise 'unable to checkout an order without a user' unless order && order.user locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, namespace: namespace } render partial: 'effective/orders/checkout_step1', locals: locals end |
#render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/effective_orders_helper.rb', line 101 def render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil) raise 'unable to checkout an order without a user' unless order && order.user purchased_url ||= session["effective_orders_#{order.id}_purchased_url"] declined_url ||= session["effective_orders_#{order.id}_declined_url"] locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, namespace: namespace } if order.new_record? || !order.valid? render(partial: 'effective/orders/checkout_step1', locals: locals) else render(partial: 'effective/orders/checkout_step2', locals: locals) end end |
#render_order(order) ⇒ Object
88 89 90 |
# File 'app/helpers/effective_orders_helper.rb', line 88 def render_order(order) render(partial: 'effective/orders/order', locals: { order: order }) end |
#render_orders(obj, opts = {}) ⇒ Object Also known as: render_purchases, render_my_purchases, render_order_history
142 143 144 145 146 147 148 149 150 |
# File 'app/helpers/effective_orders_helper.rb', line 142 def render_orders(obj, opts = {}) orders = Array(obj.kind_of?(User) ? Effective::Order.purchased_by(obj) : obj) if orders.any? { |order| order.kind_of?(Effective::Order) == false } raise 'expected a User or Effective::Order' end render(partial: 'effective/orders/orders_table', locals: { orders: orders }.merge(opts)) end |
#tax_rate_to_percentage(tax_rate, options = {}) ⇒ Object
8 9 10 11 |
# File 'app/helpers/effective_orders_helper.rb', line 8 def tax_rate_to_percentage(tax_rate, = {}) [:strip_insignificant_zeros] = true if [:strip_insignificant_zeros].nil? number_to_percentage(tax_rate, strip_insignificant_zeros: true) end |