module Workarea decorate Pricing::Collection, with: :flow_io do decorated { attr_accessor :flow_experience } def regular_min_price return super unless flow_experience.present? @regular_min_price ||= records .map { |pricing_sku| pricing_sku.find_price(experience: flow_experience).regular } .sort .first end def regular_max_price return super unless flow_experience.present? @regular_max_price ||= records .map { |pricing_sku| pricing_sku.find_price(experience: flow_experience).regular } .sort .last end def sale_min_price return super unless flow_experience.present? @sale_min_price ||= records .map { |pricing_sku| pricing_sku.find_price(experience: flow_experience).sale } .compact .sort .first end def sale_max_price return super unless flow_experience.present? @sale_max_price ||= records .map { |pricing_sku| pricing_sku.find_price(experience: flow_experience).sale } .compact .sort .last end def sell_min_price return super unless flow_experience.present? @sell_min_price ||= records .map { |pricing_sku| pricing_sku.find_price(experience: flow_experience).sell } .sort .first end def sell_max_price return super unless flow_experience.present? @sell_max_price ||= records .map { |pricing_sku| pricing_sku.find_price(experience: flow_experience).sell } .sort .last end def msrp_min_price return super unless flow_experience.present? @msrp_min_price ||= records .map { |pricing_sku| pricing_sku.msrp_for_experience(flow_experience) } .compact .sort .first end def msrp_max_price return super unless flow_experience.present? @msrp_max_price ||= records .map { |pricing_sku| pricing_sku.msrp_for_experience(flow_experience) } .compact .sort .last end # All localized selling prices grouped by experience_key # eg. { "europe" => [12.4, 34], "canada" => [11.8, 9] } # # @return [::Hash] def localized_selling_prices records.each_with_object({}) do |sku, memo| sku.flow_io_local_items.each do |local_item| memo[local_item.experience.key] ||= [] memo[local_item.experience.key] << local_item.to_price.sell.to_f end end end # All localized minimum selling pricea grouped by experience_key # eg. { "europe" => 12.4, "canada" => 11.8 } # # @return [::Hash] def localized_min_sell_prices records.each_with_object({}) do |sku, memo| sku.flow_io_local_items.each do |local_item| sell_price = local_item.to_price.sell.to_f experience_key = local_item.experience.key memo[experience_key] ||= sell_price if sell_price < memo[experience_key] memo[experience_key] = sell_price end end end end end end