sample-products 1.27 KB
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
include Noosfero::SampleDataHelper

enterprises = $environment.enterprises
categories = $environment.product_categories

print "Creating products: "
THINGS = %w[ Car House Bicycle Book Pen Computer Webcam ]
COLORS = %w[ Black Red White Blue Green Purple ]
for thing in THINGS
  for color in COLORS
    name = [color, thing].join(' ')
    rand(10).times do |i|
    profile = enterprises.rand
    next if profile.products.where(:name => name).first
      save Product.new(
        :name => name,
        :profile_id => profile.id, :price => (i * 13.7),
        :product_category_id => categories.rand.id
      )
    end
  end
end
done

print "Creating qualifiers and certifier: "
QUALIFIERS = ['Organic', 'Free as in Freedom', 'Regional']
CERTIFIERS = ['FBES', 'Colivre', 'Institute Paulo Freire', 'Fora do Eixo']
for qualifier in QUALIFIERS
  save Qualifier.new(:name => qualifier, :environment => $environment)
end
for certifier in CERTIFIERS
  save Certifier.new(:name => certifier, :environment => $environment)
end
done

print "Creating units: "
[['Litre', 'Litres'], ['Kilo', 'Kilos'], ['Meter', 'Meters']].each do |unit|
  save Unit.new(:singular => unit[0], :plural => unit[1], :environment => $environment)
end
done