Class: Spree::ShippingManifest Private

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/shipping_manifest.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: ManifestItem

Instance Method Summary (collapse)

Constructor Details

- (ShippingManifest) initialize(inventory_units:)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ShippingManifest



4
5
6
# File 'app/models/spree/shipping_manifest.rb', line 4

def initialize(inventory_units:)
  @inventory_units = inventory_units.to_a
end

Instance Method Details

- (Object) for_order(order)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
11
12
# File 'app/models/spree/shipping_manifest.rb', line 8

def for_order(order)
  Spree::ShippingManifest.new(
    inventory_units: @inventory_units.select { |iu| iu.order_id == order.id }
  )
end

- (Object) items

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/spree/shipping_manifest.rb', line 14

def items
  # Grouping by the ID means that we don't have to call out to the association accessor
  # This makes the grouping by faster because it results in less SQL cache hits.
  @inventory_units.group_by(&:variant_id).map do |_variant_id, variant_units|
    variant_units.group_by(&:line_item_id).map do |_line_item_id, units|
      states = {}
      units.group_by(&:state).each { |state, iu| states[state] = iu.count }

      line_item = units.first.line_item
      variant = units.first.variant
      ManifestItem.new(line_item, variant, units.length, states)
    end
  end.flatten
end