Class: Spree::CSV::OrderLineItemPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree/csv/order_line_item_presenter.rb

Constant Summary collapse

HEADERS =
[
  'Number',
  'Email',
  'Status',
  'Currency',
  'Subtotal',
  'Shipping',
  'Taxes',
  'Taxes included',
  'Discount Used',
  'Free Shipping',
  'Discount',
  'Discount Code',
  'Store Credit amount',
  'Total',
  'Shipping method',
  'Total weight',
  'Payment Type Used',
  'Product ID',
  'Item Quantity',
  'Item SKU',
  'Item Name',
  'Item Price',
  'Item Total Discount',
  'Item Total Price',
  'Item requires shipping',
  'Item taxbale',
  'Item Vendor',
  'Category lvl0',
  'Category lvl1',
  'Category lvl2',
  'Category lvl3',
  'Category lvl4',
  'Billing Name',
  'Billing Address 1',
  'Billing Address 2',
  'Billing Company',
  'Billing City',
  'Billing Zip',
  'Billing State',
  'Billing Country',
  'Billing Phone',
  'Shipping Name',
  'Shipping Address 1',
  'Shipping Address 2',
  'Shipping Company',
  'Shipping City',
  'Shipping Zip',
  'Shipping State',
  'Shipping Country',
  'Shipping Phone',
  'Placed at',
  'Shipped at',
  'Cancelled at',
  'Cancelled by',
  'Notes'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, line_item, index, metafields = []) ⇒ OrderLineItemPresenter

Returns a new instance of OrderLineItemPresenter.



62
63
64
65
66
67
# File 'app/presenters/spree/csv/order_line_item_presenter.rb', line 62

def initialize(order, line_item, index, metafields = [])
  @order = order
  @line_item = line_item
  @index = index
  @metafields = metafields
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



69
70
71
# File 'app/presenters/spree/csv/order_line_item_presenter.rb', line 69

def index
  @index
end

#line_itemObject

Returns the value of attribute line_item.



69
70
71
# File 'app/presenters/spree/csv/order_line_item_presenter.rb', line 69

def line_item
  @line_item
end

#metafieldsObject

Returns the value of attribute metafields.



69
70
71
# File 'app/presenters/spree/csv/order_line_item_presenter.rb', line 69

def metafields
  @metafields
end

#orderObject

Returns the value of attribute order.



69
70
71
# File 'app/presenters/spree/csv/order_line_item_presenter.rb', line 69

def order
  @order
end

Instance Method Details

#callObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/presenters/spree/csv/order_line_item_presenter.rb', line 71

def call
  csv = [
    order.number,
    index.zero? ? order.email : nil,
    index.zero? ? order.state : nil,
    index.zero? ? order.currency : nil,
    index.zero? ? order.item_total.to_f : nil,
    index.zero? ? order.shipment_total.to_f : nil,
    index.zero? ? order.tax_total.to_f : nil,
    index.zero? ? order.included_tax_total.positive? : nil,
    index.zero? ? (order.promo_total.negative? || line_item.promo_total.negative?) : nil,
    index.zero? ? order.has_free_shipping? : nil,
    index.zero? ? order.promo_total.abs : nil,
    index.zero? ? order.promo_code : nil,
    index.zero? ? order.payments.store_credits.sum(:amount).abs : nil,
    index.zero? ? order.total.to_f : nil,
    index.zero? ? order.shipping_method&.name : nil,
    index.zero? ? order.total_weight.to_f : nil,
    index.zero? ? order.payments.valid&.first&.display_source_name : nil,
    line_item.product_id,
    line_item.quantity,
    line_item.sku,
    line_item.name,
    line_item.price,
    line_item.promo_total.abs,
    line_item.total,
    !line_item.product.digital?,
    line_item.product.tax_category_id.present?,
    line_item.product.try(:vendor_name),
    taxon_dict(line_item.product.main_taxon)[0],
    taxon_dict(line_item.product.main_taxon)[1],
    taxon_dict(line_item.product.main_taxon)[2],
    taxon_dict(line_item.product.main_taxon)[3],
    taxon_dict(line_item.product.main_taxon)[4],
    index.zero? ? order.bill_address&.full_name : nil,
    index.zero? ? order.bill_address&.address1 : nil,
    index.zero? ? order.bill_address&.address2 : nil,
    index.zero? ? order.bill_address&.company : nil,
    index.zero? ? order.bill_address&.city : nil,
    index.zero? ? order.bill_address&.zipcode : nil,
    index.zero? ? order.bill_address&.state_name : nil,
    index.zero? ? order.bill_address&.country&.name : nil,
    index.zero? ? order.bill_address&.phone : nil,
    index.zero? ? order.ship_address&.full_name : nil,
    index.zero? ? order.ship_address&.address1 : nil,
    index.zero? ? order.ship_address&.address2 : nil,
    index.zero? ? order.ship_address&.company : nil,
    index.zero? ? order.ship_address&.city : nil,
    index.zero? ? order.ship_address&.zipcode : nil,
    index.zero? ? order.ship_address&.state_name : nil,
    index.zero? ? order.ship_address&.country&.name : nil,
    index.zero? ? order.ship_address&.phone : nil,
    index.zero? ? format_date(order.completed_at) : nil,
    format_date(line_item.order.shipments.first&.shipped_at),
    index.zero? ? format_date(order.canceled_at) : nil,
    index.zero? ? order.canceler&.email : nil,
    index.zero? ? order.special_instructions : nil
  ]

  if index.zero?
    csv += metafields
  end

  csv
end