Sha256: 7661e95c53ddaf1776d6e6dead656d489780e0274f21bbce57ce24a519cecf7a

Contents?: true

Size: 892 Bytes

Versions: 1

Compression:

Stored size: 892 Bytes

Contents

module Workarea
  module FlowIo
    class LocalItem
      include ApplicationDocument

      field :included_levies, type: Hash, default: {}

      embedded_in :sku, class_name: "Workarea::Pricing::Sku"

      embeds_one :experience, class_name: "Workarea::FlowIo::ExperienceSummary"
      embeds_one :msrp, class_name: "Workarea::FlowIo::PriceWithBase"
      embeds_many :prices, class_name: "Workarea::FlowIo::LocalizedPrice"

      validates_presence_of :experience

      # Creates a Pricing::Price from this local item
      # used in Pricing::Sku#find_price
      #
      # @return [Pricing::Price]
      #
      def to_price(quantity = 1)
        prices.sort_by(&:min_quantity).reverse.detect do |localized_price|
          quantity >= localized_price.min_quantity
        end&.to_price || Workarea::Pricing::Price.new(regular: 0.to_m(experience.currency))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-flow_io-1.2.1 app/models/workarea/flow_io/local_item.rb