Class: Workarea::Orderbot::Pricing::ImportPricing

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/workarea/orderbot/pricing/import_pricing.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
# File 'app/workers/workarea/orderbot/pricing/import_pricing.rb', line 7

def perform
  Workarea::Orderbot::PricingImportData.each do |sku_price|
    pricing_data = sku_price.pricing_data.deep_symbolize_keys

    next unless pricing_data[:sku].present?
    sku = Workarea::Pricing::Sku.find_or_initialize_by(id: pricing_data[:sku])

    original_price = pricing_data[:original_price]
    price =  pricing_data[:price]

    regular = regular_price(price, original_price)
    sale = sale_price(price, original_price)

    sku.on_sale = sale.present?
    sku.prices = [{ regular: regular, sale: sale, on_sale: sale.present? }]
    sku.save!

    sku_price.delete
  end
end