Class: Workarea::Orderbot::Product::ImportParentProducts

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/workarea/orderbot/product/import_parent_products.rb

Instance Method Summary collapse

Instance Method Details

#performObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/workers/workarea/orderbot/product/import_parent_products.rb', line 7

def perform
  Orderbot::ProductImportData.parent_products.each do |parent_product|
    result = begin
      Orderbot::ParentProduct.new(parent_product).process

      # if a parent product has no children then import the variants
      # pricing and shipping skus
      if !parent_product.has_children
        Orderbot::ChildProduct.new(parent_product).process
      end

      true
    rescue StandardError => e
      parent_product.update_attributes!(error_message: e.message)
      false
    end

    if result
      parent_product.delete
    end
  end
end