Class: PriceChangeJob

Inherits:
Struct
  • Object
show all
Defined in:
lib/price_change_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#recordObject

Returns the value of attribute record

Returns:

  • (Object)

    the current value of record



1
2
3
# File 'lib/price_change_job.rb', line 1

def record
  @record
end

Instance Method Details

#performObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/price_change_job.rb', line 2

def perform
  inactive_states = YAML.load Spree::Config.get(:order_price_sync_inactive_states_list)
  to_update = LineItem.joins(:order).where(:variant_id => record).where("orders.state not in (?)", inactive_states)
  to_update.each do |l|
    puts "Invoking with #{l.inspect}"
    if l.price != record.price
      puts "Price changed #{l.price}"
      item = LineItem.find(l.id)
      item.price = record.price
      puts item.save

      order = item.order
      order.update_totals
      order.save
    end
  end
end