spree_sample 3.5.0 → 3.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 91671528fff304c0c25a1470cbf5e5403bc73d84
4
- data.tar.gz: 6816c82f505b0752047739d254c3c19c089e4958
2
+ SHA256:
3
+ metadata.gz: 4c26831ae4064ae77d73f1dee1ef9c58b6b130ffca1a589eb16042706ef9f7b1
4
+ data.tar.gz: 875091811939c84887d2b90a3126b5f0bb47c6efba25e65c81f42b8e55eba8f7
5
5
  SHA512:
6
- metadata.gz: 5ca3c783683f042135dded713b53056713fa7c9350efc1aedb9c06f2ddc9eccf960e29d23772ebfdb8308513d064280cfcf85ed312929f0add5494159cae0aa3
7
- data.tar.gz: bbb418f7f8788cbb05058076c843c3da0a4500408118f22ed7ef6bb77dd0ff2dee556464952f79067c80984ef01ef3662a8686155941918ecd8a8fd326626dc0
6
+ metadata.gz: a8ee152c2ea08268208fcb41bec8145578cd827ce418f3d0d67900d2cb0944749523fb8621fa1e42e7d0f94a8784d3a1c3f6301fb26919059a73c6e4c1c41c7c
7
+ data.tar.gz: 805ed9b71b26b978007a409cdb3a1aaffae49c5142bb1c8aad0767cf4aa88a9812a454812814c74d915a52fe3420308a45ca49c6b7b8927b630a45ea23636016
data/db/samples.rb CHANGED
@@ -1,2 +1,2 @@
1
- Spree::Sample.load_sample("payment_methods")
2
- Spree::Sample.load_sample("shipping_categories")
1
+ Spree::Sample.load_sample('payment_methods')
2
+ Spree::Sample.load_sample('shipping_categories')
@@ -1,5 +1,5 @@
1
- united_states = Spree::Country.find_by!(iso: "US")
2
- new_york = Spree::State.find_by!(name: "New York")
1
+ united_states = Spree::Country.find_by!(iso: 'US')
2
+ new_york = Spree::State.find_by!(name: 'New York')
3
3
 
4
4
  # Billing address
5
5
  Spree::Address.create!(
@@ -11,9 +11,10 @@ Spree::Address.create!(
11
11
  state: new_york,
12
12
  zipcode: 16804,
13
13
  country: united_states,
14
- phone: FFaker::PhoneNumber.phone_number)
14
+ phone: FFaker::PhoneNumber.phone_number
15
+ )
15
16
 
16
- #Shipping address
17
+ # Shipping address
17
18
  Spree::Address.create!(
18
19
  firstname: FFaker::Name.first_name,
19
20
  lastname: FFaker::Name.last_name,
@@ -23,4 +24,5 @@ Spree::Address.create!(
23
24
  state: new_york,
24
25
  zipcode: 16804,
25
26
  country: united_states,
26
- phone: FFaker::PhoneNumber.phone_number)
27
+ phone: FFaker::PhoneNumber.phone_number
28
+ )
@@ -1,22 +1,24 @@
1
- Spree::Sample.load_sample("orders")
1
+ Spree::Sample.load_sample('orders')
2
2
 
3
- first_order = Spree::Order.find_by!(number: "R123456789")
4
- last_order = Spree::Order.find_by!(number: "R987654321")
3
+ first_order = Spree::Order.find_by!(number: 'R123456789')
4
+ last_order = Spree::Order.find_by!(number: 'R987654321')
5
5
 
6
6
  first_order.adjustments.where(
7
- source: Spree::TaxRate.find_by!(name: "North America"),
7
+ source: Spree::TaxRate.find_by!(name: 'North America'),
8
8
  order: first_order,
9
- label: "Tax",
10
- state: "open",
11
- mandatory: true).first_or_create! do |adj|
12
- adj.amount = 0
13
- end
9
+ label: 'Tax',
10
+ state: 'open',
11
+ mandatory: true
12
+ ).first_or_create! do |adj|
13
+ adj.amount = 0
14
+ end
14
15
 
15
16
  last_order.adjustments.where(
16
- source: Spree::TaxRate.find_by!(name: "North America"),
17
+ source: Spree::TaxRate.find_by!(name: 'North America'),
17
18
  order: last_order,
18
- label: "Tax",
19
- state: "open",
20
- mandatory: true).first_or_create! do |adj|
21
- adj.amount = 0
22
- end
19
+ label: 'Tax',
20
+ state: 'open',
21
+ mandatory: true
22
+ ).first_or_create! do |adj|
23
+ adj.amount = 0
24
+ end
data/db/samples/assets.rb CHANGED
@@ -1,196 +1,209 @@
1
1
  unless ENV['SKIP_SAMPLE_IMAGES']
2
- Spree::Sample.load_sample("products")
3
- Spree::Sample.load_sample("variants")
4
-
2
+ Spree::Sample.load_sample('products')
3
+ Spree::Sample.load_sample('variants')
5
4
  products = {}
6
- products[:ror_baseball_jersey] = Spree::Product.find_by!(name: "Ruby on Rails Baseball Jersey")
7
- products[:ror_tote] = Spree::Product.find_by!(name: "Ruby on Rails Tote")
8
- products[:ror_bag] = Spree::Product.find_by!(name: "Ruby on Rails Bag")
9
- products[:ror_jr_spaghetti] = Spree::Product.find_by!(name: "Ruby on Rails Jr. Spaghetti")
10
- products[:ror_mug] = Spree::Product.find_by!(name: "Ruby on Rails Mug")
11
- products[:ror_ringer] = Spree::Product.find_by!(name: "Ruby on Rails Ringer T-Shirt")
12
- products[:ror_stein] = Spree::Product.find_by!(name: "Ruby on Rails Stein")
13
- products[:spree_baseball_jersey] = Spree::Product.find_by!(name: "Spree Baseball Jersey")
14
- products[:spree_stein] = Spree::Product.find_by!(name: "Spree Stein")
15
- products[:spree_jr_spaghetti] = Spree::Product.find_by!(name: "Spree Jr. Spaghetti")
16
- products[:spree_mug] = Spree::Product.find_by!(name: "Spree Mug")
17
- products[:spree_ringer] = Spree::Product.find_by!(name: "Spree Ringer T-Shirt")
18
- products[:spree_tote] = Spree::Product.find_by!(name: "Spree Tote")
19
- products[:spree_bag] = Spree::Product.find_by!(name: "Spree Bag")
20
- products[:ruby_baseball_jersey] = Spree::Product.find_by!(name: "Ruby Baseball Jersey")
21
- products[:apache_baseball_jersey] = Spree::Product.find_by!(name: "Apache Baseball Jersey")
5
+ products[:ror_baseball_jersey] = Spree::Product.find_by!(name: 'Ruby on Rails Baseball Jersey')
6
+ products[:ror_tote] = Spree::Product.find_by!(name: 'Ruby on Rails Tote')
7
+ products[:ror_bag] = Spree::Product.find_by!(name: 'Ruby on Rails Bag')
8
+ products[:ror_jr_spaghetti] = Spree::Product.find_by!(name: 'Ruby on Rails Jr. Spaghetti')
9
+ products[:ror_mug] = Spree::Product.find_by!(name: 'Ruby on Rails Mug')
10
+ products[:ror_ringer] = Spree::Product.find_by!(name: 'Ruby on Rails Ringer T-Shirt')
11
+ products[:ror_stein] = Spree::Product.find_by!(name: 'Ruby on Rails Stein')
12
+ products[:spree_baseball_jersey] = Spree::Product.find_by!(name: 'Spree Baseball Jersey')
13
+ products[:spree_stein] = Spree::Product.find_by!(name: 'Spree Stein')
14
+ products[:spree_jr_spaghetti] = Spree::Product.find_by!(name: 'Spree Jr. Spaghetti')
15
+ products[:spree_mug] = Spree::Product.find_by!(name: 'Spree Mug')
16
+ products[:spree_ringer] = Spree::Product.find_by!(name: 'Spree Ringer T-Shirt')
17
+ products[:spree_tote] = Spree::Product.find_by!(name: 'Spree Tote')
18
+ products[:spree_bag] = Spree::Product.find_by!(name: 'Spree Bag')
19
+ products[:ruby_baseball_jersey] = Spree::Product.find_by!(name: 'Ruby Baseball Jersey')
20
+ products[:apache_baseball_jersey] = Spree::Product.find_by!(name: 'Apache Baseball Jersey')
22
21
 
23
- def image(name, type = "jpeg")
24
- images_path = Pathname.new(File.dirname(__FILE__)) + "images"
22
+ def image(name, type = 'jpeg')
23
+ images_path = Pathname.new(File.dirname(__FILE__)) + 'images'
25
24
  path = images_path + file_name(name, type)
26
- return false if !File.exist?(path)
25
+ return false unless File.exist?(path)
27
26
  File.open(path)
28
27
  end
29
28
 
30
- def file_name(name, type = "jpeg")
29
+ def file_name(name, type = 'jpeg')
31
30
  "#{name}.#{type}"
32
31
  end
33
32
 
33
+ def attach_paperclip_image(variant, name, type)
34
+ if variant.images.where(attachment_file_name: file_name(name, type)).none?
35
+ image = image(name, type)
36
+ variant.images.create!(attachment: image)
37
+ end
38
+ end
39
+
40
+ def attach_active_storage_image(variant, name, type)
41
+ if variant.images.with_attached_attachment.where(active_storage_blobs: { filename: file_name(name, type) }).none?
42
+ image = image(name, type)
43
+ variant.images.create!(attachment: { io: image, filename: file_name(name, type) })
44
+ end
45
+ end
46
+
34
47
  images = {
35
48
  products[:ror_tote].master => [
36
49
  {
37
- name: file_name("ror_tote"),
38
- attachment: image("ror_tote")
50
+ name: file_name('ror_tote'),
51
+ attachment: image('ror_tote')
39
52
  },
40
53
  {
41
- name: file_name("ror_tote_back"),
42
- attachment: image("ror_tote_back")
54
+ name: file_name('ror_tote_back'),
55
+ attachment: image('ror_tote_back')
43
56
  }
44
57
  ],
45
58
  products[:ror_bag].master => [
46
59
  {
47
- name: file_name("ror_bag"),
48
- attachment: image("ror_bag")
60
+ name: file_name('ror_bag'),
61
+ attachment: image('ror_bag')
49
62
  }
50
63
  ],
51
64
  products[:ror_baseball_jersey].master => [
52
65
  {
53
- name: file_name("ror_baseball"),
54
- attachment: image("ror_baseball")
66
+ name: file_name('ror_baseball'),
67
+ attachment: image('ror_baseball')
55
68
  },
56
69
  {
57
- name: file_name("ror_baseball_back"),
58
- attachment: image("ror_baseball_back")
70
+ name: file_name('ror_baseball_back'),
71
+ attachment: image('ror_baseball_back')
59
72
  }
60
73
  ],
61
74
  products[:ror_jr_spaghetti].master => [
62
75
  {
63
- name: file_name("ror_jr_spaghetti"),
64
- attachment: image("ror_jr_spaghetti")
76
+ name: file_name('ror_jr_spaghetti'),
77
+ attachment: image('ror_jr_spaghetti')
65
78
  }
66
79
  ],
67
80
  products[:ror_mug].master => [
68
81
  {
69
- name: file_name("ror_mug"),
70
- attachment: image("ror_mug")
82
+ name: file_name('ror_mug'),
83
+ attachment: image('ror_mug')
71
84
  },
72
85
  {
73
- name: file_name("ror_mug_back"),
74
- attachment: image("ror_mug_back")
86
+ name: file_name('ror_mug_back'),
87
+ attachment: image('ror_mug_back')
75
88
  }
76
89
  ],
77
90
  products[:ror_ringer].master => [
78
91
  {
79
- name: file_name("ror_ringer"),
80
- attachment: image("ror_ringer")
92
+ name: file_name('ror_ringer'),
93
+ attachment: image('ror_ringer')
81
94
  },
82
95
  {
83
- name: file_name("ror_ringer_back"),
84
- attachment: image("ror_ringer_back")
96
+ name: file_name('ror_ringer_back'),
97
+ attachment: image('ror_ringer_back')
85
98
  }
86
99
  ],
87
100
  products[:ror_stein].master => [
88
101
  {
89
- name: file_name("ror_stein"),
90
- attachment: image("ror_stein")
102
+ name: file_name('ror_stein'),
103
+ attachment: image('ror_stein')
91
104
  },
92
105
  {
93
- name: file_name("ror_stein_back"),
94
- attachment: image("ror_stein_back")
106
+ name: file_name('ror_stein_back'),
107
+ attachment: image('ror_stein_back')
95
108
  }
96
109
  ],
97
110
  products[:apache_baseball_jersey].master => [
98
111
  {
99
- name: file_name("apache_baseball", "png"),
100
- attachment: image("apache_baseball", "png")
101
- },
112
+ name: file_name('apache_baseball', 'png'),
113
+ attachment: image('apache_baseball', 'png')
114
+ }
102
115
  ],
103
116
  products[:ruby_baseball_jersey].master => [
104
117
  {
105
- name: file_name("ruby_baseball", "png"),
106
- attachment: image("ruby_baseball", "png")
107
- },
118
+ name: file_name('ruby_baseball', 'png'),
119
+ attachment: image('ruby_baseball', 'png')
120
+ }
108
121
  ],
109
122
  products[:spree_bag].master => [
110
123
  {
111
- name: file_name("spree_bag"),
112
- attachment: image("spree_bag")
113
- },
124
+ name: file_name('spree_bag'),
125
+ attachment: image('spree_bag')
126
+ }
114
127
  ],
115
128
  products[:spree_tote].master => [
116
129
  {
117
- name: file_name("spree_tote_front"),
118
- attachment: image("spree_tote_front")
130
+ name: file_name('spree_tote_front'),
131
+ attachment: image('spree_tote_front')
119
132
  },
120
133
  {
121
- name: file_name("spree_tote_back"),
122
- attachment: image("spree_tote_back")
134
+ name: file_name('spree_tote_back'),
135
+ attachment: image('spree_tote_back')
123
136
  }
124
137
  ],
125
138
  products[:spree_ringer].master => [
126
139
  {
127
- name: file_name("spree_ringer_t"),
128
- attachment: image("spree_ringer_t")
140
+ name: file_name('spree_ringer_t'),
141
+ attachment: image('spree_ringer_t')
129
142
  },
130
143
  {
131
- name: file_name("spree_ringer_t_back"),
132
- attachment: image("spree_ringer_t_back")
144
+ name: file_name('spree_ringer_t_back'),
145
+ attachment: image('spree_ringer_t_back')
133
146
  }
134
147
  ],
135
148
  products[:spree_jr_spaghetti].master => [
136
149
  {
137
- name: file_name("spree_spaghetti"),
138
- attachment: image("spree_spaghetti")
150
+ name: file_name('spree_spaghetti'),
151
+ attachment: image('spree_spaghetti')
139
152
  }
140
153
  ],
141
154
  products[:spree_baseball_jersey].master => [
142
155
  {
143
- name: file_name("spree_jersey"),
144
- attachment: image("spree_jersey")
156
+ name: file_name('spree_jersey'),
157
+ attachment: image('spree_jersey')
145
158
  },
146
159
  {
147
- name: file_name("spree_jersey_back"),
148
- attachment: image("spree_jersey_back")
160
+ name: file_name('spree_jersey_back'),
161
+ attachment: image('spree_jersey_back')
149
162
  }
150
163
  ],
151
164
  products[:spree_stein].master => [
152
165
  {
153
- name: file_name("spree_stein"),
154
- attachment: image("spree_stein")
166
+ name: file_name('spree_stein'),
167
+ attachment: image('spree_stein')
155
168
  },
156
169
  {
157
- name: file_name("spree_stein_back"),
158
- attachment: image("spree_stein_back")
170
+ name: file_name('spree_stein_back'),
171
+ attachment: image('spree_stein_back')
159
172
  }
160
173
  ],
161
174
  products[:spree_mug].master => [
162
175
  {
163
- name: file_name("spree_mug"),
164
- attachment: image("spree_mug")
176
+ name: file_name('spree_mug'),
177
+ attachment: image('spree_mug')
165
178
  },
166
179
  {
167
- name: file_name("spree_mug_back"),
168
- attachment: image("spree_mug_back")
180
+ name: file_name('spree_mug_back'),
181
+ attachment: image('spree_mug_back')
169
182
  }
170
- ],
183
+ ]
171
184
  }
172
185
 
173
186
  products[:ror_baseball_jersey].variants.each do |variant|
174
- color = variant.option_value("tshirt-color").downcase
175
-
176
- if variant.images.where(attachment_file_name: file_name("ror_baseball_jersey_#{color}", "png")).none?
177
- main_image = image("ror_baseball_jersey_#{color}", "png")
178
- variant.images.create!(attachment: main_image)
179
- end
187
+ color = variant.option_value('tshirt-color').downcase
180
188
 
181
- if variant.images.where(attachment_file_name: file_name("ror_baseball_jersey_back_#{color}", "png")).none?
182
- back_image = image("ror_baseball_jersey_back_#{color}", "png")
183
- variant.images.create!(attachment: back_image)
189
+ if Rails.application.config.use_paperclip
190
+ attach_paperclip_image(variant, "ror_baseball_jersey_#{color}", 'png')
191
+ attach_paperclip_image(variant, "ror_baseball_jersey_back_#{color}", 'png')
192
+ else
193
+ attach_active_storage_image(variant, "ror_baseball_jersey_#{color}", 'png')
194
+ attach_active_storage_image(variant, "ror_baseball_jersey_back_#{color}", 'png')
184
195
  end
185
196
  end
186
197
 
187
198
  images.each do |variant, attachments|
188
199
  puts "Loading images for #{variant.product.name}"
189
200
  attachments.each do |attrs|
190
- file_name = attrs.delete(:name)
191
-
192
- if variant.images.where(attachment_file_name: file_name).none?
193
- variant.images.create!(attrs)
201
+ if Rails.application.config.use_paperclip
202
+ file_name = attrs.delete(:name)
203
+ variant.images.create!(attrs) if variant.images.where(attachment_file_name: file_name).none?
204
+ else
205
+ name, type = attrs.delete(:name).split('.')
206
+ attach_active_storage_image(variant, name, type)
194
207
  end
195
208
  end
196
209
  end
@@ -1,12 +1,12 @@
1
1
  option_types_attributes = [
2
2
  {
3
- name: "tshirt-size",
4
- presentation: "Size",
3
+ name: 'tshirt-size',
4
+ presentation: 'Size',
5
5
  position: 1
6
6
  },
7
7
  {
8
- name: "tshirt-color",
9
- presentation: "Color",
8
+ name: 'tshirt-color',
9
+ presentation: 'Color',
10
10
  position: 2
11
11
  }
12
12
  ]
@@ -1,48 +1,48 @@
1
- Spree::Sample.load_sample("option_types")
1
+ Spree::Sample.load_sample('option_types')
2
2
 
3
- size = Spree::OptionType.find_by!(presentation: "Size")
4
- color = Spree::OptionType.find_by!(presentation: "Color")
3
+ size = Spree::OptionType.find_by!(presentation: 'Size')
4
+ color = Spree::OptionType.find_by!(presentation: 'Color')
5
5
 
6
6
  option_values_attributes = [
7
7
  {
8
- name: "Small",
9
- presentation: "S",
8
+ name: 'Small',
9
+ presentation: 'S',
10
10
  position: 1,
11
11
  option_type: size
12
12
  },
13
13
  {
14
- name: "Medium",
15
- presentation: "M",
14
+ name: 'Medium',
15
+ presentation: 'M',
16
16
  position: 2,
17
17
  option_type: size
18
18
  },
19
19
  {
20
- name: "Large",
21
- presentation: "L",
20
+ name: 'Large',
21
+ presentation: 'L',
22
22
  position: 3,
23
23
  option_type: size
24
24
  },
25
25
  {
26
- name: "Extra Large",
27
- presentation: "XL",
26
+ name: 'Extra Large',
27
+ presentation: 'XL',
28
28
  position: 4,
29
29
  option_type: size
30
30
  },
31
31
  {
32
- name: "Red",
33
- presentation: "Red",
32
+ name: 'Red',
33
+ presentation: 'Red',
34
34
  position: 1,
35
- option_type: color,
35
+ option_type: color
36
36
  },
37
37
  {
38
- name: "Green",
39
- presentation: "Green",
38
+ name: 'Green',
39
+ presentation: 'Green',
40
40
  position: 2,
41
- option_type: color,
41
+ option_type: color
42
42
  },
43
43
  {
44
- name: "Blue",
45
- presentation: "Blue",
44
+ name: 'Blue',
45
+ presentation: 'Blue',
46
46
  position: 3,
47
47
  option_type: color
48
48
  }