datashift_spree 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -14,12 +14,17 @@ module DataShift
14
14
 
15
15
  class ProductLoader < SpreeBaseLoader
16
16
 
17
- # depending on version get_product_class should return us right class, namespaced or not
18
-
17
+ # Options
18
+ #
19
+ # :reload : Force load of the method dictionary for object_class even if already loaded
20
+ # :verbose : Verboise logging and to STDOUT
21
+ #
19
22
  def initialize(product = nil, options = {})
20
23
 
21
24
  opts = {:instance_methods => true}.merge( options )
22
25
 
26
+ # depending on version get_product_class should return us right class, namespaced or not
27
+
23
28
  super( DataShift::SpreeHelper::get_product_class(), true, product, opts)
24
29
 
25
30
  raise "Failed to create Product for loading" unless @load_object
@@ -120,10 +125,10 @@ module DataShift
120
125
  # Special case for OptionTypes as it's two stage process
121
126
  # First add the possible option_types to Product, then we are able
122
127
  # to define Variants on those options values.
123
- # To defiene a Variant :
124
- # 1) define at least one OptionType on Product, for example Size
125
- # 2) Provide a value for at least one of these OptionType
126
- # 3) A composite Variant can be created by supplyiung a vlaue for more than one OptionType
128
+ # So to defiene a Variant :
129
+ # 1) define at least one OptionType on Product, for example Size
130
+ # 2) Provide a value for at least one of these OptionType
131
+ # 3) A composite Variant can be created by supplying a value for more than one OptionType
127
132
  # fro example Colour : Red and Size Medium
128
133
  # Supported Syntax :
129
134
  # '|' seperates Variants
@@ -134,15 +139,18 @@ module DataShift
134
139
  # mime_type:jpeg;print_type:black_white|mime_type:jpeg|mime_type:png, PDF;print_type:colour
135
140
  #
136
141
  def add_options
137
-
142
+
138
143
  # TODO smart column ordering to ensure always valid by time we get to associations
139
144
  save_if_new
140
145
 
141
146
  # example : mime_type:jpeg;print_type:black_white|mime_type:jpeg|mime_type:png, PDF;print_type:colour
142
147
 
143
- variants = get_each_assoc#current_value.split( Delimiters::multi_assoc_delim )
148
+ variants = get_each_assoc
144
149
 
145
- # 1) mime_type:jpeg;print_type:black_white 2) mime_type:jpeg 3) mime_type:png, PDF;print_type:colour
150
+ # example line becomes :
151
+ # 1) mime_type:jpeg;print_type:black_white
152
+ # 2) mime_type:jpeg
153
+ # 3) mime_type:png, PDF;print_type:colour
146
154
 
147
155
  variants.each do |per_variant|
148
156
 
@@ -166,7 +174,7 @@ module DataShift
166
174
  end
167
175
  puts "Created missing OptionType #{option_type.inspect}"
168
176
  end
169
-
177
+
170
178
  # OptionTypes must be specified first on Product to enable Variants to be created
171
179
  # TODO - is include? very inefficient ??
172
180
  @load_object.option_types << option_type unless @load_object.option_types.include?(option_type)
@@ -185,30 +193,39 @@ module DataShift
185
193
  # Now create set of Variants, some of which maybe composites
186
194
  # Find the longest set of OVs to use as base for combining with the rest
187
195
  sorted_map = optiontype_vlist_map.sort_by { |k,v| v.size }.reverse
188
-
189
- # ovalues = 'pdf','jpeg','png'
190
- option_type, ovalues = sorted_map.shift
196
+
197
+ # [ [mime, ['pdf', 'jpeg', 'gif']], [print_type, ['black_white']] ]
198
+
199
+ lead_option_type, lead_ovalues = sorted_map.shift
200
+
191
201
  # TODO .. benchmarking to find most efficient way to create these but ensure Product.variants list
192
202
  # populated .. currently need to call reload to ensure this (seems reqd for Spree 1/Rails 3, wasn't required b4
193
- ovalues.each do |ovname|
203
+ lead_ovalues.each do |ovname|
194
204
 
195
205
  ov_list = []
196
206
 
197
- unless ov = @@option_value_klass.find_by_name_and_option_type_id(ovname.strip, option_type.id)
198
- ov = @@option_value_klass.create!(:name => ovname.strip, :presentation => ovname.strip.humanize)
199
- ov.update_attribute(:option_type_id, option_type.id)
200
- end
207
+ ovname.strip!
208
+
209
+ ov = @@option_value_klass.find_or_create_by_name_and_option_type_id(ovname, lead_option_type.id, :presentation => ovname.humanize)
201
210
 
202
211
  ov_list << ov if ov
203
-
204
- sorted_map.each do |ot, ovlist| ovlist.each do |for_composite|
205
- ov = @@option_value_klass.find_or_create_by_name_and_option_type_id(for_composite.strip, ot.id)
212
+
213
+ # Process rest of array of types => values
214
+ sorted_map.each do |ot, ovlist|
215
+ ovlist.each do |for_composite|
216
+
217
+ for_composite.strip!
218
+
219
+ ov = @@option_value_klass.find_or_create_by_name_and_option_type_id(for_composite, ot.id, :presentation => for_composite.humanize)
206
220
 
207
221
  ov_list << ov if(ov)
208
222
  end
209
223
  end
210
224
 
211
225
  unless(ov_list.empty?)
226
+
227
+ puts "Creating Variant from OptionValue(s) #{ov_list.collect(&:name).inspect}" if(verbose)
228
+
212
229
  i = @load_object.variants.size + 1
213
230
 
214
231
  # This one line seems to works for 1.1.0 - 3.2 but not 1.0.0 - 3.1 ??
@@ -218,13 +235,12 @@ module DataShift
218
235
  variant = @@variant_klass.create( :product => @load_object, :sku => "#{@load_object.sku}_#{i}", :price => @load_object.price, :available_on => @load_object.available_on)
219
236
  end
220
237
 
221
- variant.option_values << ov_list if(variant)
238
+ variant.option_values << ov_list if(variant)
222
239
  end
223
240
  end
224
241
 
225
- #puts "DEBUG Load Object now has Variants : #{@load_object.variants.inspect}"
226
242
  @load_object.reload unless @load_object.new_record?
227
- #puts "DEBUG Load Object now has Variants : #{@load_object.variants.inspect}"
243
+ #puts "DEBUG Load Object now has Variants : #{@load_object.variants.inspect}" if(verbose)
228
244
  end
229
245
 
230
246
  end # each Variant
@@ -41,7 +41,7 @@ module Datashift
41
41
 
42
42
  require 'product_loader'
43
43
 
44
- loader = DataShift::SpreeHelper::ProductLoader.new
44
+ loader = DataShift::SpreeHelper::ProductLoader.new( nil, {:verbose => options[:verbose]})
45
45
 
46
46
  # YAML configuration file to drive defaults etc
47
47
 
@@ -133,31 +133,31 @@ describe 'Spree Variants Loader' do
133
133
  # Composite Variant Syntax is option_type_A_name:value;option_type_B_name:value
134
134
  # which creates a SINGLE Variant with 2 option types
135
135
 
136
- it "should create Variants with MULTIPLE option types from single column", :new => true do
136
+ it "should create Variants with MULTIPLE option types from single column in CSV", :new => true do
137
137
  @product_loader.perform_load( ifixture_file('SpreeMultiVariant.csv'), :mandatory => ['sku', 'name', 'price'] )
138
138
 
139
+ expected_single_column_multi_variants
140
+ end
141
+
142
+ it "should create Variants with MULTIPLE option types from single column in XLS", :new => true do
143
+ @product_loader.perform_load( ifixture_file('SpreeMultiVariant.xls'), :mandatory => ['sku', 'name', 'price'] )
144
+
145
+ expected_single_column_multi_variants
146
+ end
147
+
148
+ def expected_single_column_multi_variants
149
+
139
150
  # Product 1)
140
151
  # 1 + 2) mime_type:jpeg,PDF;print_type:colour equivalent to (mime_type:jpeg;print_type:colour|mime_type:PDF;print_type:colour)
141
152
  # 3) mime_type:PNG
142
153
  #
143
- # Product 2
144
- # 4) mime_type:jpeg;print_type:black_white
145
- # 5) mime_type:PNG;print_type:black_white
146
- #
147
- # Product 3
148
- # 6 +7) mime_type:jpeg;print_type:colour,sepia;size:large
149
- # 8) mime_type:jpeg;print_type:colour
150
- # 9) mime_type:PNG
151
- # 9 + 10) mime_type:PDF|print_type:black_white
152
-
153
154
  prod_count = 3
154
155
  var_count = 10
155
156
 
156
- # plus 3 MASTER VARIANTS
157
157
  @Product_klass.count.should == prod_count
158
- @Variant_klass.count.should == prod_count + var_count
158
+ @Variant_klass.count.should == prod_count + var_count # plus 3 MASTER VARIANTS
159
159
 
160
- p = @Product_klass.first
160
+ p = @Product_klass.all[0]
161
161
 
162
162
  p.variants_including_master.should have_exactly(4).items
163
163
  p.variants.should have_exactly(3).items
@@ -167,7 +167,33 @@ describe 'Spree Variants Loader' do
167
167
  v1 = p.variants[0]
168
168
  v1.option_values.should have_exactly(2).items
169
169
  v1.option_values.collect(&:name).sort.should == ['colour','jpeg']
170
+ v1.option_values.collect(&:presentation).sort.should == ['Colour','Jpeg']
171
+
172
+ # Product 2
173
+ # 4) mime_type:jpeg;print_type:black_white
174
+ # 5) mime_type:PNG;print_type:black_white
175
+ #
176
+ p = @Product_klass.all[1]
177
+
178
+ p.variants_including_master.should have_exactly(3).items
179
+ p.variants.should have_exactly(2).items
180
+
181
+ p.option_types.should have_exactly(2).items # mime_type, print_type
182
+
183
+ p.option_types.collect(&:name).sort.should == ['mime_type','print_type']
184
+
185
+ p.variants[0].option_values.collect(&:name).sort.should == ['black_white','jpeg']
186
+ p.variants[0].option_values.collect(&:presentation).sort.should == ['Black white','Jpeg']
187
+
188
+ p.variants[1].option_values.collect(&:name).sort.should == ['PNG', 'black_white']
189
+
190
+ # Product 3
191
+ # 6 +7) mime_type:jpeg;print_type:colour,sepia;size:large
192
+ # 8) mime_type:jpeg;print_type:colour
193
+ # 9) mime_type:PNG
194
+ # 9 + 10) mime_type:PDF|print_type:black_white
170
195
 
196
+
171
197
  end
172
198
 
173
199
 
metadata CHANGED
@@ -1,105 +1,110 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: datashift_spree
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
4
5
  prerelease:
5
- version: 0.4.1
6
6
  platform: ruby
7
- authors:
8
- - Thomas Statter
7
+ authors:
8
+ - Thomas Statter
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2013-01-02 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: datashift
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 0.12.0
24
- type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: mechanize
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
35
- type: :runtime
36
- version_requirements: *id002
37
- description: Comprehensive Excel/CSV import/export for Spree, Products,Images, any model with full associations
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: datashift
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.12.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.12.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: mechanize
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Comprehensive Excel/CSV import/export for Spree, Products,Images, any
47
+ model with full associations
38
48
  email: rubygems@autotelik.co.uk
39
49
  executables: []
40
-
41
50
  extensions: []
42
-
43
51
  extra_rdoc_files: []
44
-
45
- files:
46
- - datashift_spree.thor
47
- - README.markdown
48
- - datashift_spree.gemspec
49
- - VERSION
50
- - LICENSE.txt
51
- - lib/datashift_spree.rb
52
- - lib/datashift_spree_helper.rb
53
- - lib/helpers/spree_helper.rb
54
- - lib/loaders/spree/image_loader.rb
55
- - lib/loaders/spree/product_loader.rb
56
- - lib/loaders/spree/spree_base_loader.rb
57
- - lib/thor/spree/bootstrap_cleanup.thor
58
- - lib/thor/spree/products_images.thor
59
- - lib/thor/spree/reports.thor
60
- - spec/spec_helper.rb
61
- - spec/spree_exporter_spec.rb
62
- - spec/spree_generator_spec.rb
63
- - spec/spree_images_loader_spec.rb
64
- - spec/spree_loader_spec.rb
65
- - spec/spree_method_mapping_spec.rb
66
- - spec/spree_taxons_loader_spec.rb
67
- - spec/spree_variants_loader_spec.rb
68
- - spec/thor_spec.rb
52
+ files:
53
+ - datashift_spree.thor
54
+ - README.markdown
55
+ - datashift_spree.gemspec
56
+ - VERSION
57
+ - LICENSE.txt
58
+ - lib/datashift_spree.rb
59
+ - lib/loaders/spree/spree_base_loader.rb
60
+ - lib/loaders/spree/image_loader.rb
61
+ - lib/loaders/spree/product_loader.rb
62
+ - lib/thor/spree/products_images.thor
63
+ - lib/thor/spree/reports.thor
64
+ - lib/thor/spree/bootstrap_cleanup.thor
65
+ - lib/datashift_spree_helper.rb
66
+ - lib/helpers/spree_helper.rb
67
+ - spec/spree_generator_spec.rb
68
+ - spec/spree_loader_spec.rb
69
+ - spec/spree_variants_loader_spec.rb
70
+ - spec/thor_spec.rb
71
+ - spec/spree_images_loader_spec.rb
72
+ - spec/spree_exporter_spec.rb
73
+ - spec/spree_taxons_loader_spec.rb
74
+ - spec/spree_method_mapping_spec.rb
75
+ - spec/spec_helper.rb
69
76
  homepage: http://github.com/autotelik/datashift_spree
70
- licenses:
71
- - MIT
77
+ licenses:
78
+ - MIT
72
79
  post_install_message:
73
80
  rdoc_options: []
74
-
75
- require_paths:
76
- - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
78
84
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: "0"
83
- required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
90
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: "0"
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
89
95
  requirements: []
90
-
91
96
  rubyforge_project:
92
97
  rubygems_version: 1.8.24
93
98
  signing_key:
94
99
  specification_version: 3
95
100
  summary: Product and image import/export for Spree from Excel/CSV
96
- test_files:
97
- - spec/spec_helper.rb
98
- - spec/spree_exporter_spec.rb
99
- - spec/spree_generator_spec.rb
100
- - spec/spree_images_loader_spec.rb
101
- - spec/spree_loader_spec.rb
102
- - spec/spree_method_mapping_spec.rb
103
- - spec/spree_taxons_loader_spec.rb
104
- - spec/spree_variants_loader_spec.rb
105
- - spec/thor_spec.rb
101
+ test_files:
102
+ - spec/spree_generator_spec.rb
103
+ - spec/spree_loader_spec.rb
104
+ - spec/spree_variants_loader_spec.rb
105
+ - spec/thor_spec.rb
106
+ - spec/spree_images_loader_spec.rb
107
+ - spec/spree_exporter_spec.rb
108
+ - spec/spree_taxons_loader_spec.rb
109
+ - spec/spree_method_mapping_spec.rb
110
+ - spec/spec_helper.rb