Sha256: 1c3b1fd9622aeb93e7349bc187cec19fd6d9ec6b959f4df14e8a7b11d68d83d4
Contents?: true
Size: 1.02 KB
Versions: 39
Compression:
Stored size: 1.02 KB
Contents
module Spree class Order < Spree::Base module CurrencyUpdater extend ActiveSupport::Concern included do def homogenize_line_item_currencies update_line_item_currencies! update_with_updater! end end # Updates prices of order's line items def update_line_item_currencies! line_items.where.not(currency: currency).each do |line_item| update_line_item_price!(line_item) end end # Returns the price object from given item def price_from_line_item(line_item) line_item.variant.prices.where(currency: currency).first end # Updates price from given line item 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 end end end
Version data entries
39 entries across 39 versions & 1 rubygems