26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/workers/workarea/listrak/product_exporter.rb', line 26
def perform(class_name, id)
product, skus =
if class_name == "Workarea::Catalog::Product"
prod = Catalog::Product.find(id)
[prod, prod.skus]
else
[Catalog::Product.find_by_sku(id), [id]]
end
return unless product.present?
inventory = Inventory::Collection.new product.skus
pricing = Inventory::Collection.new product.skus
listrak_products = skus.map do |sku|
Listrak::Models::ProductForm.new product,
pricing_sku: pricing.for_sku(sku),
inventory_sku: inventory.for_sku(sku)
end
Workarea::Listrak.data.products.import(listrak_products)
end
|