jipiboily / spree_multi_lingual

Spree multi-lingual is a plugin to make multi locale store with Spree possible
BSD 3-Clause "New" or "Revised" License
49 stars 56 forks source link

for 1-3 branch migrations failling #37

Open harssh opened 11 years ago

harssh commented 11 years ago

rails g spree_multi_lingual:install append app/assets/javascripts/store/all.js append app/assets/javascripts/admin/all.js insert app/assets/stylesheets/store/all.css insert app/assets/stylesheets/admin/all.css run bundle exec rake railties:install:migrations FROM=spree_multi_lingual from "." Would you like to run the migrations now? [Y/n] Y run bundle exec rake db:migrate from "." == MigrateDataForProducts: migrating ========================================= rake aborted!

An error has occurred, this and all later migrations canceled:

cannot set on_demand of product with variants

anybody with solution or same issue here..........

picazoH commented 11 years ago

yep same problem... I've changed the migration to make it pass, not including the columns causing the problem... The code can be improved.

This migration comes from spree_multi_lingual (originally 20120309094246)

class MigrateDataForProducts < ActiveRecord::Migration def up Spree::Product.transaction do Spree::Product.find_each do |product| producttemp = product.untranslated_attributes.reject!{ |k| k == "count_on_hand"} producttemp = producttemp.reject!{ |k| k == "on_demand"} product.update_attributes!(producttemp, :without_protection => true) end end end

def down end end

ghost commented 11 years ago

yep +1 !!

sbounmy commented 11 years ago

in product.rb

def on_demand=(new_on_demand)
   raise 'cannot set on_demand of product with variants' if has_variants? && Spree::Config[:track_inventory_levels]
   master.on_demand = on_demand
   self[:on_demand] = new_on_demand
end

I would suggest changing db/{datetime}_add_translation_product.rb :

class AddTranslationToProduct < ActiveRecord::Migration
  def up

  Spree::Config[:track_inventory_levels] = false
  Spree::Product.create_translation_table! :name => :string, :description => :text, :meta_description => :string, :meta_keywords => :string
  Spree::Config[:track_inventory_levels] = true
  end

  def down
    Spree::Product.drop_translation_table!
  end  
end

Could anyone give a try please ? I will fix it once confirmed ! thanks

lucamonfredo commented 11 years ago

@sbounmy I had to add the track inventory thing also on MigrateDataForProduct migration to make it work.

class MigrateDataForProducts < ActiveRecord::Migration
  def up
    Spree::Product.transaction do
      Spree::Product.find_each do |product|
        Spree::Config[:track_inventory_levels] = false
        product.update_attributes!(product.untranslated_attributes, :without_protection => true)
        Spree::Config[:track_inventory_levels] = true
      end
    end
  end

  def down
  end
end