Module: OrdersHelper
- Defined in:
- app/helpers/orders_helper.rb
Overview
View helper: orders.
Instance Method Summary collapse
- #build_order_party_hash(order) ⇒ Object
- #carrier_tag(shipment_entry) ⇒ Object
- #cod_text(order) ⇒ Object
- #create_new_order_button(context_object) ⇒ Object
- #display_order_update_alerts(order) ⇒ Object
- #display_ship_insurance_alerts(order) ⇒ Object
- #fields_for_order_shipping_cost(shipping_cost) ⇒ Object
-
#has_prepurchased_label?(order) ⇒ Boolean
Returns true if the order has an active pre-purchased shipping label that would be voided by cancel/hold/fraud actions.
- #order_command_options(order_presenter) ⇒ Object
- #order_tab_options ⇒ Object
-
#prepurchased_label_void_confirm(order, base_confirm_msg = nil) ⇒ String?
Build a confirmation message warning that a pre-purchased label will be voided.
- #price_edit_link(order) ⇒ Object
- #selectable_order_types ⇒ Object
- #setup_order(order) ⇒ Object
- #setup_order_billing_address(order) ⇒ Object
- #setup_order_shipping_address(order) ⇒ Object
Instance Method Details
#build_order_party_hash(order) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'app/helpers/orders_helper.rb', line 16 def build_order_party_hash(order) parties_hash = {} primary_party = order.opportunity && (order.primary_party != order.opportunity.primary_party) ? order.opportunity.primary_party : order.primary_party parties_hash["#{primary_party.full_name} (Primary)"] = primary_party parties_hash["#{order.customer.full_name} (Billing Customer)"] = { party: order.customer } if order.customer != primary_party append_opportunity_participants_hash(order.opportunity, parties_hash) if order.opportunity parties_hash end |
#carrier_tag(shipment_entry) ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/helpers/orders_helper.rb', line 40 def carrier_tag(shipment_entry) if shipment_entry.carrier_icon image_tag(shipment_entry.carrier_icon) elsif shipment_entry.carrier.present? fa_icon('truck', text: shipment_entry.carrier) end end |
#cod_text(order) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/orders_helper.rb', line 48 def cod_text(order) return '' if order.nil? if order.cod_collection_type == 'no_check' 'COD (certified check or money order required)' elsif order.cod_collection_type == 'check' 'COD (business check)' else '' end end |
#create_new_order_button(context_object) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/orders_helper.rb', line 139 def (context_object) actions = [] Order::UNRESTRICTED_ORDER_TYPES.each do |order_type, order_type_label| next unless can?(:create, Order.new(order_type: order_type)) actions << link_to(order_type_label, polymorphic_path([context_object, :order], action: :new, order_type: order_type), class: 'dropdown-item', data: { turbo_submits_with: 'Please wait...' }) end render_simple_drop_down(['Create new order'] + actions) end |
#display_order_update_alerts(order) ⇒ Object
131 132 133 |
# File 'app/helpers/orders_helper.rb', line 131 def display_order_update_alerts(order) render partial: '/shared/order_alerts', locals: { order: order } end |
#display_ship_insurance_alerts(order) ⇒ Object
135 136 137 |
# File 'app/helpers/orders_helper.rb', line 135 def display_ship_insurance_alerts(order) render partial: '/shared/ship_insurance_alerts', locals: { ship_quotable: order } end |
#fields_for_order_shipping_cost(shipping_cost) ⇒ Object
5 6 7 8 |
# File 'app/helpers/orders_helper.rb', line 5 def fields_for_order_shipping_cost(shipping_cost, &) prefix = shipping_cost.new_record? ? 'new' : 'existing' fields_for("order[#{prefix}_shipping_cost_attributes][]", shipping_cost, &) end |
#has_prepurchased_label?(order) ⇒ Boolean
Returns true if the order has an active pre-purchased shipping label
that would be voided by cancel/hold/fraud actions.
180 181 182 |
# File 'app/helpers/orders_helper.rb', line 180 def has_prepurchased_label?(order) order&.has_early_purchased_label? == true end |
#order_command_options(order_presenter) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/helpers/orders_helper.rb', line 60 def (order_presenter) opts = [] opts << if order_presenter.awaiting_future_deliveries? 'Awaiting Future Deliveries' else order_presenter.order.human_state_name.titleize end state_description = order_presenter.order.try(:state_description) opts << { content: state_description } if state_description.present? # opts << { class: 'divider' } opts += order_presenter.actions opts.compact end |
#order_tab_options ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/helpers/orders_helper.rb', line 86 def { line_items: { remote_href: tab_line_items_order_path(@order) }, main: { remote_href: tab_main_order_path(@order) }, contacts: { remote_href: tab_contacts_order_path(@order) }, shipping: { remote_href: tab_shipping_order_path(@order) }, activities: { counter: @order.open_activities_counter, remote_href: tab_activities_order_path(@order, selected_activity: params[:selected_activity]) }, communications: { remote_href: tab_communications_order_path(@order) }, sms: { remote_href: tab_sms_order_path(@order), counter: @order..unread.size }, payments: { remote_href: tab_payments_order_path(@order) }, rooms: { counter: @order.room_configurations.size, title: +'Rooms & Areas', remote_href: tab_rooms_order_path(@order) }, attachments: { counter: @order.all_uploads.size, remote_href: (@order) }, tickets: { title: 'Tickets', counter_html: tech_counter_badge(@order.support_cases), remote_href: tab_tickets_order_path(@order) }, inventory: { remote_href: tab_inventory_order_path(@order) }, invoices: { remote_href: tab_invoices_order_path(@order) }, rmas: { counter: @order.rmas.rma_active.size, remote_href: tab_rmas_order_path(@order) }, credit_memos: { remote_href: tab_credit_memos_order_path(@order) }, material_alerts: { remote_href: tab_material_alerts_order_path(@order) }, reviews: { remote_href: tab_reviews_order_path(@order) }, marketing: { title: 'Marketing', remote_href: tab_marketing_order_path(@order) }, edi_documents: { title: 'EDI', counter: @order.edi_communication_logs.size, remote_href: tab_edi_documents_order_path(@order) } }.tap { |h| h.delete(:edi_documents) if h[:edi_documents][:counter].zero? } end |
#prepurchased_label_void_confirm(order, base_confirm_msg = nil) ⇒ String?
Build a confirmation message warning that a pre-purchased label will be voided.
Returns nil if the order has no active pre-purchased label.
164 165 166 167 168 169 170 171 172 173 |
# File 'app/helpers/orders_helper.rb', line 164 def prepurchased_label_void_confirm(order, base_confirm_msg = nil) return base_confirm_msg unless order&.has_early_purchased_label? warning = "⚠️ WARNING: This order has a pre-purchased shipping label " \ "(#{order.early_label_carrier} — #{order.early_label_tracking_number}). " \ "This action will VOID the pre-purchased label. " \ "A new label will need to be purchased when the order is ready to ship." base_confirm_msg.present? ? "#{warning}\n\n#{base_confirm_msg}" : warning end |
#price_edit_link(order) ⇒ Object
74 75 76 77 78 |
# File 'app/helpers/orders_helper.rb', line 74 def price_edit_link(order) return unless order.is_price_editable? link_to_if can?(:edit_prices, order), 'Edit Prices', url_for(controller: 'orders', action: 'price_edit', id: order.id), class: 'btn btn-outline-primary', data: { turbo_frame: '_top' } end |
#selectable_order_types ⇒ Object
80 81 82 83 84 |
# File 'app/helpers/orders_helper.rb', line 80 def selectable_order_types Order.selectable_order_types.select do |(_order_type_label, order_type)| can?(:create, Order.new(order_type: order_type)) end end |
#setup_order(order) ⇒ Object
10 11 12 13 14 |
# File 'app/helpers/orders_helper.rb', line 10 def setup_order(order) order.tap do |o| o.opportunity ||= Opportunity.new end end |
#setup_order_billing_address(order) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'app/helpers/orders_helper.rb', line 25 def setup_order_billing_address(order) order.tap do |o| if o.billing_address.nil? o.billing_address = o.customer.billing_address o.billing_address ||= Address.new(country_iso3: @customer.catalog.store.country_iso3, party_id: o.customer_id) end end end |
#setup_order_shipping_address(order) ⇒ Object
34 35 36 37 38 |
# File 'app/helpers/orders_helper.rb', line 34 def setup_order_shipping_address(order) order.tap do |o| o.shipping_address = o.customer.try(:shipping_address).try(:clone) || o.customer.addresses.first.try(:clone) if o.shipping_address_id.nil? end end |