Sha256: 55e685f2bf7de171350c3d170018e571b7dc659990bb9602e33da4e5cac79eb8
Contents?: true
Size: 810 Bytes
Versions: 120
Compression:
Stored size: 810 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
120 entries across 120 versions & 1 rubygems