spree_sample 3.1.14 → 3.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/db/samples/stock.rb CHANGED
@@ -1,12 +1,19 @@
1
1
  Spree::Sample.load_sample("variants")
2
2
 
3
3
  country = Spree::Country.find_by(iso: 'US')
4
- location = Spree::StockLocation.first_or_create! name: 'default', address1: 'Example Street', city: 'City', zipcode: '12345', country: country, state: country.states.first
4
+ location = Spree::StockLocation.first_or_create!(name: 'default',
5
+ address1: 'Example Street',
6
+ city: 'City',
7
+ zipcode: '12345',
8
+ country: country,
9
+ state: country.states.first)
5
10
  location.active = true
6
11
  location.save!
7
12
 
8
13
  Spree::Variant.all.each do |variant|
14
+ next if variant.is_master? && variant.product.has_variants?
15
+
9
16
  variant.stock_items.each do |stock_item|
10
- Spree::StockMovement.create(:quantity => 10, :stock_item => stock_item)
17
+ Spree::StockMovement.create(quantity: 10, stock_item: stock_item)
11
18
  end
12
19
  end
@@ -1,2 +1,2 @@
1
- Spree::TaxCategory.create!(:name => "Clothing")
2
- Spree::TaxCategory.create!(:name => "Food")
1
+ Spree::TaxCategory.where(name: 'Clothing').first_or_create!
2
+ Spree::TaxCategory.where(name: 'Food').first_or_create!
@@ -1,9 +1,10 @@
1
1
  north_america = Spree::Zone.find_by_name!("North America")
2
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
- tax_rate.calculator = Spree::Calculator::DefaultTax.create!
9
- tax_rate.save!
3
+
4
+ Spree::TaxRate.where(
5
+ name: "North America",
6
+ zone: north_america,
7
+ amount: 0.05,
8
+ tax_category: clothing).first_or_create! do |tax_rate|
9
+ tax_rate.calculator = Spree::Calculator::DefaultTax.create!
10
+ end
@@ -1,8 +1,8 @@
1
1
  taxonomies = [
2
- { name: "Categories" },
2
+ { name: I18n.t('spree.taxonomy_brands_name') },
3
3
  { name: "Brand" }
4
4
  ]
5
5
 
6
6
  taxonomies.each do |taxonomy_attrs|
7
- Spree::Taxonomy.create!(taxonomy_attrs)
7
+ Spree::Taxonomy.where(taxonomy_attrs).first_or_create!
8
8
  end
data/db/samples/taxons.rb CHANGED
@@ -1,45 +1,44 @@
1
1
  Spree::Sample.load_sample("taxonomies")
2
2
  Spree::Sample.load_sample("products")
3
3
 
4
- categories = Spree::Taxonomy.find_by_name!("Categories")
4
+ categories = Spree::Taxonomy.find_by_name!(I18n.t('spree.taxonomy_brands_name'))
5
5
  brands = Spree::Taxonomy.find_by_name!("Brand")
6
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",
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
24
  }
25
25
 
26
-
27
26
  products.each do |key, name|
28
27
  products[key] = Spree::Product.find_by_name!(name)
29
28
  end
30
29
 
31
30
  taxons = [
32
31
  {
33
- :name => "Categories",
34
- :taxonomy => categories,
35
- :position => 0
32
+ name: I18n.t('spree.taxonomy_brands_name'),
33
+ taxonomy: categories,
34
+ position: 0
36
35
  },
37
36
  {
38
- :name => "Bags",
39
- :taxonomy => categories,
40
- :parent => "Categories",
41
- :position => 1,
42
- :products => [
37
+ name: "Bags",
38
+ taxonomy: categories,
39
+ parent: I18n.t('spree.taxonomy_brands_name'),
40
+ position: 1,
41
+ products: [
43
42
  products[:ror_tote],
44
43
  products[:ror_bag],
45
44
  products[:spree_tote],
@@ -47,11 +46,11 @@ taxons = [
47
46
  ]
48
47
  },
49
48
  {
50
- :name => "Mugs",
51
- :taxonomy => categories,
52
- :parent => "Categories",
53
- :position => 2,
54
- :products => [
49
+ name: "Mugs",
50
+ taxonomy: categories,
51
+ parent: I18n.t('spree.taxonomy_brands_name'),
52
+ position: 2,
53
+ products: [
55
54
  products[:ror_mug],
56
55
  products[:ror_stein],
57
56
  products[:spree_stein],
@@ -59,25 +58,25 @@ taxons = [
59
58
  ]
60
59
  },
61
60
  {
62
- :name => "Clothing",
63
- :taxonomy => categories,
64
- :parent => "Categories"
61
+ name: "Clothing",
62
+ taxonomy: categories,
63
+ parent: I18n.t('spree.taxonomy_brands_name')
65
64
  },
66
65
  {
67
- :name => "Shirts",
68
- :taxonomy => categories,
69
- :parent => "Clothing",
70
- :position => 0,
71
- :products => [
66
+ name: "Shirts",
67
+ taxonomy: categories,
68
+ parent: "Clothing",
69
+ position: 0,
70
+ products: [
72
71
  products[:ror_jr_spaghetti],
73
72
  products[:spree_jr_spaghetti]
74
73
  ]
75
74
  },
76
75
  {
77
- :name => "T-Shirts",
78
- :taxonomy => categories,
79
- :parent => "Clothing" ,
80
- :products => [
76
+ name: "T-Shirts",
77
+ taxonomy: categories,
78
+ parent: "Clothing",
79
+ products: [
81
80
  products[:ror_baseball_jersey],
82
81
  products[:ror_ringer],
83
82
  products[:apache_baseball_jersey],
@@ -85,33 +84,33 @@ taxons = [
85
84
  products[:spree_baseball_jersey],
86
85
  products[:spree_ringer]
87
86
  ],
88
- :position => 0
87
+ position: 0
89
88
  },
90
89
  {
91
- :name => "Brands",
92
- :taxonomy => brands
90
+ name: I18n.t('spree.taxonomy_brands_name'),
91
+ taxonomy: brands
93
92
  },
94
93
  {
95
- :name => "Ruby",
96
- :taxonomy => brands,
97
- :parent => "Brand",
98
- :products => [
94
+ name: "Ruby",
95
+ taxonomy: brands,
96
+ parent: I18n.t('spree.taxonomy_brands_name'),
97
+ products: [
99
98
  products[:ruby_baseball_jersey]
100
99
  ]
101
100
  },
102
101
  {
103
- :name => "Apache",
104
- :taxonomy => brands,
105
- :parent => "Brand",
106
- :products => [
102
+ name: "Apache",
103
+ taxonomy: brands,
104
+ parent: I18n.t('spree.taxonomy_brands_name'),
105
+ products: [
107
106
  products[:apache_baseball_jersey]
108
107
  ]
109
108
  },
110
109
  {
111
- :name => "Spree",
112
- :taxonomy => brands,
113
- :parent => "Brand",
114
- :products => [
110
+ name: "Spree",
111
+ taxonomy: brands,
112
+ parent: I18n.t('spree.taxonomy_brands_name'),
113
+ products: [
115
114
  products[:spree_stein],
116
115
  products[:spree_mug],
117
116
  products[:spree_ringer],
@@ -122,10 +121,10 @@ taxons = [
122
121
  ]
123
122
  },
124
123
  {
125
- :name => "Rails",
126
- :taxonomy => brands,
127
- :parent => "Brand",
128
- :products => [
124
+ name: "Rails",
125
+ taxonomy: brands,
126
+ parent: I18n.t('spree.taxonomy_brands_name'),
127
+ products: [
129
128
  products[:ror_tote],
130
129
  products[:ror_bag],
131
130
  products[:ror_mug],
@@ -138,8 +137,11 @@ taxons = [
138
137
  ]
139
138
 
140
139
  taxons.each do |taxon_attrs|
141
- if taxon_attrs[:parent]
142
- taxon_attrs[:parent] = Spree::Taxon.where(name: taxon_attrs[:parent]).first
143
- Spree::Taxon.create!(taxon_attrs)
140
+ parent = Spree::Taxon.where(name: taxon_attrs[:parent]).first
141
+ taxonomy = taxon_attrs[:taxonomy]
142
+ Spree::Taxon.where(name: taxon_attrs[:name]).first_or_create! do |taxon|
143
+ taxon.parent = parent
144
+ taxon.taxonomy = taxonomy
145
+ taxon.products = taxon_attrs[:products] if taxon_attrs[:products]
144
146
  end
145
147
  end
@@ -29,135 +29,139 @@ green = Spree::OptionValue.where(name: "Green").first
29
29
 
30
30
  variants = [
31
31
  {
32
- :product => ror_baseball_jersey,
33
- :option_values => [small, red],
34
- :sku => "ROR-00001",
35
- :cost_price => 17
32
+ product: ror_baseball_jersey,
33
+ option_values: [small, red],
34
+ sku: "ROR-00001",
35
+ cost_price: 17
36
36
  },
37
37
  {
38
- :product => ror_baseball_jersey,
39
- :option_values => [small, blue],
40
- :sku => "ROR-00002",
41
- :cost_price => 17
38
+ product: ror_baseball_jersey,
39
+ option_values: [small, blue],
40
+ sku: "ROR-00002",
41
+ cost_price: 17
42
42
  },
43
43
  {
44
- :product => ror_baseball_jersey,
45
- :option_values => [small, green],
46
- :sku => "ROR-00003",
47
- :cost_price => 17
44
+ product: ror_baseball_jersey,
45
+ option_values: [small, green],
46
+ sku: "ROR-00003",
47
+ cost_price: 17
48
48
  },
49
49
  {
50
- :product => ror_baseball_jersey,
51
- :option_values => [medium, red],
52
- :sku => "ROR-00004",
53
- :cost_price => 17
50
+ product: ror_baseball_jersey,
51
+ option_values: [medium, red],
52
+ sku: "ROR-00004",
53
+ cost_price: 17
54
54
  },
55
55
  {
56
- :product => ror_baseball_jersey,
57
- :option_values => [medium, blue],
58
- :sku => "ROR-00005",
59
- :cost_price => 17
56
+ product: ror_baseball_jersey,
57
+ option_values: [medium, blue],
58
+ sku: "ROR-00005",
59
+ cost_price: 17
60
60
  },
61
61
  {
62
- :product => ror_baseball_jersey,
63
- :option_values => [medium, green],
64
- :sku => "ROR-00006",
65
- :cost_price => 17
62
+ product: ror_baseball_jersey,
63
+ option_values: [medium, green],
64
+ sku: "ROR-00006",
65
+ cost_price: 17
66
66
  },
67
67
  {
68
- :product => ror_baseball_jersey,
69
- :option_values => [large, red],
70
- :sku => "ROR-00007",
71
- :cost_price => 17
68
+ product: ror_baseball_jersey,
69
+ option_values: [large, red],
70
+ sku: "ROR-00007",
71
+ cost_price: 17
72
72
  },
73
73
  {
74
- :product => ror_baseball_jersey,
75
- :option_values => [large, blue],
76
- :sku => "ROR-00008",
77
- :cost_price => 17
74
+ product: ror_baseball_jersey,
75
+ option_values: [large, blue],
76
+ sku: "ROR-00008",
77
+ cost_price: 17
78
78
  },
79
79
  {
80
- :product => ror_baseball_jersey,
81
- :option_values => [large, green],
82
- :sku => "ROR-00009",
83
- :cost_price => 17
80
+ product: ror_baseball_jersey,
81
+ option_values: [large, green],
82
+ sku: "ROR-00009",
83
+ cost_price: 17
84
84
  },
85
85
  {
86
- :product => ror_baseball_jersey,
87
- :option_values => [extra_large, green],
88
- :sku => "ROR-00010",
89
- :cost_price => 17
86
+ product: ror_baseball_jersey,
87
+ option_values: [extra_large, green],
88
+ sku: "ROR-00010",
89
+ cost_price: 17
90
90
  },
91
91
  ]
92
92
 
93
93
  masters = {
94
94
  ror_baseball_jersey => {
95
- :sku => "ROR-001",
96
- :cost_price => 17,
95
+ sku: "ROR-001",
96
+ cost_price: 17,
97
97
  },
98
98
  ror_tote => {
99
- :sku => "ROR-00011",
100
- :cost_price => 17
99
+ sku: "ROR-00011",
100
+ cost_price: 17
101
101
  },
102
102
  ror_bag => {
103
- :sku => "ROR-00012",
104
- :cost_price => 21
103
+ sku: "ROR-00012",
104
+ cost_price: 21
105
105
  },
106
106
  ror_jr_spaghetti => {
107
- :sku => "ROR-00013",
108
- :cost_price => 17
107
+ sku: "ROR-00013",
108
+ cost_price: 17
109
109
  },
110
110
  ror_mug => {
111
- :sku => "ROR-00014",
112
- :cost_price => 11
111
+ sku: "ROR-00014",
112
+ cost_price: 11
113
113
  },
114
114
  ror_ringer => {
115
- :sku => "ROR-00015",
116
- :cost_price => 17
115
+ sku: "ROR-00015",
116
+ cost_price: 17
117
117
  },
118
118
  ror_stein => {
119
- :sku => "ROR-00016",
120
- :cost_price => 15
119
+ sku: "ROR-00016",
120
+ cost_price: 15
121
121
  },
122
122
  apache_baseball_jersey => {
123
- :sku => "APC-00001",
124
- :cost_price => 17
123
+ sku: "APC-00001",
124
+ cost_price: 17
125
125
  },
126
126
  ruby_baseball_jersey => {
127
- :sku => "RUB-00001",
128
- :cost_price => 17
127
+ sku: "RUB-00001",
128
+ cost_price: 17
129
129
  },
130
130
  spree_baseball_jersey => {
131
- :sku => "SPR-00001",
132
- :cost_price => 17
131
+ sku: "SPR-00001",
132
+ cost_price: 17
133
133
  },
134
134
  spree_stein => {
135
- :sku => "SPR-00016",
136
- :cost_price => 15
135
+ sku: "SPR-00016",
136
+ cost_price: 15
137
137
  },
138
138
  spree_jr_spaghetti => {
139
- :sku => "SPR-00013",
140
- :cost_price => 17
139
+ sku: "SPR-00013",
140
+ cost_price: 17
141
141
  },
142
142
  spree_mug => {
143
- :sku => "SPR-00014",
144
- :cost_price => 11
143
+ sku: "SPR-00014",
144
+ cost_price: 11
145
145
  },
146
146
  spree_ringer => {
147
- :sku => "SPR-00015",
148
- :cost_price => 17
147
+ sku: "SPR-00015",
148
+ cost_price: 17
149
149
  },
150
150
  spree_tote => {
151
- :sku => "SPR-00011",
152
- :cost_price => 13
151
+ sku: "SPR-00011",
152
+ cost_price: 13
153
153
  },
154
154
  spree_bag => {
155
- :sku => "SPR-00012",
156
- :cost_price => 21
155
+ sku: "SPR-00012",
156
+ cost_price: 21
157
157
  }
158
158
  }
159
159
 
160
- Spree::Variant.create!(variants)
160
+ variants.each do |attrs|
161
+ if Spree::Variant.where(product_id: attrs[:product].id, sku: attrs[:sku]).none?
162
+ Spree::Variant.create!(attrs)
163
+ end
164
+ end
161
165
 
162
166
  masters.each do |product, variant_attrs|
163
167
  product.master.update_attributes!(variant_attrs)