7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/workers/workarea/orderbot/product_importer.rb', line 7
def perform(options = {})
return unless Orderbot.api_configured?
Orderbot::ImportLog.log('product') do |last_imported_at|
last_import = options[:from_updated_on] || last_imported_at
attrs = {
response_model: "integration",
sort_by: "LastUpdatedOn"
}.merge!(product_filters)
response = gateway.get_products(attrs)
write_products(response.body, last_import)
if response.total_pages.to_i > 1
count = 2
while count <= response.total_pages.to_i
page_attrs = attrs.merge(page: count)
response = gateway.get_products(page_attrs)
write_products(response.body, last_import)
count = count + 1
end
end
Orderbot::Product::ImportParentProducts.new.perform
Orderbot::Product::ImportChildProducts.new.perform
end
end
|