Sha256: 6126a2e1f0beeda3515348865055fdfdd0dfb4ea282964ba728135744fafb7be

Contents?: true

Size: 839 Bytes

Versions: 3

Compression:

Stored size: 839 Bytes

Contents

class CreateDefaultStock < ActiveRecord::Migration
  def up
    Spree::StockLocation.skip_callback(:create, :after, :create_stock_items)
    Spree::StockItem.skip_callback(:save, :after, :process_backorders)
    location = Spree::StockLocation.new(name: 'default')
    location.save(validate: false)
    Spree::Variant.all.each do |variant|
      stock_item = location.stock_items.build(variant: variant)
      stock_item.send(:count_on_hand=, variant.count_on_hand)
      stock_item.save!
    end

    remove_column :spree_variants, :count_on_hand
  end

  def down
    add_column :spree_variants, :count_on_hand, :integer

    Spree::StockItem.all.each do |stock_item|
      stock_item.variant.update_column :count_on_hand, stock_item.count_on_hand
    end

    Spree::StockLocation.delete_all
    Spree::StockItem.delete_all
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_core-2.1.1 db/migrate/20130213191427_create_default_stock.rb
spree_core-2.0.5 db/migrate/20130213191427_create_default_stock.rb
spree_core-2.1.0 db/migrate/20130213191427_create_default_stock.rb