Sha256: 294a0e038bae21b05c51df513fd67b388a25b1cb003966ca717cc47716b5eac4

Contents?: true

Size: 809 Bytes

Versions: 21

Compression:

Stored size: 809 Bytes

Contents

class AddLineItemIdToSpreeInventoryUnits < ActiveRecord::Migration[4.2]
  def change
    # Stores running the product-assembly extension already have a line_item_id column
    unless column_exists? Spree::InventoryUnit.table_name, :line_item_id
      add_column :spree_inventory_units, :line_item_id, :integer
      add_index :spree_inventory_units, :line_item_id

      shipments = Spree::Shipment.includes(:inventory_units, :order)

      shipments.find_each do |shipment|
        shipment.inventory_units.group_by(&:variant_id).each do |variant_id, units|
          line_item = shipment.order.line_items.find_by(variant_id: variant_id)
          next unless line_item

          Spree::InventoryUnit.where(id: units.map(&:id)).update_all(line_item_id: line_item.id)
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
solidus_core-2.3.1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.2.2 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.1.1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.0.3 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.3.0 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.3.0.rc3 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.3.0.rc2 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.3.0.rc1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.3.0.beta1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.0.2 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.2.1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.2.0 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.2.0.rc1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.2.0.beta1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.1.0 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.1.0.rc1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.0.1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.1.0.beta1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.0.0 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb
solidus_core-2.0.0.rc1 db/migrate/20131118183431_add_line_item_id_to_spree_inventory_units.rb