spree_sample 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/db/samples/addresses.rb +28 -0
  3. data/db/samples/adjustments.rb +40 -0
  4. data/db/samples/assets.rb +158 -0
  5. data/db/{sample/spree/products → samples/images}/apache_baseball.png +0 -0
  6. data/db/{sample/spree/products → samples/images}/ror_bag.jpeg +0 -0
  7. data/db/{sample/spree/products → samples/images}/ror_baseball.jpeg +0 -0
  8. data/db/{sample/spree/products → samples/images}/ror_baseball_back.jpeg +0 -0
  9. data/db/{sample/spree/products → samples/images}/ror_baseball_jersey_back_blue.png +0 -0
  10. data/db/{sample/spree/products → samples/images}/ror_baseball_jersey_back_green.png +0 -0
  11. data/db/{sample/spree/products → samples/images}/ror_baseball_jersey_back_red.png +0 -0
  12. data/db/{sample/spree/products → samples/images}/ror_baseball_jersey_blue.png +0 -0
  13. data/db/{sample/spree/products → samples/images}/ror_baseball_jersey_green.png +0 -0
  14. data/db/{sample/spree/products → samples/images}/ror_baseball_jersey_red.png +0 -0
  15. data/db/{sample/spree/products → samples/images}/ror_jr_spaghetti.jpeg +0 -0
  16. data/db/{sample/spree/products → samples/images}/ror_mug.jpeg +0 -0
  17. data/db/{sample/spree/products → samples/images}/ror_mug_back.jpeg +0 -0
  18. data/db/{sample/spree/products → samples/images}/ror_ringer.jpeg +0 -0
  19. data/db/{sample/spree/products → samples/images}/ror_ringer_back.jpeg +0 -0
  20. data/db/{sample/spree/products → samples/images}/ror_stein.jpeg +0 -0
  21. data/db/{sample/spree/products → samples/images}/ror_stein_back.jpeg +0 -0
  22. data/db/{sample/spree/products → samples/images}/ror_tote.jpeg +0 -0
  23. data/db/{sample/spree/products → samples/images}/ror_tote_back.jpeg +0 -0
  24. data/db/{sample/spree/products → samples/images}/ruby_baseball.png +0 -0
  25. data/db/{sample/spree/products → samples/images}/spree_bag.jpeg +0 -0
  26. data/db/{sample/spree/products → samples/images}/spree_jersey.jpeg +0 -0
  27. data/db/{sample/spree/products → samples/images}/spree_jersey_back.jpeg +0 -0
  28. data/db/{sample/spree/products → samples/images}/spree_mug.jpeg +0 -0
  29. data/db/{sample/spree/products → samples/images}/spree_mug_back.jpeg +0 -0
  30. data/db/{sample/spree/products → samples/images}/spree_ringer_t.jpeg +0 -0
  31. data/db/{sample/spree/products → samples/images}/spree_ringer_t_back.jpeg +0 -0
  32. data/db/{sample/spree/products → samples/images}/spree_spaghetti.jpeg +0 -0
  33. data/db/{sample/spree/products → samples/images}/spree_stein.jpeg +0 -0
  34. data/db/{sample/spree/products → samples/images}/spree_stein_back.jpeg +0 -0
  35. data/db/{sample/spree/products → samples/images}/spree_tote_back.jpeg +0 -0
  36. data/db/{sample/spree/products → samples/images}/spree_tote_front.jpeg +0 -0
  37. data/db/samples/line_items.rb +16 -0
  38. data/db/samples/option_types.rb +16 -0
  39. data/db/samples/option_values.rb +53 -0
  40. data/db/samples/orders.rb +26 -0
  41. data/db/samples/payment_methods.rb +43 -0
  42. data/db/{sample/spree → samples}/payments.rb +1 -4
  43. data/db/samples/product_option_types.rb +12 -0
  44. data/db/samples/product_properties.rb +118 -0
  45. data/db/samples/products.rb +122 -0
  46. data/db/samples/prototypes.rb +21 -0
  47. data/db/samples/shipments.rb +18 -0
  48. data/db/samples/shipping_categories.rb +1 -0
  49. data/db/samples/shipping_methods.rb +49 -0
  50. data/db/samples/tax_categories.rb +2 -0
  51. data/db/samples/tax_rates.rb +10 -0
  52. data/db/samples/taxonomies.rb +8 -0
  53. data/db/samples/taxons.rb +121 -0
  54. data/db/samples/variants.rb +170 -0
  55. data/db/samples.rb +2 -0
  56. data/lib/spree/sample.rb +17 -0
  57. data/lib/spree_sample.rb +24 -0
  58. data/lib/tasks/sample.rake +17 -4
  59. metadata +64 -76
  60. data/db/sample/spree/addresses.yml +0 -27
  61. data/db/sample/spree/adjustments.yml +0 -26
  62. data/db/sample/spree/assets.yml +0 -440
  63. data/db/sample/spree/calculators.yml +0 -26
  64. data/db/sample/spree/inventory_units.rb +0 -4
  65. data/db/sample/spree/line_items.yml +0 -40
  66. data/db/sample/spree/option_types.yml +0 -8
  67. data/db/sample/spree/option_values.yml +0 -35
  68. data/db/sample/spree/orders.yml +0 -20
  69. data/db/sample/spree/payment_methods.yml +0 -29
  70. data/db/sample/spree/preferences.rb +0 -21
  71. data/db/sample/spree/prices.yml +0 -224
  72. data/db/sample/spree/product_option_types.yml +0 -16
  73. data/db/sample/spree/product_properties.yml +0 -264
  74. data/db/sample/spree/products.rb +0 -15
  75. data/db/sample/spree/products.yml +0 -108
  76. data/db/sample/spree/properties.yml +0 -39
  77. data/db/sample/spree/prototypes.yml +0 -9
  78. data/db/sample/spree/shipments.yml +0 -8
  79. data/db/sample/spree/shipping_categories.yml +0 -2
  80. data/db/sample/spree/shipping_methods.yml +0 -12
  81. data/db/sample/spree/tax_categories.yml +0 -6
  82. data/db/sample/spree/tax_rates.yml +0 -4
  83. data/db/sample/spree/taxonomies.yml +0 -4
  84. data/db/sample/spree/taxons.rb +0 -3
  85. data/db/sample/spree/taxons.yml +0 -100
  86. data/db/sample/spree/variants.yml +0 -174
@@ -0,0 +1,122 @@
1
+ Spree::Sample.load_sample("tax_categories")
2
+
3
+ clothing = Spree::TaxCategory.find_by_name!("Clothing")
4
+
5
+ default_attrs = {
6
+ :description => Faker::Lorem.paragraph,
7
+ :available_on => Time.zone.now
8
+ }
9
+
10
+ products = [
11
+ {
12
+ :name => "Ruby on Rails Tote",
13
+ :tax_category => clothing,
14
+ :price => 15.99,
15
+ :eur_price => 14,
16
+ },
17
+ {
18
+ :name => "Ruby on Rails Bag",
19
+ :tax_category => clothing,
20
+ :price => 22.99,
21
+ :eur_price => 19,
22
+ },
23
+ {
24
+ :name => "Ruby on Rails Baseball Jersey",
25
+ :tax_category => clothing,
26
+ :price => 19.99,
27
+ :eur_price => 16
28
+ },
29
+ {
30
+ :name => "Ruby on Rails Jr. Spaghetti",
31
+ :tax_category => clothing,
32
+ :price => 19.99,
33
+ :eur_price => 16
34
+
35
+ },
36
+ {
37
+ :name => "Ruby on Rails Ringer T-Shirt",
38
+ :tax_category => clothing,
39
+ :price => 19.99,
40
+ :eur_price => 16
41
+ },
42
+ {
43
+ :name => "Ruby Baseball Jersey",
44
+ :tax_category => clothing,
45
+ :price => 19.99,
46
+ :eur_price => 16
47
+ },
48
+ {
49
+ :name => "Apache Baseball Jersey",
50
+ :tax_category => clothing,
51
+ :price => 19.99,
52
+ :eur_price => 16
53
+ },
54
+ {
55
+ :name => "Spree Baseball Jersey",
56
+ :tax_category => clothing,
57
+ :price => 19.99,
58
+ :eur_price => 16
59
+ },
60
+ {
61
+ :name => "Spree Jr. Spaghetti",
62
+ :tax_category => clothing,
63
+ :price => 19.99,
64
+ :eur_price => 16
65
+ },
66
+ {
67
+ :name => "Spree Ringer T-Shirt",
68
+ :tax_category => clothing,
69
+ :price => 19.99,
70
+ :eur_price => 16
71
+ },
72
+ {
73
+ :name => "Spree Tote",
74
+ :tax_category => clothing,
75
+ :price => 15.99,
76
+ :eur_price => 14,
77
+ },
78
+ {
79
+ :name => "Spree Bag",
80
+ :tax_category => clothing,
81
+ :price => 22.99,
82
+ :eur_price => 19
83
+ },
84
+ {
85
+ :name => "Ruby on Rails Mug",
86
+ :price => 13.99,
87
+ :eur_price => 12
88
+ },
89
+ {
90
+ :name => "Ruby on Rails Stein",
91
+ :price => 16.99,
92
+ :eur_price => 14
93
+ },
94
+ {
95
+ :name => "Spree Stein",
96
+ :price => 16.99,
97
+ :eur_price => 14,
98
+ },
99
+ {
100
+ :name => "Spree Mug",
101
+ :price => 13.99,
102
+ :eur_price => 12
103
+ }
104
+ ]
105
+
106
+ # Need to call reset_column information here
107
+ # Otherwise running db:migrate db:seed spree_sample:load will fail
108
+ # complaining about cost_currency missing
109
+ Spree::Variant.reset_column_information
110
+
111
+ products.each do |product_attrs|
112
+ eur_price = product_attrs.delete(:eur_price)
113
+ Spree::Config[:currency] = "USD"
114
+
115
+ product = Spree::Product.create!(default_attrs.merge(product_attrs), :without_protection => true)
116
+ Spree::Config[:currency] = "EUR"
117
+ product.reload
118
+ product.price = eur_price
119
+ product.save!
120
+ end
121
+
122
+ Spree::Config[:currency] = "USD"
@@ -0,0 +1,21 @@
1
+ prototypes = [
2
+ {
3
+ :name => "Shirt",
4
+ :properties => ["Manufacturer", "Brand", "Model", "Shirt Type", "Sleeve Type", "Material", "Fit", "Gender"]
5
+ },
6
+ {
7
+ :name => "Bag",
8
+ :properties => ["Type", "Size", "Material"]
9
+ },
10
+ {
11
+ :name => "Mugs",
12
+ :properties => ["Size", "Type"]
13
+ }
14
+ ]
15
+
16
+ prototypes.each do |prototype_attrs|
17
+ prototype = Spree::Prototype.create!(:name => prototype_attrs[:name])
18
+ prototype_attrs[:properties].each do |property|
19
+ prototype.properties << Spree::Property.find_by_name!(property)
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ first_order = Spree::Order.find_by_number!("R123456789")
2
+ last_order = Spree::Order.find_by_number!("R987654321")
3
+
4
+ Spree::Shipment.create!({
5
+ :order => first_order,
6
+ :number => Array.new(11){rand(11)}.join,
7
+ :shipping_method => Spree::ShippingMethod.find_by_name!("UPS Ground (USD)"),
8
+ :address => Spree::Address.first,
9
+ :state => "pending"
10
+ }, :without_protection => true)
11
+
12
+ Spree::Shipment.create!({
13
+ :order => last_order,
14
+ :number => Array.new(11){rand(11)}.join,
15
+ :shipping_method => Spree::ShippingMethod.find_by_name!("UPS Ground (USD)"),
16
+ :address => Spree::Address.first,
17
+ :state => "pending"
18
+ }, :without_protection => true)
@@ -0,0 +1 @@
1
+ Spree::ShippingCategory.create!(:name => "Default Shipping")
@@ -0,0 +1,49 @@
1
+ begin
2
+ north_america = Spree::Zone.find_by_name!("North America")
3
+ rescue ActiveRecord::RecordNotFound
4
+ puts "Couldn't find 'North America' zone. Did you run `rake db:seed` first?"
5
+ puts "That task will set up the countries, states and zones required for Spree."
6
+ exit
7
+ end
8
+
9
+ europe_vat = Spree::Zone.find_by_name!("EU_VAT")
10
+
11
+ shipping_methods = [
12
+ {
13
+ :name => "UPS Ground (USD)",
14
+ :zone => north_america,
15
+ :calculator => Spree::Calculator::FlatRate.create!
16
+ },
17
+ {
18
+ :name => "UPS Two Day (USD)",
19
+ :zone => north_america,
20
+ :calculator => Spree::Calculator::FlatRate.create!
21
+ },
22
+ {
23
+ :name => "UPS One Day (USD)",
24
+ :zone => north_america,
25
+ :calculator => Spree::Calculator::FlatRate.create!
26
+ },
27
+ {
28
+ :name => "UPS Ground (EUR)",
29
+ :zone => europe_vat,
30
+ :calculator => Spree::Calculator::FlatRate.create!
31
+ }
32
+ ]
33
+
34
+ shipping_methods.each do |shipping_method_attrs|
35
+ Spree::ShippingMethod.create!(shipping_method_attrs, :without_protection => true)
36
+ end
37
+
38
+ {
39
+ "UPS Ground (USD)" => [5, "USD"],
40
+ "UPS Ground (EUR)" => [5, "EUR"],
41
+ "UPS One Day (USD)" => [15, "USD"],
42
+ "UPS Two Day (USD)" => [10, "USD"]
43
+ }.each do |shipping_method_name, (price, currency)|
44
+ shipping_method = Spree::ShippingMethod.find_by_name!(shipping_method_name)
45
+ shipping_method.calculator.preferred_amount = price
46
+ shipping_method.calculator.preferred_currency = currency
47
+ shipping_method.save!
48
+ end
49
+
@@ -0,0 +1,2 @@
1
+ Spree::TaxCategory.create!(:name => "Clothing")
2
+ Spree::TaxCategory.create!(:name => "Food")
@@ -0,0 +1,10 @@
1
+ north_america = Spree::Zone.find_by_name!("North America")
2
+ clothing = Spree::TaxCategory.find_by_name!("Clothing")
3
+ tax_rate = Spree::TaxRate.create({
4
+ :name => "North America",
5
+ :zone => north_america,
6
+ :amount => 0.05,
7
+ :tax_category => clothing},
8
+ :without_protection => true)
9
+ tax_rate.calculator = Spree::Calculator::DefaultTax.create!
10
+ tax_rate.save!
@@ -0,0 +1,8 @@
1
+ taxonomies = [
2
+ { :name => "Categories" },
3
+ { :name => "Brand" }
4
+ ]
5
+
6
+ taxonomies.each do |taxonomy_attrs|
7
+ Spree::Taxonomy.create!(taxonomy_attrs)
8
+ end
@@ -0,0 +1,121 @@
1
+ Spree::Sample.load_sample("taxonomies")
2
+ Spree::Sample.load_sample("products")
3
+
4
+ categories = Spree::Taxonomy.find_by_name!("Categories")
5
+ brands = Spree::Taxonomy.find_by_name!("Brand")
6
+
7
+ products = {
8
+ :ror_tote => "Ruby on Rails Tote",
9
+ :ror_bag => "Ruby on Rails Bag",
10
+ :ror_mug => "Ruby on Rails Mug",
11
+ :ror_stein => "Ruby on Rails Stein",
12
+ :ror_baseball_jersey => "Ruby on Rails Baseball Jersey",
13
+ :ror_jr_spaghetti => "Ruby on Rails Jr. Spaghetti",
14
+ :ror_ringer => "Ruby on Rails Ringer T-Shirt",
15
+ :spree_stein => "Spree Stein",
16
+ :spree_mug => "Spree Mug",
17
+ :spree_ringer => "Spree Ringer T-Shirt",
18
+ :spree_baseball_jersey => "Spree Baseball Jersey",
19
+ :spree_tote => "Spree Tote",
20
+ :spree_bag => "Spree Bag",
21
+ :spree_jr_spaghetti => "Spree Jr. Spaghetti",
22
+ :apache_baseball_jersey => "Apache Baseball Jersey",
23
+ :ruby_baseball_jersey => "Ruby Baseball Jersey",
24
+ }
25
+
26
+
27
+ products.each do |key, name|
28
+ products[key] = Spree::Product.find_by_name!(name)
29
+ end
30
+
31
+ taxons = [
32
+ {
33
+ :name => "Categories",
34
+ :taxonomy => categories,
35
+ :position => 0
36
+ },
37
+ {
38
+ :name => "Bags",
39
+ :taxonomy => categories,
40
+ :parent => "Categories",
41
+ :position => 1,
42
+ :products => [
43
+ products[:ror_tote],
44
+ products[:ror_bag],
45
+ products[:spree_tote],
46
+ products[:spree_bag]
47
+ ]
48
+ },
49
+ {
50
+ :name => "Mugs",
51
+ :taxonomy => categories,
52
+ :parent => "Categories",
53
+ :position => 2,
54
+ :products => [
55
+ products[:ror_mug],
56
+ products[:ror_stein],
57
+ products[:spree_stein],
58
+ products[:spree_mug]
59
+ ]
60
+ },
61
+ {
62
+ :name => "Clothing",
63
+ :taxonomy => categories,
64
+ :parent => "Categories"
65
+ },
66
+ {
67
+ :name => "Shirts",
68
+ :taxonomy => categories,
69
+ :parent => "Clothing",
70
+ :position => 0,
71
+ :products => [
72
+ products[:ror_jr_spaghetti],
73
+ products[:spree_jr_spaghetti]
74
+ ]
75
+ },
76
+ {
77
+ :name => "T-Shirts",
78
+ :taxonomy => categories,
79
+ :parent => "Clothing" ,
80
+ :products => [
81
+ products[:ror_baseball_jersey],
82
+ products[:ror_ringer],
83
+ products[:apache_baseball_jersey],
84
+ products[:ruby_baseball_jersey],
85
+ products[:spree_baseball_jersey],
86
+ products[:spree_ringer]
87
+ ],
88
+ :position => 0
89
+ },
90
+ {
91
+ :name => "Brands",
92
+ :taxonomy => brands
93
+ },
94
+ {
95
+ :name => "Ruby",
96
+ :taxonomy => brands,
97
+ :parent => "Brand"
98
+ },
99
+ {
100
+ :name => "Apache",
101
+ :taxonomy => brands,
102
+ :parent => "Brand"
103
+ },
104
+ {
105
+ :name => "Spree",
106
+ :taxonomy => brands,
107
+ :parent => "Brand"
108
+ },
109
+ {
110
+ :name => "Rails",
111
+ :taxonomy => brands,
112
+ :parent => "Brand"
113
+ },
114
+ ]
115
+
116
+ taxons.each do |taxon_attrs|
117
+ if taxon_attrs[:parent]
118
+ taxon_attrs[:parent] = Spree::Taxon.find_by_name!(taxon_attrs[:parent])
119
+ end
120
+ Spree::Taxon.create!(taxon_attrs, :without_protection => true)
121
+ end
@@ -0,0 +1,170 @@
1
+ Spree::Sample.load_sample("option_values")
2
+ Spree::Sample.load_sample("products")
3
+
4
+ ror_baseball_jersey = Spree::Product.find_by_name!("Ruby on Rails Baseball Jersey")
5
+ ror_tote = Spree::Product.find_by_name!("Ruby on Rails Tote")
6
+ ror_bag = Spree::Product.find_by_name!("Ruby on Rails Bag")
7
+ ror_jr_spaghetti = Spree::Product.find_by_name!("Ruby on Rails Jr. Spaghetti")
8
+ ror_mug = Spree::Product.find_by_name!("Ruby on Rails Mug")
9
+ ror_ringer = Spree::Product.find_by_name!("Ruby on Rails Ringer T-Shirt")
10
+ ror_stein = Spree::Product.find_by_name!("Ruby on Rails Stein")
11
+ spree_baseball_jersey = Spree::Product.find_by_name!("Spree Baseball Jersey")
12
+ spree_stein = Spree::Product.find_by_name!("Spree Stein")
13
+ spree_jr_spaghetti = Spree::Product.find_by_name!("Spree Jr. Spaghetti")
14
+ spree_mug = Spree::Product.find_by_name!("Spree Mug")
15
+ spree_ringer = Spree::Product.find_by_name!("Spree Ringer T-Shirt")
16
+ spree_tote = Spree::Product.find_by_name!("Spree Tote")
17
+ spree_bag = Spree::Product.find_by_name!("Spree Bag")
18
+ ruby_baseball_jersey = Spree::Product.find_by_name!("Ruby Baseball Jersey")
19
+ apache_baseball_jersey = Spree::Product.find_by_name!("Apache Baseball Jersey")
20
+
21
+ small = Spree::OptionValue.find_by_name!("Small")
22
+ medium = Spree::OptionValue.find_by_name!("Medium")
23
+ large = Spree::OptionValue.find_by_name!("Large")
24
+ extra_large = Spree::OptionValue.find_by_name!("Extra Large")
25
+
26
+ red = Spree::OptionValue.find_by_name!("Red")
27
+ blue = Spree::OptionValue.find_by_name!("Blue")
28
+ green = Spree::OptionValue.find_by_name!("Green")
29
+
30
+ default_attrs = {
31
+ :count_on_hand => 10
32
+ }
33
+
34
+ variants = [
35
+ {
36
+ :product => ror_baseball_jersey,
37
+ :option_values => [small, red],
38
+ :sku => "ROR-00001",
39
+ :cost_price => 17
40
+ },
41
+ {
42
+ :product => ror_baseball_jersey,
43
+ :option_values => [small, blue],
44
+ :sku => "ROR-00002",
45
+ :cost_price => 17
46
+ },
47
+ {
48
+ :product => ror_baseball_jersey,
49
+ :option_values => [small, green],
50
+ :sku => "ROR-00003",
51
+ :cost_price => 17
52
+ },
53
+ {
54
+ :product => ror_baseball_jersey,
55
+ :option_values => [medium, red],
56
+ :sku => "ROR-00004",
57
+ :cost_price => 17
58
+ },
59
+ {
60
+ :product => ror_baseball_jersey,
61
+ :option_values => [medium, blue],
62
+ :sku => "ROR-00005",
63
+ :cost_price => 17
64
+ },
65
+ {
66
+ :product => ror_baseball_jersey,
67
+ :option_values => [medium, green],
68
+ :sku => "ROR-00006",
69
+ :cost_price => 17
70
+ },
71
+ {
72
+ :product => ror_baseball_jersey,
73
+ :option_values => [large, red],
74
+ :sku => "ROR-00007",
75
+ :cost_price => 17
76
+ },
77
+ {
78
+ :product => ror_baseball_jersey,
79
+ :option_values => [large, blue],
80
+ :sku => "ROR-00008",
81
+ :cost_price => 17
82
+ },
83
+ {
84
+ :product => ror_baseball_jersey,
85
+ :option_values => [large, green],
86
+ :sku => "ROR-00009",
87
+ :cost_price => 17
88
+ },
89
+ {
90
+ :product => ror_baseball_jersey,
91
+ :option_values => [extra_large, green],
92
+ :sku => "ROR-00012",
93
+ :cost_price => 17
94
+ },
95
+ ]
96
+
97
+ masters = {
98
+ ror_baseball_jersey => {
99
+ :sku => "ROR-001",
100
+ :cost_price => 17,
101
+ },
102
+ ror_tote => {
103
+ :sku => "ROR-00011",
104
+ :cost_price => 17
105
+ },
106
+ ror_bag => {
107
+ :sku => "ROR-00012",
108
+ :cost_price => 21
109
+ },
110
+ ror_jr_spaghetti => {
111
+ :sku => "ROR-00013",
112
+ :cost_price => 17
113
+ },
114
+ ror_mug => {
115
+ :sku => "ROR-00014",
116
+ :cost_price => 11
117
+ },
118
+ ror_ringer => {
119
+ :sku => "ROR-00015",
120
+ :cost_price => 17
121
+ },
122
+ ror_stein => {
123
+ :sku => "ROR-00016",
124
+ :cost_price => 15
125
+ },
126
+ apache_baseball_jersey => {
127
+ :sku => "APC-00001",
128
+ :cost_price => 17
129
+ },
130
+ ruby_baseball_jersey => {
131
+ :sku => "RUB-00001",
132
+ :cost_price => 17
133
+ },
134
+ spree_baseball_jersey => {
135
+ :sku => "SPR-00001",
136
+ :cost_price => 17
137
+ },
138
+ spree_stein => {
139
+ :sku => "SPR-00016",
140
+ :cost_price => 15
141
+ },
142
+ spree_jr_spaghetti => {
143
+ :sku => "SPR-00013",
144
+ :cost_price => 17
145
+ },
146
+ spree_mug => {
147
+ :sku => "SPR-00014",
148
+ :cost_price => 11
149
+ },
150
+ spree_ringer => {
151
+ :sku => "SPR-00015",
152
+ :cost_price => 17
153
+ },
154
+ spree_tote => {
155
+ :sku => "SPR-00011",
156
+ :cost_price => 13
157
+ },
158
+ spree_bag => {
159
+ :sku => "SPR-00012",
160
+ :cost_price => 21
161
+ }
162
+ }
163
+
164
+ variants.each do |variant_attrs|
165
+ Spree::Variant.create!(variant_attrs, :without_protection => true)
166
+ end
167
+
168
+ masters.each do |product, variant_attrs|
169
+ product.master.update_attributes!(variant_attrs)
170
+ end
data/db/samples.rb ADDED
@@ -0,0 +1,2 @@
1
+ Spree::Sample.load_sample("payment_methods")
2
+ Spree::Sample.load_sample("shipping_categories")
@@ -0,0 +1,17 @@
1
+ module Spree
2
+ module Sample
3
+ def self.load_sample(file)
4
+ path = File.expand_path(samples_path + "#{file}.rb")
5
+ # Check to see if the specified file has been loaded before
6
+ if !$LOADED_FEATURES.include?(path)
7
+ require path
8
+ puts "Loaded #{file.titleize} samples"
9
+ end
10
+ end
11
+
12
+ private
13
+ def self.samples_path
14
+ Pathname.new(File.join(File.dirname(__FILE__), '..', '..', 'db', 'samples'))
15
+ end
16
+ end
17
+ end
data/lib/spree_sample.rb CHANGED
@@ -1,7 +1,31 @@
1
1
  require 'spree_core'
2
+ require 'spree/sample'
2
3
 
3
4
  module SpreeSample
4
5
  class Engine < Rails::Engine
5
6
  engine_name 'spree_sample'
7
+
8
+ # Needs to be here so we can access it inside the tests
9
+ def self.load_samples
10
+ Spree::Sample.load_sample("payment_methods")
11
+ Spree::Sample.load_sample("shipping_categories")
12
+ Spree::Sample.load_sample("shipping_methods")
13
+ Spree::Sample.load_sample("tax_categories")
14
+ Spree::Sample.load_sample("tax_rates")
15
+
16
+ Spree::Sample.load_sample("products")
17
+ Spree::Sample.load_sample("taxons")
18
+ Spree::Sample.load_sample("option_values")
19
+ Spree::Sample.load_sample("product_option_types")
20
+ Spree::Sample.load_sample("product_properties")
21
+ Spree::Sample.load_sample("prototypes")
22
+ Spree::Sample.load_sample("variants")
23
+ Spree::Sample.load_sample("assets")
24
+
25
+ Spree::Sample.load_sample("orders")
26
+ Spree::Sample.load_sample("line_items")
27
+ Spree::Sample.load_sample("adjustments")
28
+ Spree::Sample.load_sample("payments")
29
+ end
6
30
  end
7
31
  end
@@ -1,11 +1,24 @@
1
1
  require 'ffaker'
2
+ require 'pathname'
3
+ require 'spree/sample'
2
4
 
3
5
  namespace :spree_sample do
4
6
  desc 'Loads sample data'
5
- task :load do
6
- sample_path = File.join(File.dirname(__FILE__), '..', '..', 'db', 'sample')
7
+ task :load => :environment do
8
+ if ARGV.include?("db:migrate")
9
+ puts %Q{
10
+ Please run db:migrate separately from spree_sample:load.
7
11
 
8
- Rake::Task['db:load_dir'].reenable
9
- Rake::Task['db:load_dir'].invoke(sample_path)
12
+ Running db:migrate and spree_sample:load at the same time has been known to
13
+ cause problems where columns may be not available during sample data loading.
14
+
15
+ Migrations have been run. Please run "rake spree_sample:load" by itself now.
16
+ }
17
+ exit(1)
18
+ end
19
+
20
+ SpreeSample::Engine.load_samples
10
21
  end
11
22
  end
23
+
24
+