Sha256: 44ceb1fd5ff9add20e13a97721de65f7abdb8c2a4923c7c964480b75a942cc13

Contents?: true

Size: 872 Bytes

Versions: 9

Compression:

Stored size: 872 Bytes

Contents

# This migration comes from spree (originally 20131118183431)
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

9 entries across 9 versions & 2 rubygems

Version Path
spree_purchase_order-3.7.0 spec/dummy/db/migrate/20191113195817_add_line_item_id_to_spree_inventory_units.spree.rb
spree_billing_sisow-0.9.2 spec/dummy/db/migrate/20190729091758_add_line_item_id_to_spree_inventory_units.spree.rb
spree_billing_sisow-0.9.1 spec/dummy/db/migrate/20190729091758_add_line_item_id_to_spree_inventory_units.spree.rb
spree_purchase_order-3.6.0 spec/dummy/db/migrate/20180516181946_add_line_item_id_to_spree_inventory_units.spree.rb
spree_purchase_order-3.5.0 spec/dummy/db/migrate/20180516181946_add_line_item_id_to_spree_inventory_units.spree.rb
spree_purchase_order-3.5.0.rc1 spec/dummy/db/migrate/20180516181946_add_line_item_id_to_spree_inventory_units.spree.rb
spree_purchase_order-3.4.0 spec/dummy/db/migrate/20180516181946_add_line_item_id_to_spree_inventory_units.spree.rb
spree_purchase_order-3.3.0 spec/dummy/db/migrate/20180516181946_add_line_item_id_to_spree_inventory_units.spree.rb
spree_purchase_order-3.2.0 spec/dummy/db/migrate/20180516181946_add_line_item_id_to_spree_inventory_units.spree.rb