datashift_spree 0.4.2 → 0.5.0

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.2
1
+ 0.5.0
@@ -9,7 +9,7 @@
9
9
  #
10
10
  module Datashift
11
11
 
12
- class Spree < Thor
12
+ class SpreeTasks < Thor
13
13
 
14
14
  desc 'build', 'Build gem '
15
15
 
@@ -23,8 +23,7 @@
23
23
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
24
  #++
25
25
 
26
-
27
- # Details:: Active Record Loader
26
+ # Details:: Spree Product and Image Loader from .xls or CSV
28
27
  #
29
28
  # To pull DataShift commands into your main Spree application :
30
29
  #
@@ -16,9 +16,9 @@ require 'datashift_spree'
16
16
 
17
17
  require 'spree_helper'
18
18
 
19
- module Datashift
20
-
21
- class Spree < Thor
19
+ module DatashiftSpree
20
+
21
+ class Load < Thor
22
22
 
23
23
  include DataShift::Logging
24
24
 
@@ -157,5 +157,4 @@ module Datashift
157
157
  end
158
158
 
159
159
  end
160
-
161
160
  end
@@ -11,9 +11,9 @@
11
11
 
12
12
  require 'excel_exporter'
13
13
 
14
- module Datashift
14
+ module DatashiftSpree
15
15
 
16
- class Spreereports < Thor
16
+ class Reports < Thor
17
17
 
18
18
  include DataShift::Logging
19
19
 
@@ -9,9 +9,9 @@
9
9
  #
10
10
  # Note, not DataShift, case sensitive, create namespace for command line : datashift
11
11
 
12
- module Datashift
12
+ module DatashiftSpree
13
13
 
14
- class Spreeboot < Thor
14
+ class Utils < Thor
15
15
 
16
16
  include DataShift::Logging
17
17
 
@@ -26,9 +26,10 @@ module Datashift
26
26
  require File.expand_path('config/environment.rb')
27
27
 
28
28
  ActiveRecord::Base.connection.execute("TRUNCATE spree_products_taxons")
29
+ ActiveRecord::Base.connection.execute("TRUNCATE spree_products_promotion_rules")
29
30
 
30
31
  cleanup = %w{ Image OptionType OptionValue
31
- Product Property ProductGroup ProductProperty ProductOptionType
32
+ Product Property ProductProperty ProductOptionType
32
33
  Variant Taxonomy Taxon
33
34
  }
34
35
 
@@ -0,0 +1,290 @@
1
+ # Copyright:: (c) Autotelik Media Ltd 201=3
2
+ # Author :: Tom Statter
3
+ # Date :: Jan 2013
4
+ # License:: MIT. Free, Open Source.
5
+ #
6
+ # Details:: Helper tasks for setting up Royal Mail UK Shipping in Spree
7
+ #
8
+ # Must be run from your Rails.root path
9
+ #
10
+ # => N.B Before using set your required Rates(prices) in @cat_rates_matrix
11
+
12
+ require 'thor'
13
+
14
+
15
+ module DatashiftSpree
16
+
17
+ module DataBank
18
+
19
+ class UkShipping < Thor
20
+
21
+ require File.expand_path('config/environment.rb')
22
+
23
+ #############################
24
+ # Zone Setup for Royal Mail
25
+ # http://www.royalmail.com
26
+ #############################
27
+ usage =<<-EOS
28
+ Setup Royal Mail Zones, Shipping Categories and Methods
29
+
30
+ Available Calculators are:
31
+ \t#{Spree::ShippingMethod.calculators.sort_by(&:name).join("\n\t")}
32
+
33
+ EOS
34
+
35
+ desc "royal_mail", usage
36
+
37
+ method_option :commit, :aliases => '-c', :type => :boolean, :required => false, :desc => "Commit changes permanently"
38
+ method_option :calc, :required => false, :default => 'Spree::Calculator::FlatRate', :desc => "Calculators"
39
+
40
+ def royal_mail
41
+
42
+ # Royal Mail is the ShippingMethod (actual service used to send the product) with 3 applicable Zones.
43
+ #
44
+ # [UK 1st, EU, INT]
45
+ #
46
+ # Matrix of Rates for with your required Category(s)
47
+ # Generally products are classified by ShippingCategory, with each Product assigned to a single Category
48
+ #
49
+ # For example each Product would be in either one of the Categories, Light or Heavy
50
+ # @cat_rates_matrix = {
51
+ # 'Light' => [3.73, 4.23, 5.95],
52
+ # 'Heavy' => [5.00, 6.00, 10.00]
53
+ # }
54
+
55
+ @cat_rates_matrix = {
56
+ 'FlatPerOrder' => [10.00, 12.00, 15.00]
57
+ }
58
+
59
+ raise "Please set the Rates for each Categoryt in the task" if(@cat_rates_matrix.nil? || @cat_rates_matrix.empty?)
60
+
61
+ Spree::Zone.transaction do
62
+
63
+ # FIRST CREATE 3 RM ZONES
64
+
65
+ zone_map = {
66
+ 'UK' => 'United Kingdom (GB)',
67
+ 'Europe' => 'Countries within the European economic area',
68
+ 'International' => 'Rest of World',
69
+ }
70
+
71
+ zone_names = zone_map.keys
72
+
73
+ zone_map.each do |n, d|
74
+ Spree::Zone.create( :name => n, :description => d )
75
+ puts "Zone #{n} created"
76
+ end
77
+
78
+ # NOW POPULATE ZONE MEMBERS
79
+
80
+ current_zone = Spree::Zone.find_by_name( 'UK' )
81
+ country = Spree::Country.find_by_name( 'United Kingdom' )
82
+
83
+ raise "No UK Zone/Country Found" unless current_zone && country
84
+
85
+ # Seed on :zoneable_id since in this case we know each country in a distinct zone
86
+ zoneable_type = 'Spree::Country'
87
+
88
+ Spree::ZoneMember.create( :zone => current_zone, :zoneable_type => zoneable_type, :zoneable_id => country.id)
89
+
90
+ ## 2 N.B This is for shipping FROM UK so UK NOT in Europe ZONE
91
+ current_zone = Spree::Zone.find_by_name( 'Europe' )
92
+
93
+ europe_list = %w{Albania Andorra Armenia Austria Azerbaijan Azores
94
+ Balearic\ Islands
95
+ Belarus Belgium
96
+ Bosnia\ and\ Herzegovina
97
+ Bulgaria
98
+ Canary\ Islands
99
+ Corsica Croatia Cyprus
100
+ Czech\ Republic
101
+ Denmark Estonia
102
+ Faroe\ Islands
103
+ Finland France Georgia Germany Gibraltar Greece Greenland Hungary Iceland
104
+ Ireland
105
+ Italy Kazakhstan Kosovo Kyrgyzstan Latvia Liechtenstein Lithuania Luxembourg
106
+ Macedonia Madeira Malta
107
+ Moldova,\ Republic\ of
108
+ Monaco Montenegro Netherlands Norway
109
+ Poland Portugal Romania
110
+ Russian\ Federation
111
+ San\ Marino
112
+ Serbia Slovakia Slovenia Spain Sweden Switzerland Tajikistan Turkey Turkmenistan
113
+ Ukraine Uzbekistan
114
+ Vatican\ City\ State
115
+ }
116
+
117
+ europe_list.each do |c|
118
+
119
+ country = Spree::Country.find_by_name( c )
120
+
121
+ unless country
122
+ puts "WARNING: Country #{c} not found in DB"
123
+ puts "If you require this Country #{c} you will have to add MANUALLY with ISO"
124
+ next
125
+ end
126
+
127
+ Spree::ZoneMember.create!( :zone => current_zone, :zoneable_type => zoneable_type, :zoneable_id => country.id)
128
+ end
129
+
130
+ puts "European countries added to Europe Zone"
131
+
132
+ current_zone = Spree::Zone.find_by_name( 'International' )
133
+
134
+ raise "No International Zone Found" unless current_zone
135
+
136
+ Spree::Country.all.each do |country|
137
+
138
+ next if( country.name == 'United Kingdom' || europe_list.include?( country.name ) )
139
+
140
+ Spree::ZoneMember.create!( :zone => current_zone, :zoneable_type => zoneable_type, :zoneable_id => country.id)
141
+ end
142
+
143
+ puts "Countries added to International Zone"
144
+
145
+ # In this example we are working with 1 deliverer, 3 Zones => 3 Shipping Methods
146
+
147
+ # And we have a single product classification => 1 Shipping Categories:
148
+
149
+ #######################
150
+ # SHIPPING CATEGORIES #
151
+ #######################
152
+
153
+ #first create the categories
154
+ @cat_rates_matrix.each do |cat, rates|
155
+
156
+ current_shipping_category = Spree::ShippingCategory.create!(:name => cat)
157
+
158
+ puts "Spree::ShippingCategory #{cat} created"
159
+
160
+ # Now associate Shipping with Zones
161
+ @shipping_methods = []
162
+ {
163
+ 'Royal Mail UK 1st' => zone_names[0],
164
+ 'Royal Mail Europe' => zone_names[1],
165
+ 'Royal Mail International' => zone_names[2]
166
+
167
+ }.each do |name, zone|
168
+
169
+ ship_method_attributes = {
170
+ :name => name,
171
+ :zone => Spree::Zone.find_by_name(zone),
172
+ :shipping_category => current_shipping_category,
173
+ :calculator_type => options[:calc]
174
+ }
175
+
176
+ @shipping_methods << Spree::ShippingMethod.create!( ship_method_attributes, :without_protection => true )
177
+
178
+ puts "Spree::Shipping Method #{name} created with Cal #{options[:calc]} in Zone #{zone}"
179
+ end
180
+
181
+ # Now set the Rates (
182
+ unless(@shipping_methods.size == rates.size)
183
+ puts "WARNING: Sorry could not set Rates check @cat_rates_matrix set correctly in script"
184
+ else
185
+ puts "Setting Rates on the Shipping Methods"
186
+ @shipping_methods.each_with_index do |m, i|
187
+ m.calculator.preferred_amount= rates[i];
188
+ m.save!
189
+ end
190
+ end
191
+ end
192
+
193
+ unless options[:commit] == true
194
+ puts "Dummy run - rolling back changes - run with --commit to make changes permenant"
195
+ raise ActiveRecord::Rollback
196
+ end
197
+ end
198
+ end
199
+
200
+ desc "counties", "Setup UK Counties (Spree::State)"
201
+
202
+ method_option :commit, :aliases => '-c', :type => :boolean, :required => false, :desc => "Commit changes permanently"
203
+
204
+ def counties
205
+
206
+ names, abbrs = [],[]
207
+
208
+ names << 'Avon'
209
+ names << 'Bedfordshire'
210
+ names << 'Berkshire'
211
+ names << 'Borders'
212
+ names << 'Buckinghamshire'
213
+ names << 'Cambridgeshire'
214
+ names << 'Central'
215
+ names << 'Cheshire'
216
+ names << 'Cleveland'
217
+ names << 'Clwyd'
218
+ names << 'Cornwall'
219
+ names << 'County Antrim'
220
+ names << 'County Armagh'
221
+ names << 'County Down'
222
+ names << 'County Fermanagh'
223
+ names << 'County Londonderry'
224
+ names << 'County Tyrone'
225
+ names << 'Cumbria'
226
+ names << 'Derbyshire'
227
+ names << 'Devon'
228
+ names << 'Dorset'
229
+ names << 'Dumfries and Galloway'
230
+ names << 'Durham'
231
+ names << 'Dyfed'
232
+ names << 'East Sussex'
233
+ names << 'Essex'
234
+ names << 'Fife'
235
+ names << 'Gloucestershire'
236
+ names << 'Grampian'
237
+ names << 'Greater Manchester'
238
+ names << 'Gwent'
239
+ names << 'Gwynedd County'
240
+ names << 'Hampshire'
241
+ names << 'Herefordshire'
242
+ names << 'Hertfordshire'
243
+ names << 'Highlands and Islands'
244
+ names << 'Humberside'
245
+ names << 'Isle of Wight'
246
+ names << 'Kent'
247
+ names << 'Lancashire'
248
+ names << 'Leicestershire'
249
+ names << 'Lincolnshire'
250
+ names << 'London'
251
+ names << 'Lothian'
252
+ names << 'Merseyside'
253
+ names << 'Mid Glamorgan'
254
+ names << 'Norfolk'
255
+ names << 'North Yorkshire'
256
+ names << 'Northamptonshire'
257
+ names << 'Northumberland'
258
+ names << 'Nottinghamshire'
259
+ names << 'Oxfordshire'
260
+ names << 'Powys'
261
+ names << 'Rutland'
262
+ names << 'Shropshire'
263
+ names << 'Somerset'
264
+ names << 'South Glamorgan'
265
+ names << 'South Yorkshire'
266
+ names << 'Staffordshire'
267
+ names << 'Strathclyde'
268
+ names << 'Suffolk'
269
+ names << 'Surrey'
270
+ names << 'Tayside'
271
+ names << 'Tyne and Wear'
272
+ names << 'Warwickshire'
273
+ names << 'West Glamorgan'
274
+ names << 'West Midlands'
275
+ names << 'West Sussex'
276
+ names << 'West Yorkshire'
277
+ names << 'Wiltshire'
278
+ names << 'Worcestershire'
279
+
280
+ uk = Spree::Country.find_by_name( 'United Kingdom' )
281
+
282
+ names.each do |n|
283
+ Spree::State.create( :name => n, :country_id => uk.id)
284
+ end
285
+ end
286
+
287
+ end
288
+ end # class
289
+
290
+ end # module
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datashift_spree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-03 00:00:00.000000000 Z
12
+ date: 2013-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: datashift
@@ -61,7 +61,8 @@ files:
61
61
  - lib/loaders/spree/product_loader.rb
62
62
  - lib/thor/spree/products_images.thor
63
63
  - lib/thor/spree/reports.thor
64
- - lib/thor/spree/bootstrap_cleanup.thor
64
+ - lib/thor/spree/utils.thor
65
+ - lib/thor/spree_databank/uk_shipping.thor
65
66
  - lib/datashift_spree_helper.rb
66
67
  - lib/helpers/spree_helper.rb
67
68
  - spec/spree_generator_spec.rb