spree_sample 4.0.9 → 4.1.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,19 +1,26 @@
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',
5
- address1: 'Example Street',
6
- city: 'City',
7
- zipcode: '12345',
8
- country: country,
9
- state: country.states.first)
10
- location.active = true
11
- location.save!
4
+ location = Spree::StockLocation.find_or_create_by!(name: 'default')
5
+ location.update_attributes!(
6
+ address1: 'Example Street',
7
+ city: 'City',
8
+ zipcode: '12345',
9
+ country: country,
10
+ state: country.states.first,
11
+ active: true
12
+ )
13
+
14
+ product_1 = Spree::Product.find_by!(name: 'Denim Shirt')
15
+ product_2 = Spree::Product.find_by!(name: 'Checked Shirt')
16
+
17
+ product_1.master.stock_items.find_by!(stock_location: location).update!(count_on_hand: 1)
18
+ product_2.master.stock_items.find_by!(stock_location: location).update!(count_on_hand: 1)
12
19
 
13
20
  Spree::Variant.all.each do |variant|
14
21
  next if variant.is_master? && variant.product.has_variants?
15
22
 
16
23
  variant.stock_items.each do |stock_item|
17
- Spree::StockMovement.create(quantity: 10, stock_item: stock_item)
24
+ Spree::StockMovement.create(quantity: rand(20..50), stock_item: stock_item)
18
25
  end
19
26
  end
@@ -1,2 +1 @@
1
1
  Spree::TaxCategory.where(name: 'Clothing').first_or_create!
2
- Spree::TaxCategory.where(name: 'Food').first_or_create!
@@ -1,10 +1,13 @@
1
- north_america = Spree::Zone.find_by!(name: 'North America')
1
+ Spree::Sample.load_sample('tax_categories')
2
+ Spree::Sample.load_sample('zones')
3
+
4
+ california = Spree::Zone.find_by!(name: 'California Tax')
2
5
  clothing = Spree::TaxCategory.find_by!(name: 'Clothing')
3
6
 
4
7
  Spree::TaxRate.where(
5
- name: 'North America',
6
- zone: north_america,
7
- amount: 0.05,
8
+ name: 'California',
9
+ zone: california,
10
+ amount: 0.1,
8
11
  tax_category: clothing
9
12
  ).first_or_create! do |tax_rate|
10
13
  tax_rate.calculator = Spree::Calculator::DefaultTax.create!
@@ -1,6 +1,5 @@
1
1
  taxonomies = [
2
- { name: I18n.t('spree.taxonomy_categories_name') },
3
- { name: I18n.t('spree.taxonomy_brands_name') }
2
+ { name: I18n.t('spree.taxonomy_categories_name') }
4
3
  ]
5
4
 
6
5
  taxonomies.each do |taxonomy_attrs|
data/db/samples/taxons.rb CHANGED
@@ -1,148 +1,39 @@
1
+ require 'csv'
2
+
1
3
  Spree::Sample.load_sample('taxonomies')
2
- Spree::Sample.load_sample('products')
3
4
 
4
- categories = Spree::Taxonomy.find_by!(name: I18n.t('spree.taxonomy_categories_name'))
5
- brands = Spree::Taxonomy.find_by!(name: I18n.t('spree.taxonomy_brands_name'))
5
+ CHILDREN_TAXON_NAMES = CSV.read(File.join(__dir__, 'variants.csv')).map do |(parent_name, taxon_name, _product_name, _color_name)|
6
+ [parent_name, taxon_name]
7
+ end.uniq
6
8
 
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
- }
9
+ TAXON_NAMES = CHILDREN_TAXON_NAMES.map { |(parent_name, taxon_name)| parent_name }
25
10
 
26
- products.each do |key, name|
27
- products[key] = Spree::Product.find_by!(name: name)
11
+ categories = Spree::Taxonomy.find_by!(name: I18n.t('spree.taxonomy_categories_name'))
12
+ categories_taxon = Spree::Taxon.where(name: I18n.t('spree.taxonomy_categories_name')).first_or_create!
13
+
14
+ TAXON_NAMES.each do |taxon_name|
15
+ taxon = categories_taxon.children.where(name: taxon_name).first_or_create!
16
+ taxon.permalink = taxon.permalink.gsub('categories/', '')
17
+ taxon.taxonomy = categories
18
+ taxon.save!
28
19
  end
29
20
 
30
- taxons = [
31
- {
32
- name: I18n.t('spree.taxonomy_categories_name'),
33
- taxonomy: categories,
34
- position: 0
35
- },
36
- {
37
- name: 'Bags',
38
- taxonomy: categories,
39
- parent: I18n.t('spree.taxonomy_categories_name'),
40
- position: 1,
41
- products: [
42
- products[:ror_tote],
43
- products[:ror_bag],
44
- products[:spree_tote],
45
- products[:spree_bag]
46
- ]
47
- },
48
- {
49
- name: 'Mugs',
50
- taxonomy: categories,
51
- parent: I18n.t('spree.taxonomy_categories_name'),
52
- position: 2,
53
- products: [
54
- products[:ror_mug],
55
- products[:ror_stein],
56
- products[:spree_stein],
57
- products[:spree_mug]
58
- ]
59
- },
60
- {
61
- name: 'Clothing',
62
- taxonomy: categories,
63
- parent: I18n.t('spree.taxonomy_categories_name')
64
- },
65
- {
66
- name: 'Shirts',
67
- taxonomy: categories,
68
- parent: 'Clothing',
69
- position: 0,
70
- products: [
71
- products[:ror_jr_spaghetti],
72
- products[:spree_jr_spaghetti]
73
- ]
74
- },
75
- {
76
- name: 'T-Shirts',
77
- taxonomy: categories,
78
- parent: 'Clothing',
79
- products: [
80
- products[:ror_baseball_jersey],
81
- products[:ror_ringer],
82
- products[:apache_baseball_jersey],
83
- products[:ruby_baseball_jersey],
84
- products[:spree_baseball_jersey],
85
- products[:spree_ringer]
86
- ],
87
- position: 0
88
- },
89
- {
90
- name: I18n.t('spree.taxonomy_brands_name'),
91
- taxonomy: brands
92
- },
93
- {
94
- name: 'Ruby',
95
- taxonomy: brands,
96
- parent: I18n.t('spree.taxonomy_brands_name'),
97
- products: [
98
- products[:ruby_baseball_jersey]
99
- ]
100
- },
101
- {
102
- name: 'Apache',
103
- taxonomy: brands,
104
- parent: I18n.t('spree.taxonomy_brands_name'),
105
- products: [
106
- products[:apache_baseball_jersey]
107
- ]
108
- },
109
- {
110
- name: 'Spree',
111
- taxonomy: brands,
112
- parent: I18n.t('spree.taxonomy_brands_name'),
113
- products: [
114
- products[:spree_stein],
115
- products[:spree_mug],
116
- products[:spree_ringer],
117
- products[:spree_baseball_jersey],
118
- products[:spree_tote],
119
- products[:spree_bag],
120
- products[:spree_jr_spaghetti]
121
- ]
122
- },
123
- {
124
- name: 'Rails',
125
- taxonomy: brands,
126
- parent: I18n.t('spree.taxonomy_brands_name'),
127
- products: [
128
- products[:ror_tote],
129
- products[:ror_bag],
130
- products[:ror_mug],
131
- products[:ror_stein],
132
- products[:ror_baseball_jersey],
133
- products[:ror_jr_spaghetti],
134
- products[:ror_ringer]
135
- ]
136
- }
137
- ]
21
+ CHILDREN_TAXON_NAMES.each do |(parent_name, taxon_name)|
22
+ parent = Spree::Taxon.where(name: parent_name).first
23
+ taxon = parent.children.where(name: taxon_name).first_or_create!
24
+ taxon.permalink = taxon.permalink.gsub('categories/', '')
25
+ taxon.taxonomy = categories
26
+ taxon.save!
27
+ end
138
28
 
139
- taxons.each do |taxon_attrs|
140
- parent = Spree::Taxon.where(name: taxon_attrs[:parent]).first
141
- taxonomy = taxon_attrs[:taxonomy]
29
+ taxon = categories_taxon.children.where(name: 'New', permalink: 'newest').first_or_create!
30
+ taxon.permalink = taxon.permalink.gsub('categories/', '')
31
+ taxon.taxonomy = categories
32
+ taxon.save!
142
33
 
143
- taxon = Spree::Taxon.where(name: taxon_attrs[:name]).first_or_create!
144
- taxon.parent = parent
145
- taxon.taxonomy = taxonomy
146
- taxon.save
147
- taxon.products = taxon_attrs[:products] if taxon_attrs[:products]
34
+ ['Bestsellers', 'Trending', 'Streetstyle', 'Summer Sale'].each do |taxon_name|
35
+ taxon = categories_taxon.children.where(name: taxon_name).first_or_create!
36
+ taxon.permalink = taxon.permalink.gsub('categories/', '')
37
+ taxon.taxonomy = categories
38
+ taxon.save!
148
39
  end
@@ -0,0 +1,194 @@
1
+ Men,Shirts,denim shirt,blue
2
+ Men,Shirts,denim shirt,light_blue
3
+ Men,Shirts,checked shirt,red
4
+ Men,Shirts,covered placket shirt,dark_blue
5
+ Men,Shirts,covered placket shirt,white
6
+ Men,Shirts,slim fit shirt,dark_blue
7
+ Men,Shirts,slim fit shirt,light_blue
8
+ Men,Shirts,slim fit shirt,burgundy
9
+ Men,Shirts,short sleeve shirt,burgundy
10
+ Men,Shirts,printed short sleeve shirt,brown
11
+ Men,Shirts,regular shirt,blue
12
+ Men,Shirts,checked slim fit shirt,black
13
+ Men,Shirts,dotted shirt,white
14
+ Men,Shirts,linen shirt,light_blue
15
+ Men,Shirts,linen shirt,pink
16
+ Men,Shirts,regular shirt with rolled up sleeves,light_blue
17
+ Men,T-shirts,polo t-shirt,light_blue
18
+ Men,T-shirts,polo t-shirt,pink
19
+ Men,T-shirts,polo t-shirt,red
20
+ Men,T-shirts,long sleeve t-shirt,grey
21
+ Men,T-shirts,3_4 sleeve t-shirt,white
22
+ Men,T-shirts,t-shirt with holes,grey
23
+ Men,T-shirts,raw-edge t-shirt,brown
24
+ Men,T-shirts,v-neck t-shirt,grey
25
+ Men,T-shirts,v-neck t-shirt,white
26
+ Men,T-shirts,tank top,pink
27
+ Men,T-shirts,basic t-shirt,grey
28
+ Men,T-shirts,basic t-shirt,burgundy
29
+ Men,T-shirts,basic t-shirt,white
30
+ Men,T-shirts,basic t-shirt,black
31
+ Men,Sweaters,high neck sweater,black
32
+ Men,Sweaters,stripped jumper,brown
33
+ Men,Sweaters,long sleeve jumper with pocket,ecru
34
+ Men,Sweaters,jumper,grey
35
+ Men,Sweaters,long sleeve sweatshirt,mint
36
+ Men,Sweaters,long sleeve sweatshirt,light_blue
37
+ Men,Sweaters,long sleeve sweatshirt,pink
38
+ Men,Sweaters,long sleeve sweatshirt,orange
39
+ Men,Sweaters,hoodie,grey
40
+ Men,Sweaters,zipped high neck sweater,green
41
+ Men,Sweaters,long sleeve jumper,dark_blue
42
+ Men,Sweaters,long sleeve jumper,beige
43
+ Men,Jackets and Coats,suede biker jacket,brown
44
+ Men,Jackets and Coats,hooded jacket,beige
45
+ Men,Jackets and Coats,anorak with hood,yellow
46
+ Men,Jackets and Coats,anorak with hood,white
47
+ Men,Jackets and Coats,denim jacket,light_blue
48
+ Men,Jackets and Coats,wool-blend short coat,brown
49
+ Men,Jackets and Coats,down jacket with hood,dark_blue
50
+ Men,Jackets and Coats,down jacket with hood,blue
51
+ Men,Jackets and Coats,down jacket with hood,khaki
52
+ Men,Jackets and Coats,down jacket with hood,yellow
53
+ Men,Jackets and Coats,wool-blend coat,beige
54
+ Men,Jackets and Coats,jacket with liner,black
55
+ Women,Skirts,flared midi skirt,burgundy
56
+ Women,Skirts,midi skirt with bottoms,green
57
+ Women,Skirts,midi skirt with bottoms,blue
58
+ Women,Skirts,midi skirt with bottoms,grey
59
+ Women,Skirts,fitted skirt,orange
60
+ Women,Skirts,a-line suede skirt,dark_blue
61
+ Women,Skirts,a-line suede skirt,purple
62
+ Women,Skirts,leather skirt with lacing,black
63
+ Women,Skirts,flared skirt,orange
64
+ Women,Skirts,skater skirt,brown
65
+ Women,Skirts,skater short skirt,white
66
+ Women,Skirts,floral flared skirt,light_blue
67
+ Women,Skirts,floral flared skirt,black
68
+ Women,Skirts,pleated skirt 2,green
69
+ Women,Skirts,pleated skirt 2,light_blue
70
+ Women,Skirts,pleated skirt 2,pink
71
+ Women,Skirts,pleated skirt 2,red
72
+ Women,Skirts,pleated skirt 2,black
73
+ Women,Skirts,pleated skirt 2,orange
74
+ Women,Dresses,floral wrap dress,black
75
+ Women,Dresses,v-neck floral maxi dress,pink
76
+ Women,Dresses,v-neck floral maxi dress,white
77
+ Women,Dresses,v-neck floral maxi dress,black
78
+ Women,Dresses,flared dress,red
79
+ Women,Dresses,flared dress,black
80
+ Women,Dresses,elegant flared dress,black
81
+ Women,Dresses,elegant flared dress,orange
82
+ Women,Dresses,long sleeve knitted dress,grey
83
+ Women,Dresses,long sleeve knitted dress,beige
84
+ Women,Dresses,long sleeve knitted dress,black
85
+ Women,Dresses,striped shirt dress,light_blue
86
+ Women,Dresses,striped shirt dress,grey
87
+ Women,Dresses,printed dress,light_blue
88
+ Women,Dresses,printed dress,pink
89
+ Women,Dresses,printed slit-sleeves dress,light_blue
90
+ Women,Dresses,printed slit-sleeves dress,grey
91
+ Women,Dresses,printed slit-sleeves dress,black
92
+ Women,Dresses,dress with belt,red
93
+ Women,Dresses,dress with belt,burgundy
94
+ Women,Dresses,v-neck floral dress,light_blue
95
+ Women,Dresses,v-neck floral dress,grey
96
+ Women,Dresses,v-neck floral dress,black
97
+ Women,Dresses,flounced dress,beige
98
+ Women,Dresses,slit maxi dress,red
99
+ Women,Shirts and Blouses,semi-sheer shirt with floral cuffs,brown
100
+ Women,Shirts and Blouses,semi-sheer shirt with floral cuffs,white
101
+ Women,Shirts and Blouses,striped shirt,blue
102
+ Women,Shirts and Blouses,striped shirt,red
103
+ Women,Shirts and Blouses,v-neck wide shirt,dark_blue
104
+ Women,Shirts and Blouses,v-neck wide shirt,white
105
+ Women,Shirts and Blouses,printed wrapped blouse,white
106
+ Women,Shirts and Blouses,pleated sleeve v-neck shirt,orange
107
+ Women,Shirts and Blouses,cotton shirt,light_blue
108
+ Women,Shirts and Blouses,blouse with wide flounced sleeve,pink
109
+ Women,Shirts and Blouses,elegant blouse with chocker,mint
110
+ Women,Shirts and Blouses,elegant blouse with chocker,pink
111
+ Women,Shirts and Blouses,elegant blouse with chocker,white
112
+ Women,Shirts and Blouses,floral shirt,pink
113
+ Women,Shirts and Blouses,floral shirt,beige
114
+ Women,Shirts and Blouses,semi-sheer shirt with pockets,white
115
+ Women,Shirts and Blouses,v-neck shirt,pink
116
+ Women,Shirts and Blouses,v-neck shirt,white
117
+ Women,Shirts and Blouses,printed shirt,green
118
+ Women,Sweaters,asymetric sweater with wide sleeves,blue
119
+ Women,Sweaters,asymetric sweater with wide sleeves,grey
120
+ Women,Sweaters,asymetric sweater with wide sleeves,red
121
+ Women,Sweaters,asymetric sweater with wide sleeves,white
122
+ Women,Sweaters,oversized knitted sweater,red
123
+ Women,Sweaters,oversized sweatshirt,brown
124
+ Women,Sweaters,knitted high neck sweater,blue
125
+ Women,Sweaters,knitted high neck sweater,pink
126
+ Women,Sweaters,knitted high neck sweater,white
127
+ Women,Sweaters,knitted v-neck sweater,blue
128
+ Women,Sweaters,knitted v-neck sweater,red
129
+ Women,Sweaters,knitted v-neck sweater,beige
130
+ Women,Sweaters,long sleeve sweatshirt,mint
131
+ Women,Sweaters,cropped fitted sweater,red
132
+ Women,Sweaters,cropped fitted sweater,yellow
133
+ Women,Tops and T-shirts,crop top with tie,red
134
+ Women,Tops and T-shirts,printed t-shirt,white
135
+ Women,Tops and T-shirts,scrappy top,black
136
+ Women,Tops and T-shirts,pleated sleeve t-shirt,beige
137
+ Women,Tops and T-shirts,pleated sleeve t-shirt,white
138
+ Women,Tops and T-shirts,scrappy crop top with tie,grey
139
+ Women,Tops and T-shirts,crop top,black
140
+ Women,Tops and T-shirts,loose t-shirt with pocket imitation,white
141
+ Women,Tops and T-shirts,sleeveless loose top,white
142
+ Women,Tops and T-shirts,basic loose t-shirt,green
143
+ Women,Tops and T-shirts,basic loose t-shirt,blue
144
+ Women,Tops and T-shirts,basic loose t-shirt,pink
145
+ Women,Tops and T-shirts,basic loose t-shirt,red
146
+ Women,Tops and T-shirts,basic loose t-shirt,white
147
+ Women,Tops and T-shirts,basic loose t-shirt,orange
148
+ Women,Tops and T-shirts,basic t-shirt,yellow
149
+ Women,Tops and T-shirts,basic t-shirt,orange
150
+ Women,Jackets and Coats,coat with pockets,pink
151
+ Women,Jackets and Coats,coat with pockets,burgundy
152
+ Women,Jackets and Coats,coat with pockets,black
153
+ Women,Jackets and Coats,long wool-blend coat with belt,dark_blue
154
+ Women,Jackets and Coats,long wool-blend coat with belt,beige
155
+ Women,Jackets and Coats,asymetric coat,white
156
+ Women,Jackets and Coats,long coat with belt,beige
157
+ Women,Jackets and Coats,down jacket,white
158
+ Women,Jackets and Coats,zipped jacket,blue
159
+ Women,Jackets and Coats,loose-fitted jacket,light_blue
160
+ Women,Jackets and Coats,double-breasted jacket,white
161
+ Women,Jackets and Coats,leather biker jacket,black
162
+ Women,Jackets and Coats,wool-blend coat with belt,burgundy
163
+ Women,Jackets and Coats,wool-blend coat with belt,lila
164
+ Women,Jackets and Coats,denim hooded jacket,blue
165
+ Women,Jackets and Coats,bomber jacket,khaki
166
+ Sportswear,Tops,sports bra low support,grey
167
+ Sportswear,Tops,sports bra low support,lila
168
+ Sportswear,Tops,long sleeves yoga crop top,mint
169
+ Sportswear,Tops,long sleeves yoga crop top,light_blue
170
+ Sportswear,Tops,long sleeves yoga crop top,pink
171
+ Sportswear,Tops,oversize t-shirt wrapped on back,pink
172
+ Sportswear,Tops,long sleeves crop top,black
173
+ Sportswear,Tops,laced crop top,black
174
+ Sportswear,Tops,sports bra medium support,black
175
+ Sportswear,Tops,sports bra ,green
176
+ Sportswear,Tops,sports bra ,blue
177
+ Sportswear,Tops,sports bra ,burgundy
178
+ Sportswear,Tops,sport cropp top,burgundy
179
+ Sportswear,Sweatshirts,running sweatshirt,light_blue
180
+ Sportswear,Sweatshirts,leightweight running jacket,grey
181
+ Sportswear,Sweatshirts,oversize sweatshirt,pink
182
+ Sportswear,Sweatshirts,sport windproof jacket,blue
183
+ Sportswear,Sweatshirts,sport waistcoat,purple
184
+ Sportswear,Pants,shined pants,light_blue
185
+ Sportswear,Pants,shined pants,grey
186
+ Sportswear,Pants,shined pants,black
187
+ Sportswear,Pants,short pants,black
188
+ Sportswear,Pants,printed pants with holes,black
189
+ Sportswear,Pants,pants,black
190
+ Sportswear,Pants,printed pants,grey
191
+ Sportswear,Pants,high waist pants with pockets,pink
192
+ Sportswear,Pants,high waist pants with pockets,purple
193
+ Sportswear,Pants,high waist pants,blue
194
+ Sportswear,Pants,high waist pants,burgundy
@@ -1,166 +1,43 @@
1
+ require 'csv'
2
+
1
3
  Spree::Sample.load_sample('option_values')
2
4
  Spree::Sample.load_sample('products')
5
+ Spree::Sample.load_sample('tax_categories')
3
6
 
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.where(name: 'Small').first
22
- medium = Spree::OptionValue.where(name: 'Medium').first
23
- large = Spree::OptionValue.where(name: 'Large').first
24
- extra_large = Spree::OptionValue.where(name: 'Extra Large').first
25
-
26
- red = Spree::OptionValue.where(name: 'Red').first
27
- blue = Spree::OptionValue.where(name: 'Blue').first
28
- green = Spree::OptionValue.where(name: 'Green').first
7
+ VARIANTS = CSV.read(File.join(__dir__, 'variants.csv'))
29
8
 
30
- variants = [
31
- {
32
- product: ror_baseball_jersey,
33
- option_values: [small, red],
34
- sku: 'ROR-00001',
35
- cost_price: 17
36
- },
37
- {
38
- product: ror_baseball_jersey,
39
- option_values: [small, blue],
40
- sku: 'ROR-00002',
41
- cost_price: 17
42
- },
43
- {
44
- product: ror_baseball_jersey,
45
- option_values: [small, green],
46
- sku: 'ROR-00003',
47
- cost_price: 17
48
- },
49
- {
50
- product: ror_baseball_jersey,
51
- option_values: [medium, red],
52
- sku: 'ROR-00004',
53
- cost_price: 17
54
- },
55
- {
56
- product: ror_baseball_jersey,
57
- option_values: [medium, blue],
58
- sku: 'ROR-00005',
59
- cost_price: 17
60
- },
61
- {
62
- product: ror_baseball_jersey,
63
- option_values: [medium, green],
64
- sku: 'ROR-00006',
65
- cost_price: 17
66
- },
67
- {
68
- product: ror_baseball_jersey,
69
- option_values: [large, red],
70
- sku: 'ROR-00007',
71
- cost_price: 17
72
- },
73
- {
74
- product: ror_baseball_jersey,
75
- option_values: [large, blue],
76
- sku: 'ROR-00008',
77
- cost_price: 17
78
- },
79
- {
80
- product: ror_baseball_jersey,
81
- option_values: [large, green],
82
- sku: 'ROR-00009',
83
- cost_price: 17
84
- },
85
- {
86
- product: ror_baseball_jersey,
87
- option_values: [extra_large, green],
88
- sku: 'ROR-00010',
89
- cost_price: 17
90
- }
91
- ]
9
+ clothing_tax_category = Spree::TaxCategory.find_by!(name: 'Clothing')
10
+ color_option_values = Spree::OptionType.find_by!(name: 'color').option_values
11
+ length_option_values = Spree::OptionType.find_by!(name: 'length').option_values
12
+ size_option_values = Spree::OptionType.find_by!(name: 'size').option_values
92
13
 
93
- masters = {
94
- ror_baseball_jersey => {
95
- sku: 'ROR-001',
96
- cost_price: 17
97
- },
98
- ror_tote => {
99
- sku: 'ROR-00011',
100
- cost_price: 17
101
- },
102
- ror_bag => {
103
- sku: 'ROR-00012',
104
- cost_price: 21
105
- },
106
- ror_jr_spaghetti => {
107
- sku: 'ROR-00013',
108
- cost_price: 17
109
- },
110
- ror_mug => {
111
- sku: 'ROR-00014',
112
- cost_price: 11
113
- },
114
- ror_ringer => {
115
- sku: 'ROR-00015',
116
- cost_price: 17
117
- },
118
- ror_stein => {
119
- sku: 'ROR-00016',
120
- cost_price: 15
121
- },
122
- apache_baseball_jersey => {
123
- sku: 'APC-00001',
124
- cost_price: 17
125
- },
126
- ruby_baseball_jersey => {
127
- sku: 'RUB-00001',
128
- cost_price: 17
129
- },
130
- spree_baseball_jersey => {
131
- sku: 'SPR-00001',
132
- cost_price: 17
133
- },
134
- spree_stein => {
135
- sku: 'SPR-00016',
136
- cost_price: 15
137
- },
138
- spree_jr_spaghetti => {
139
- sku: 'SPR-00013',
140
- cost_price: 17
141
- },
142
- spree_mug => {
143
- sku: 'SPR-00014',
144
- cost_price: 11
145
- },
146
- spree_ringer => {
147
- sku: 'SPR-00015',
148
- cost_price: 17
149
- },
150
- spree_tote => {
151
- sku: 'SPR-00011',
152
- cost_price: 13
153
- },
154
- spree_bag => {
155
- sku: 'SPR-00012',
156
- cost_price: 21
157
- }
158
- }
159
-
160
- variants.each do |attrs|
161
- Spree::Variant.create!(attrs) if Spree::Variant.where(product_id: attrs[:product].id, sku: attrs[:sku]).none?
162
- end
14
+ VARIANTS.each do |(parent_name, taxon_name, product_name, color_name)|
15
+ parent = Spree::Taxon.find_by!(name: parent_name)
16
+ taxon = parent.children.find_by!(name: taxon_name)
17
+ product = taxon.products.find_by!(name: product_name.titleize)
18
+ color = color_option_values.find_by!(name: color_name)
163
19
 
164
- masters.each do |product, variant_attrs|
165
- product.master.update!(variant_attrs)
20
+ size_option_values.each do |size|
21
+ if parent_name == 'Women' and %w[Dresses Skirts].include?(taxon_name)
22
+ length_option_values.each do |length|
23
+ option_values = [color, length, size]
24
+ product.variants.new do |variant|
25
+ variant.cost_price = product.price
26
+ variant.option_values = option_values
27
+ variant.sku = product.sku + '_' + option_values.map(&:name).join('_')
28
+ variant.tax_category = clothing_tax_category
29
+ variant.save!
30
+ end
31
+ end
32
+ else
33
+ option_values = [color, size]
34
+ product.variants.new do |variant|
35
+ variant.cost_price = product.price
36
+ variant.option_values = option_values
37
+ variant.sku = product.sku + '_' + option_values.map(&:name).join('_')
38
+ variant.tax_category = clothing_tax_category
39
+ variant.save!
40
+ end
41
+ end
42
+ end
166
43
  end
@@ -0,0 +1,3 @@
1
+ california_zone = Spree::Zone.where(name: 'California Tax', description: 'California tax zone', kind: 'state').first_or_create!
2
+ california_state = Spree::Country.find_by!(iso3: 'USA').states.find_by(abbr: 'CA')
3
+ california_zone.zone_members.where(zoneable: california_state).first_or_create!
data/lib/spree_sample.rb CHANGED
@@ -7,26 +7,30 @@ module SpreeSample
7
7
 
8
8
  # Needs to be here so we can access it inside the tests
9
9
  def self.load_samples
10
+ Spree::Sample.load_sample('addresses')
11
+ Spree::Sample.load_sample('zones')
10
12
  Spree::Sample.load_sample('payment_methods')
11
13
  Spree::Sample.load_sample('shipping_categories')
12
14
  Spree::Sample.load_sample('shipping_methods')
13
15
  Spree::Sample.load_sample('tax_categories')
14
16
  Spree::Sample.load_sample('tax_rates')
17
+ Spree::Sample.load_sample('taxonomies')
18
+ Spree::Sample.load_sample('promotions')
15
19
 
16
20
  Spree::Sample.load_sample('products')
17
21
  Spree::Sample.load_sample('taxons')
22
+ Spree::Sample.load_sample('option_types')
18
23
  Spree::Sample.load_sample('option_values')
19
- Spree::Sample.load_sample('product_option_types')
20
24
  Spree::Sample.load_sample('product_properties')
21
25
  Spree::Sample.load_sample('prototypes')
22
26
  Spree::Sample.load_sample('variants')
23
27
  Spree::Sample.load_sample('stock')
24
- Spree::Sample.load_sample('assets')
25
28
 
26
29
  Spree::Sample.load_sample('orders')
27
30
  Spree::Sample.load_sample('adjustments')
28
31
  Spree::Sample.load_sample('payments')
29
32
  Spree::Sample.load_sample('store_credit_categories')
33
+ Spree::Sample.load_sample('return_authorization_reasons')
30
34
  end
31
35
  end
32
36
  end