Class: Spree::CSV::CustomerPresenter

Inherits:
Object
  • Object
show all
Includes:
MetafieldsHelper
Defined in:
app/presenters/spree/csv/customer_presenter.rb

Constant Summary collapse

HEADERS =
[
  'First Name',
  'Last Name',
  'Email',
  'Accepts Email Marketing',
  'Company',
  'Address 1',
  'Address 2',
  'City',
  'Province',
  'Province Code',
  'Country',
  'Country Code',
  'Zip',
  'Phone',
  'Total Spent',
  'Total Orders',
  'Tags'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(customer) ⇒ CustomerPresenter

Returns a new instance of CustomerPresenter.



26
27
28
# File 'app/presenters/spree/csv/customer_presenter.rb', line 26

def initialize(customer)
  @customer = customer
end

Instance Attribute Details

#customerObject

Returns the value of attribute customer.



30
31
32
# File 'app/presenters/spree/csv/customer_presenter.rb', line 30

def customer
  @customer
end

Instance Method Details

#callObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/presenters/spree/csv/customer_presenter.rb', line 32

def call
  csv = [
    customer.first_name,
    customer.last_name,
    customer.email,
    customer.accepts_email_marketing ? Spree.t(:say_yes) : Spree.t(:say_no),
    customer.address&.company,
    customer.address&.address1,
    customer.address&.address2,
    customer.address&.city,
    customer.address&.state_text,
    customer.address&.state_abbr,
    customer.address&.country&.name,
    customer.address&.country&.iso,
    customer.address&.zipcode,
    customer.phone,
    customer.amount_spent_in(Spree::Store.current.default_currency),
    customer.completed_orders.count,
    customer.tag_list
  ]

  csv += metafields_for_csv(customer)

  csv
end