sample-products
1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/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.sample
next if profile.products.where(:name => name).first
product = Product.new
product.name = name
product.profile_id = profile.id
product.price = (i * 13.7)
product.product_category_id = categories.sample.id
save product
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