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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae368b2caf7e525b5322165887ab2d251c3762c7
4
- data.tar.gz: b96d9d92993d3c4d195ad26ad592229805c1dc13
3
+ metadata.gz: 032fbbb9b2a5a9b5bb0c978357797bbbfccc692c
4
+ data.tar.gz: 169d8e099c36086d2cc036f18959de1a0aa09990
5
5
  SHA512:
6
- metadata.gz: 60a8d98d10bd6d00b642b11992d1ab6dfda282e21b4ff4fef580b30938db8758b88d4306c19cc6828b91585c07c87cda41dae6f5dca3e0915d5a74d3fc93c890
7
- data.tar.gz: 8a47ef1bbaa8e7a190b6f8b69597b7c2ad8cef6bd698e2e9180be7e15e52edbdc1eb4a935d41aad75d1b89d9e1efa2547063b65d1464cf9af6817fafa59431f7
6
+ metadata.gz: f799e7f012c903e4885fa9e94aa782a47ff3cc3a2a97bfaf8563e121bc6ca3d970d8c0130d274f01de1e0678fe63c946acac5f61b0687a1c3b5291eb80ee4a3a
7
+ data.tar.gz: 2058b2b9c55ab25c671cecc0d6d0ae1b2e8da832611cdc46b518fcac88c8efc9c0f130b6a7e799770d71d186d28a189dd8c84c0325fa77ea66e99998b0a35da0
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  eval(File.read(File.dirname(__FILE__) + '/../common_spree_dependencies.rb'))
2
2
 
3
- gem 'spree_core', :path => '../core'
3
+ gem 'spree_core', path: '../core'
4
4
 
5
5
  gemspec
@@ -3,18 +3,20 @@ Spree::Sample.load_sample("orders")
3
3
  first_order = Spree::Order.find_by_number!("R123456789")
4
4
  last_order = Spree::Order.find_by_number!("R987654321")
5
5
 
6
- first_order.adjustments.create!(
7
- :amount => 0,
8
- :source => Spree::TaxRate.find_by_name!("North America"),
9
- :order => first_order,
10
- :label => "Tax",
11
- :state => "open",
12
- :mandatory => true)
6
+ first_order.adjustments.where(
7
+ source: Spree::TaxRate.find_by_name!("North America"),
8
+ order: first_order,
9
+ label: "Tax",
10
+ state: "open",
11
+ mandatory: true).first_or_create! do |adj|
12
+ adj.amount = 0
13
+ end
13
14
 
14
- last_order.adjustments.create!(
15
- :amount => 0,
16
- :source => Spree::TaxRate.find_by_name!("North America"),
17
- :order => last_order,
18
- :label => "Tax",
19
- :state => "open",
20
- :mandatory => true)
15
+ last_order.adjustments.where(
16
+ source: Spree::TaxRate.find_by_name!("North America"),
17
+ order: last_order,
18
+ label: "Tax",
19
+ state: "open",
20
+ mandatory: true).first_or_create! do |adj|
21
+ adj.amount = 0
22
+ end
data/db/samples/assets.rb CHANGED
@@ -2,7 +2,7 @@ Spree::Sample.load_sample("products")
2
2
  Spree::Sample.load_sample("variants")
3
3
 
4
4
  products = {}
5
- products[:ror_baseball_jersey] = Spree::Product.find_by_name!("Ruby on Rails Baseball Jersey")
5
+ products[:ror_baseball_jersey] = Spree::Product.find_by_name!("Ruby on Rails Baseball Jersey")
6
6
  products[:ror_tote] = Spree::Product.find_by_name!("Ruby on Rails Tote")
7
7
  products[:ror_bag] = Spree::Product.find_by_name!("Ruby on Rails Bag")
8
8
  products[:ror_jr_spaghetti] = Spree::Product.find_by_name!("Ruby on Rails Jr. Spaghetti")
@@ -19,141 +19,177 @@ products[:spree_bag] = Spree::Product.find_by_name!("Spree Bag")
19
19
  products[:ruby_baseball_jersey] = Spree::Product.find_by_name!("Ruby Baseball Jersey")
20
20
  products[:apache_baseball_jersey] = Spree::Product.find_by_name!("Apache Baseball Jersey")
21
21
 
22
-
23
- def image(name, type="jpeg")
22
+ def image(name, type = "jpeg")
24
23
  images_path = Pathname.new(File.dirname(__FILE__)) + "images"
25
- path = images_path + "#{name}.#{type}"
24
+ path = images_path + file_name(name, type)
26
25
  return false if !File.exist?(path)
27
26
  File.open(path)
28
27
  end
29
28
 
29
+ def file_name(name, type = "jpeg")
30
+ "#{name}.#{type}"
31
+ end
32
+
30
33
  images = {
31
34
  products[:ror_tote].master => [
32
35
  {
33
- :attachment => image("ror_tote")
36
+ name: file_name("ror_tote"),
37
+ attachment: image("ror_tote")
34
38
  },
35
39
  {
36
- :attachment => image("ror_tote_back")
40
+ name: file_name("ror_tote_back"),
41
+ attachment: image("ror_tote_back")
37
42
  }
38
43
  ],
39
44
  products[:ror_bag].master => [
40
45
  {
41
- :attachment => image("ror_bag")
46
+ name: file_name("ror_bag"),
47
+ attachment: image("ror_bag")
42
48
  }
43
49
  ],
44
50
  products[:ror_baseball_jersey].master => [
45
51
  {
46
- :attachment => image("ror_baseball")
52
+ name: file_name("ror_baseball"),
53
+ attachment: image("ror_baseball")
47
54
  },
48
55
  {
49
- :attachment => image("ror_baseball_back")
56
+ name: file_name("ror_baseball_back"),
57
+ attachment: image("ror_baseball_back")
50
58
  }
51
59
  ],
52
60
  products[:ror_jr_spaghetti].master => [
53
61
  {
54
- :attachment => image("ror_jr_spaghetti")
62
+ name: file_name("ror_jr_spaghetti"),
63
+ attachment: image("ror_jr_spaghetti")
55
64
  }
56
65
  ],
57
66
  products[:ror_mug].master => [
58
67
  {
59
- :attachment => image("ror_mug")
68
+ name: file_name("ror_mug"),
69
+ attachment: image("ror_mug")
60
70
  },
61
71
  {
62
- :attachment => image("ror_mug_back")
72
+ name: file_name("ror_mug_back"),
73
+ attachment: image("ror_mug_back")
63
74
  }
64
75
  ],
65
76
  products[:ror_ringer].master => [
66
77
  {
67
- :attachment => image("ror_ringer")
78
+ name: file_name("ror_ringer"),
79
+ attachment: image("ror_ringer")
68
80
  },
69
81
  {
70
- :attachment => image("ror_ringer_back")
82
+ name: file_name("ror_ringer_back"),
83
+ attachment: image("ror_ringer_back")
71
84
  }
72
85
  ],
73
86
  products[:ror_stein].master => [
74
87
  {
75
- :attachment => image("ror_stein")
88
+ name: file_name("ror_stein"),
89
+ attachment: image("ror_stein")
76
90
  },
77
91
  {
78
- :attachment => image("ror_stein_back")
92
+ name: file_name("ror_stein_back"),
93
+ attachment: image("ror_stein_back")
79
94
  }
80
95
  ],
81
96
  products[:apache_baseball_jersey].master => [
82
97
  {
83
- :attachment => image("apache_baseball", "png")
98
+ name: file_name("apache_baseball", "png"),
99
+ attachment: image("apache_baseball", "png")
84
100
  },
85
101
  ],
86
102
  products[:ruby_baseball_jersey].master => [
87
103
  {
88
- :attachment => image("ruby_baseball", "png")
104
+ name: file_name("ruby_baseball", "png"),
105
+ attachment: image("ruby_baseball", "png")
89
106
  },
90
107
  ],
91
108
  products[:spree_bag].master => [
92
109
  {
93
- :attachment => image("spree_bag")
110
+ name: file_name("spree_bag"),
111
+ attachment: image("spree_bag")
94
112
  },
95
113
  ],
96
114
  products[:spree_tote].master => [
97
115
  {
98
- :attachment => image("spree_tote_front")
116
+ name: file_name("spree_tote_front"),
117
+ attachment: image("spree_tote_front")
99
118
  },
100
119
  {
101
- :attachment => image("spree_tote_back")
120
+ name: file_name("spree_tote_back"),
121
+ attachment: image("spree_tote_back")
102
122
  }
103
123
  ],
104
124
  products[:spree_ringer].master => [
105
125
  {
106
- :attachment => image("spree_ringer_t")
126
+ name: file_name("spree_ringer_t"),
127
+ attachment: image("spree_ringer_t")
107
128
  },
108
129
  {
109
- :attachment => image("spree_ringer_t_back")
130
+ name: file_name("spree_ringer_t_back"),
131
+ attachment: image("spree_ringer_t_back")
110
132
  }
111
133
  ],
112
134
  products[:spree_jr_spaghetti].master => [
113
135
  {
114
- :attachment => image("spree_spaghetti")
136
+ name: file_name("spree_spaghetti"),
137
+ attachment: image("spree_spaghetti")
115
138
  }
116
139
  ],
117
140
  products[:spree_baseball_jersey].master => [
118
141
  {
119
- :attachment => image("spree_jersey")
142
+ name: file_name("spree_jersey"),
143
+ attachment: image("spree_jersey")
120
144
  },
121
145
  {
122
- :attachment => image("spree_jersey_back")
146
+ name: file_name("spree_jersey_back"),
147
+ attachment: image("spree_jersey_back")
123
148
  }
124
149
  ],
125
150
  products[:spree_stein].master => [
126
151
  {
127
- :attachment => image("spree_stein")
152
+ name: file_name("spree_stein"),
153
+ attachment: image("spree_stein")
128
154
  },
129
155
  {
130
- :attachment => image("spree_stein_back")
156
+ name: file_name("spree_stein_back"),
157
+ attachment: image("spree_stein_back")
131
158
  }
132
159
  ],
133
160
  products[:spree_mug].master => [
134
161
  {
135
- :attachment => image("spree_mug")
162
+ name: file_name("spree_mug"),
163
+ attachment: image("spree_mug")
136
164
  },
137
165
  {
138
- :attachment => image("spree_mug_back")
166
+ name: file_name("spree_mug_back"),
167
+ attachment: image("spree_mug_back")
139
168
  }
140
169
  ],
141
170
  }
142
171
 
143
172
  products[:ror_baseball_jersey].variants.each do |variant|
144
173
  color = variant.option_value("tshirt-color").downcase
145
- main_image = image("ror_baseball_jersey_#{color}", "png")
146
- variant.images.create!(:attachment => main_image)
147
- back_image = image("ror_baseball_jersey_back_#{color}", "png")
148
- if back_image
149
- variant.images.create!(:attachment => back_image)
174
+
175
+ if variant.images.where(attachment_file_name: file_name("ror_baseball_jersey_#{color}", "png")).none?
176
+ main_image = image("ror_baseball_jersey_#{color}", "png")
177
+ variant.images.create!(attachment: main_image)
178
+ end
179
+
180
+ if variant.images.where(attachment_file_name: file_name("ror_baseball_jersey_back_#{color}", "png")).none?
181
+ back_image = image("ror_baseball_jersey_back_#{color}", "png")
182
+ variant.images.create!(attachment: back_image)
150
183
  end
151
184
  end
152
185
 
153
186
  images.each do |variant, attachments|
154
187
  puts "Loading images for #{variant.product.name}"
155
- attachments.each do |attachment|
156
- variant.images.create!(attachment)
188
+ attachments.each do |attrs|
189
+ file_name = attrs.delete(:name)
190
+
191
+ if variant.images.where(attachment_file_name: file_name).none?
192
+ variant.images.create!(attrs)
193
+ end
157
194
  end
158
195
  end
159
-
@@ -1,12 +1,16 @@
1
- Spree::OptionType.create!([
1
+ option_types_attributes = [
2
2
  {
3
- :name => "tshirt-size",
4
- :presentation => "Size",
5
- :position => 1
3
+ name: "tshirt-size",
4
+ presentation: "Size",
5
+ position: 1
6
6
  },
7
7
  {
8
- :name => "tshirt-color",
9
- :presentation => "Color",
10
- :position => 2
8
+ name: "tshirt-color",
9
+ presentation: "Color",
10
+ position: 2
11
11
  }
12
- ])
12
+ ]
13
+
14
+ option_types_attributes.each do |attrs|
15
+ Spree::OptionType.where(attrs).first_or_create!
16
+ end
@@ -3,47 +3,51 @@ Spree::Sample.load_sample("option_types")
3
3
  size = Spree::OptionType.find_by_presentation!("Size")
4
4
  color = Spree::OptionType.find_by_presentation!("Color")
5
5
 
6
- Spree::OptionValue.create!([
6
+ option_values_attributes = [
7
7
  {
8
- :name => "Small",
9
- :presentation => "S",
10
- :position => 1,
11
- :option_type => size
8
+ name: "Small",
9
+ presentation: "S",
10
+ position: 1,
11
+ option_type: size
12
12
  },
13
13
  {
14
- :name => "Medium",
15
- :presentation => "M",
16
- :position => 2,
17
- :option_type => size
14
+ name: "Medium",
15
+ presentation: "M",
16
+ position: 2,
17
+ option_type: size
18
18
  },
19
19
  {
20
- :name => "Large",
21
- :presentation => "L",
22
- :position => 3,
23
- :option_type => size
20
+ name: "Large",
21
+ presentation: "L",
22
+ position: 3,
23
+ option_type: size
24
24
  },
25
25
  {
26
- :name => "Extra Large",
27
- :presentation => "XL",
28
- :position => 4,
29
- :option_type => size
26
+ name: "Extra Large",
27
+ presentation: "XL",
28
+ position: 4,
29
+ option_type: size
30
30
  },
31
31
  {
32
- :name => "Red",
33
- :presentation => "Red",
34
- :position => 1,
35
- :option_type => color,
32
+ name: "Red",
33
+ presentation: "Red",
34
+ position: 1,
35
+ option_type: color,
36
36
  },
37
37
  {
38
- :name => "Green",
39
- :presentation => "Green",
40
- :position => 2,
41
- :option_type => color,
38
+ name: "Green",
39
+ presentation: "Green",
40
+ position: 2,
41
+ option_type: color,
42
42
  },
43
43
  {
44
- :name => "Blue",
45
- :presentation => "Blue",
46
- :position => 3,
47
- :option_type => color
44
+ name: "Blue",
45
+ presentation: "Blue",
46
+ position: 3,
47
+ option_type: color
48
48
  }
49
- ])
49
+ ]
50
+
51
+ option_values_attributes.each do |attrs|
52
+ Spree::OptionValue.where(attrs).first_or_create!
53
+ end
data/db/samples/orders.rb CHANGED
@@ -1,33 +1,37 @@
1
1
  Spree::Sample.load_sample("addresses")
2
2
 
3
3
  orders = []
4
- orders << Spree::Order.create!(
5
- :number => "R123456789",
6
- :email => "spree@example.com",
7
- :item_total => 150.95,
8
- :adjustment_total => 150.95,
9
- :total => 301.90,
10
- :shipping_address => Spree::Address.first,
11
- :billing_address => Spree::Address.last)
4
+ orders << Spree::Order.where(
5
+ number: "R123456789",
6
+ email: "spree@example.com").first_or_create! do |order|
7
+ order.item_total = 150.95
8
+ order.adjustment_total = 150.95
9
+ order.total = 301.90
10
+ end
12
11
 
13
- orders << Spree::Order.create!(
14
- :number => "R987654321",
15
- :email => "spree@example.com",
16
- :item_total => 15.95,
17
- :adjustment_total => 15.95,
18
- :total => 31.90,
19
- :shipping_address => Spree::Address.first,
20
- :billing_address => Spree::Address.last)
12
+ orders << Spree::Order.where(
13
+ number: "R987654321",
14
+ email: "spree@example.com").first_or_create! do |order|
15
+ order.item_total = 15.95
16
+ order.adjustment_total = 15.95
17
+ order.total = 31.90
18
+ order.shipping_address = Spree::Address.first
19
+ order.billing_address = Spree::Address.last
20
+ end
21
21
 
22
- orders[0].line_items.create!(
23
- :variant => Spree::Product.find_by_name!("Ruby on Rails Tote").master,
24
- :quantity => 1,
25
- :price => 15.99)
22
+ unless orders[0].line_items.any?
23
+ orders[0].line_items.new(
24
+ variant: Spree::Product.find_by_name!("Ruby on Rails Tote").master,
25
+ quantity: 1,
26
+ price: 15.99).save!
27
+ end
26
28
 
27
- orders[1].line_items.create!(
28
- :variant => Spree::Product.find_by_name!("Ruby on Rails Bag").master,
29
- :quantity => 1,
30
- :price => 22.99)
29
+ unless orders[1].line_items.any?
30
+ orders[1].line_items.new(
31
+ variant: Spree::Product.find_by_name!("Ruby on Rails Bag").master,
32
+ quantity: 1,
33
+ price: 22.99).save!
34
+ end
31
35
 
32
36
  orders.each(&:create_proposed_shipments)
33
37