Module: Spree::Order::CurrencyUpdater

Extended by:
ActiveSupport::Concern
Included in:
Spree::Order
Defined in:
app/models/spree/order/currency_updater.rb

Instance Method Summary collapse

Instance Method Details

#price_from_line_item(line_item) ⇒ Object

Returns the price object from given item



21
22
23
# File 'app/models/spree/order/currency_updater.rb', line 21

def price_from_line_item(line_item)
  line_item.variant.prices.where(currency: currency).first
end

#update_line_item_currencies!Object

Updates prices of order’s line items



14
15
16
17
18
# File 'app/models/spree/order/currency_updater.rb', line 14

def update_line_item_currencies!
  line_items.where.not(currency: currency).each do |line_item|
    update_line_item_price!(line_item)
  end
end

#update_line_item_price!(line_item) ⇒ Object

Updates price from given line item



26
27
28
29
30
31
32
33
34
# File 'app/models/spree/order/currency_updater.rb', line 26

def update_line_item_price!(line_item)
  price = price_from_line_item(line_item)

  if price
    line_item.update_attributes!(currency: price.currency, price: price.amount)
  else
    raise "no #{currency} price found for #{line_item.product.name} (#{line_item.variant.sku})"
  end
end