Module: MyAccountHelper

Instance Method Summary collapse

Instance Method Details

#account_nav_active?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#can_list_contact_resources?(cur_user) ⇒ Boolean

Returns:

  • (Boolean)


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

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.count > 0
end

#is_current_user_or_customer_login_email?(cur_user, cp_detail) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#setup_contact(contact) ⇒ Object



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

def setup_contact(contact)
  contact.tap do |con|
    missing_contact_points = [ContactPoint::EMAIL,ContactPoint::PHONE,ContactPoint::FAX] - con.contact_points.map{|cpinc| cpinc.category}
    missing_contact_points.each do |cat|
      cp = 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



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

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 and 
    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



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

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