Module: Models::CustomerDisplay
- Extended by:
- ActiveSupport::Concern
- Included in:
- Customer
- Defined in:
- app/concerns/models/customer_display.rb
Overview
Display, formatting, CRM links, locale, and select-option helpers for Customer.
Delegated Instance Attributes collapse
-
#company ⇒ Object
Alias for Catalog#company.
-
#customer_service_manager ⇒ Object
Alias for Catalog#customer_service_manager.
Class Method Summary collapse
-
.affiliations_for_select ⇒ Array<String>
Affiliation choices for select dropdowns.
-
.customer_is_real?(customer) ⇒ Boolean
Whether the customer is a real customer rather than the website's own walk-in account.
-
.options_for_terms_select ⇒ Array<String>
Payment-term choices for select dropdowns.
-
.select_number_of_offices ⇒ Array<Array(String, String)>
Number-of-offices range choices for select dropdowns.
-
.select_projects ⇒ Array<Array(String, String)>
Projects-per-year range choices for select dropdowns.
-
.states_for_select ⇒ Array<Array(String, String)>
Customer state choices as label/value pairs for select dropdowns.
Instance Method Summary collapse
-
#billing_address_attributes ⇒ Hash?
Attributes of the customer's billing address, if any.
-
#country ⇒ String?
The customer's country, falling back to the country of their catalog's store.
-
#locale ⇒ String, ...
The customer's locale, derived from their catalog when available.
-
#main_address ⇒ Address?
The customer's preferred address: mailing, then shipping, then billing, then the default.
-
#online? ⇒ Boolean
Whether the customer can log in online.
-
#product_review_delay_months ⇒ Integer
Number of months to wait before requesting a product review from this customer.
-
#reference_number ⇒ String
The customer's reference number.
-
#to_label ⇒ String
Label for select dropdowns and pickers.
-
#to_s ⇒ String
Human-readable identifier for the customer.
Class Method Details
.affiliations_for_select ⇒ Array<String>
Affiliation choices for select dropdowns.
18 19 20 |
# File 'app/concerns/models/customer_display.rb', line 18 def affiliations_for_select CustomerConstants::AFFILIATIONS end |
.customer_is_real?(customer) ⇒ Boolean
Whether the customer is a real customer rather than the website's own walk-in account.
34 35 36 37 38 |
# File 'app/concerns/models/customer_display.rb', line 34 def customer_is_real?(customer) return false unless customer&.account customer.account.login != 'www_warmlyyours_com' end |
.options_for_terms_select ⇒ Array<String>
Payment-term choices for select dropdowns.
44 45 46 47 |
# File 'app/concerns/models/customer_display.rb', line 44 def [Customer::TERM_DUE, Customer::TERM_NET15, Customer::TERM_NET30, Customer::TERM_NET37, Customer::TERM_NET45, Customer::TERM_NET60, Customer::TERM_NET90] end |
.select_number_of_offices ⇒ Array<Array(String, String)>
Number-of-offices range choices for select dropdowns.
60 61 62 |
# File 'app/concerns/models/customer_display.rb', line 60 def select_number_of_offices [%w[Unknown unknown]] + CustomerConstants::NUMBER_OF_OFFICES.map { |range| [range, range] } end |
.select_projects ⇒ Array<Array(String, String)>
Projects-per-year range choices for select dropdowns.
53 54 55 |
# File 'app/concerns/models/customer_display.rb', line 53 def select_projects [%w[Unknown unknown]] + CustomerConstants::PROJECTS_PER_YEAR.map { |range| [range, range] } end |
.states_for_select ⇒ Array<Array(String, String)>
Customer state choices as label/value pairs for select dropdowns.
25 26 27 |
# File 'app/concerns/models/customer_display.rb', line 25 def states_for_select state_machines[:state].states.map { |sm_state| [sm_state.human_name, sm_state.value] } end |
Instance Method Details
#billing_address_attributes ⇒ Hash?
Attributes of the customer's billing address, if any.
117 118 119 120 121 |
# File 'app/concerns/models/customer_display.rb', line 117 def billing_address_attributes billing_address.attributes rescue StandardError nil end |
#company ⇒ Object
Alias for Catalog#company
10 |
# File 'app/concerns/models/customer_display.rb', line 10 delegate :company, to: :catalog |
#country ⇒ String?
The customer's country, falling back to the country of their catalog's store.
82 83 84 |
# File 'app/concerns/models/customer_display.rb', line 82 def country super || catalog&.store&.country end |
#customer_service_manager ⇒ Object
Alias for Catalog#customer_service_manager
11 |
# File 'app/concerns/models/customer_display.rb', line 11 delegate :customer_service_manager, to: :catalog |
#locale ⇒ String, ...
The customer's locale, derived from their catalog when available.
75 76 77 |
# File 'app/concerns/models/customer_display.rb', line 75 def locale Catalog.catalog_id_to_locale(catalog_id) || super end |
#main_address ⇒ Address?
The customer's preferred address: mailing, then shipping, then billing, then the default.
68 69 70 |
# File 'app/concerns/models/customer_display.rb', line 68 def main_address mailing_address || shipping_address || billing_address || super end |
#online? ⇒ Boolean
Whether the customer can log in online.
103 104 105 |
# File 'app/concerns/models/customer_display.rb', line 103 def online? account.present? end |
#product_review_delay_months ⇒ Integer
Number of months to wait before requesting a product review from this customer.
126 127 128 129 130 131 132 |
# File 'app/concerns/models/customer_display.rb', line 126 def product_review_delay_months if homeowner? Customer::HOMEOWNER_PRODUCT_REVIEW_DELAY_MONTHS else Customer::TRADE_PRO_PRODUCT_REVIEW_DELAY_MONTHS end end |
#reference_number ⇒ String
The customer's reference number.
110 111 112 |
# File 'app/concerns/models/customer_display.rb', line 110 def reference_number "CN#{id}" end |
#to_label ⇒ String
Label for select dropdowns and pickers.
96 97 98 |
# File 'app/concerns/models/customer_display.rb', line 96 def to_label "[CN#{id}] #{full_name}" end |
#to_s ⇒ String
Human-readable identifier for the customer.
89 90 91 |
# File 'app/concerns/models/customer_display.rb', line 89 def to_s "#{full_name} [CN#{id}]" end |