Class: SpreeBatchCapture::Formatter::SimpleCsv

Inherits:
Object
  • Object
show all
Defined in:
lib/spree_batch_capture/formatter/simple_csv.rb

Class Method Summary collapse

Class Method Details

.header(line_item) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/spree_batch_capture/formatter/simple_csv.rb', line 23

def self.header(line_item)
  head = []
  sections.each do |section|
    head << extract_field_names(section, line_item)
  end
  Rails.logger.debug "Exporting Header: #{head.flatten}:: #{head.flatten.to_csv}"
  return head.flatten.to_csv
end

.transform(order) ⇒ Object

Takes an order and returns 1 or more csv rows



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/spree_batch_capture/formatter/simple_csv.rb', line 6

def self.transform(order)
  return "" if order.nil? || order.id.nil?

  line_items = LineItem.includes(:order => [:ship_address, :bill_address], :variant => :product).where(:order_id => order.id)

  content = ""
  if line_items && line_items.count > 0
    content = CSV.generate do |csv|

      line_items.each do |line_item|
        csv << values(line_item)
      end
    end
  end
  return content
end