Sha256: 4373eddfe3e72143d811b84871e6691f0d341d23a9839f54fa2b9e65232d30ba
Contents?: true
Size: 1.12 KB
Versions: 43
Compression:
Stored size: 1.12 KB
Contents
module Spree module Stock class OrderCounter attr_reader :order def initialize(order) @order = order @ordered_counts = count_line_items @assigned_counts = count_inventory_units end def variants @ordered_counts.keys end def variants_with_remaining variants.select { |variant| remaining(variant) > 0 } end def remaining? not variants_with_remaining.empty? end def ordered(variant) @ordered_counts[variant] end def assigned(variant) @assigned_counts[variant] end def remaining(variant) @ordered_counts[variant] - @assigned_counts[variant] end private def count_line_items counts = Hash.new(0) order.line_items.each do |line_item| counts[line_item.variant] += line_item.quantity end counts end def count_inventory_units counts = Hash.new(0) order.inventory_units.each do |inventory_unit| counts[inventory_unit.variant] += 1 end counts end end end end
Version data entries
43 entries across 43 versions & 1 rubygems