Sha256: 542004832680a77921387653e6aee13069bc99082985769be6738ddae4fb3c37

Contents?: true

Size: 1.06 KB

Versions: 11

Compression:

Stored size: 1.06 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,
                 :quantity,
                 :variant, to: :inventory_unit
        delegate :price, to: :variant
        delegate :dimension,
                 :volume,
                 :weight, to: :variant, prefix: true
      end

      def splittable_by_weight?
        quantity > 1 && variant_weight.present?
      end

      def weight
        variant_weight * quantity
      end

      def quantity=(value)
        @inventory_unit.quantity = value
      end

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

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


      def amount
        price * quantity
      end

      def volume
        variant_volume * quantity
      end

      def dimension
        variant_dimension * quantity
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spree_core-3.3.6 app/models/spree/stock/content_item.rb
spree_core-3.3.5 app/models/spree/stock/content_item.rb
spree_core-3.3.4 app/models/spree/stock/content_item.rb
spree_core-3.3.3 app/models/spree/stock/content_item.rb
spree_core-3.3.2 app/models/spree/stock/content_item.rb
spree_core-3.3.1 app/models/spree/stock/content_item.rb
spree_core-3.3.0 app/models/spree/stock/content_item.rb
spree_core-3.3.0.rc4 app/models/spree/stock/content_item.rb
spree_core-3.3.0.rc3 app/models/spree/stock/content_item.rb
spree_core-3.3.0.rc2 app/models/spree/stock/content_item.rb
spree_core-3.3.0.rc1 app/models/spree/stock/content_item.rb