Module: MyAccountHelper

Overview

View helper: my account.

Instance Method Summary collapse

Instance Method Details

#account_nav_active?(path) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/helpers/my_account_helper.rb', line 39

def (path)
  request.path == path || request.path.start_with?("#{path}/")
end

#can_list_contact_resources?(cur_user) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/helpers/my_account_helper.rb', line 35

def can_list_contact_resources?(cur_user)
  cur_user.customer.is_organization? and cur_user.can_list_all_contact_resources? and cur_user.customer.contacts.any?
end

#is_current_user_or_customer_login_email?(cur_user, cp_detail) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/helpers/my_account_helper.rb', line 31

def (cur_user, cp_detail)
  (cur_user. and cp_detail == cur_user..email) or (cur_user.customer&. and cp_detail == cur_user.customer..email)
end

#setup_contact(contact) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'app/helpers/my_account_helper.rb', line 17

def setup_contact(contact)
  contact.tap do |con|
    missing_contact_points = [ContactPoint::EMAIL, ContactPoint::PHONE, ContactPoint::FAX] - con.contact_points.map(&:category)
    missing_contact_points.each do |cat|
      con.contact_points.build({ category: cat })
    end
    con.customer.contacts.build if con.customer && con.customer.contacts.empty?
  end
end

#setup_customer_account(customer) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/my_account_helper.rb', line 4

def (customer)
  customer.tap do |cust|
    missing_contact_points = [ContactPoint::EMAIL, ContactPoint::PHONE, ContactPoint::FAX] - cust.contact_points.map(&:category)
    missing_contact_points.each do |cat|
      cp = cust.contact_points.build({ category: cat })
      cp.detail = .email if (cat == ContactPoint::EMAIL) && 
    end
    cust.contacts.build if cust.customer.contacts.empty?
    cust.build_billing_address(country_iso3: cust.catalog.store.country_iso3) unless cust.billing_address
    cust.clear_names if cust.has_guest_name?
  end
end

#sorted_contact_points(party, first_email_detail = nil) ⇒ Object



27
28
29
# File 'app/helpers/my_account_helper.rb', line 27

def sorted_contact_points(party, first_email_detail = nil)
  party.contact_points.sort_by { |cp| cp.detail == first_email_detail ? -1 : { ContactPoint::EMAIL => 0, ContactPoint::PHONE => 1, ContactPoint::CELL => 2, ContactPoint::FAX => 3, ContactPoint::WEBSITE => 4 }[cp.category] || 5 }
end