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
-
#price_from_line_item(line_item) ⇒ Object
Returns the price object from given item.
-
#update_line_item_currencies! ⇒ Object
Updates prices of order’s line items.
-
#update_line_item_price!(line_item) ⇒ Object
Updates price from given line item.
Instance Method Details
#price_from_line_item(line_item) ⇒ Object
Returns the price object from given item
23 24 25 |
# File 'app/models/spree/order/currency_updater.rb', line 23 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
16 17 18 19 20 |
# File 'app/models/spree/order/currency_updater.rb', line 16 def update_line_item_currencies! line_items.where('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
28 29 30 31 32 33 34 35 36 |
# File 'app/models/spree/order/currency_updater.rb', line 28 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 RuntimeError, "no #{currency} price found for #{line_item.product.name} (#{line_item.variant.sku})" end end |