Sha256: 4ebd86bf3e5e306b09a386ce65b7044a1f5fbb942003a020a685aa8e554a58aa

Contents?: true

Size: 1.13 KB

Versions: 32

Compression:

Stored size: 1.13 KB

Contents

module Spree
  module Stock
    class ContentItem
      attr_accessor :inventory_unit, :state

      def initialize(inventory_unit, state = :on_hand)
        @inventory_unit = inventory_unit
        @state = state
      end

      with_options allow_nil: true do
        delegate :line_item,
                 :variant, to: :inventory_unit
        delegate :price, to: :variant
        delegate :dimension,
                 :volume,
                 :weight, to: :variant, prefix: true
      end

      def weight
        variant_weight * quantity
      end

      def on_hand?
        state.to_s == "on_hand"
      end

      def backordered?
        state.to_s == "backordered"
      end


      def amount
        price * quantity
      end

      def quantity
        # Since inventory units don't have a quantity,
        # make this always 1 for now, leaving ourselves
        # open to a different possibility in the future,
        # but this massively simplifies things for now
        1
      end

      def volume
        variant_volume * quantity
      end

      def dimension
        variant_dimension * quantity
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
spree_core-3.2.9 app/models/spree/stock/content_item.rb
spree_core-3.1.14 app/models/spree/stock/content_item.rb
spree_core-3.2.8 app/models/spree/stock/content_item.rb
spree_core-3.1.13 app/models/spree/stock/content_item.rb
spree_core-3.2.7 app/models/spree/stock/content_item.rb
spree_core-3.1.12 app/models/spree/stock/content_item.rb
spree_core-3.2.6 app/models/spree/stock/content_item.rb
spree_core-3.1.11 app/models/spree/stock/content_item.rb
spree_core-3.1.10 app/models/spree/stock/content_item.rb
spree_core-3.2.5 app/models/spree/stock/content_item.rb
spree_core-3.1.9 app/models/spree/stock/content_item.rb
spree_core-3.2.4 app/models/spree/stock/content_item.rb
spree_core-3.1.8 app/models/spree/stock/content_item.rb
spree_core-3.1.7 app/models/spree/stock/content_item.rb
spree_core-3.2.3 app/models/spree/stock/content_item.rb
spree_core-3.2.2 app/models/spree/stock/content_item.rb
spree_core-3.1.6 app/models/spree/stock/content_item.rb
spree_core-3.1.5 app/models/spree/stock/content_item.rb
spree_core-3.2.1 app/models/spree/stock/content_item.rb
spree_core-3.2.0 app/models/spree/stock/content_item.rb