Class: SolidusImporter::OrderImporter

Inherits:
BaseImporter show all
Defined in:
lib/solidus_importer/order_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseImporter

#before_import, #processors

Constructor Details

#initialize(options) ⇒ OrderImporter

Returns a new instance of OrderImporter.



9
10
11
12
# File 'lib/solidus_importer/order_importer.rb', line 9

def initialize(options)
  super
  self.orders = {}
end

Instance Attribute Details

#ordersObject

Returns the value of attribute orders.



7
8
9
# File 'lib/solidus_importer/order_importer.rb', line 7

def orders
  @orders
end

Instance Method Details

#after_import(context) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/solidus_importer/order_importer.rb', line 28

def after_import(context)
  orders.each do |_, params|
    user = params.delete(:user)
    SolidusImporter::SpreeCoreImporterOrder.import(user, params)
  rescue StandardError
    context[:success] = false
  end

  context
end

#handle_row_import(context) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/solidus_importer/order_importer.rb', line 14

def handle_row_import(context)
  number = context.dig(:order, :number)

  return unless number

  orders[number] ||= {}

  order_params = context[:order].to_h.reject { |_k, v| v.blank? }
  payments_attributes = order_params[:payments_attributes]
  orders[number][:payments_attributes] ||= []
  orders[number][:payments_attributes] << payments_attributes if payments_attributes.present?
  orders[number].merge!(order_params)
end