spree_wholesale 0.40.0.beta4.1 → 0.40.0.beta4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/README.md +4 -4
  2. data/Rakefile +81 -17
  3. data/app/controllers/admin/base_controller_decorator.rb +11 -0
  4. data/app/controllers/admin/wholesalers_controller.rb +70 -0
  5. data/app/controllers/checkout_controller_decorator.rb +15 -0
  6. data/app/controllers/wholesalers_controller.rb +5 -0
  7. data/app/models/ability.rb +71 -0
  8. data/app/models/{application_controller_decorator.rb → application_helper_decorator.rb} +1 -2
  9. data/app/models/country_decorator.rb +3 -0
  10. data/app/models/order_decorator.rb +0 -2
  11. data/app/models/spree_current_order_decorator.rb +0 -13
  12. data/app/models/user_decorator.rb +5 -0
  13. data/app/models/wholesaler.rb +45 -0
  14. data/app/views/admin/hooks/_wholesale_tab.html.erb +1 -0
  15. data/app/views/admin/wholesalers/_form.html.erb +129 -0
  16. data/app/views/admin/wholesalers/_user_options.html.erb +6 -0
  17. data/app/views/admin/wholesalers/edit.html.erb +13 -0
  18. data/app/views/admin/wholesalers/index.html.erb +88 -0
  19. data/app/views/admin/wholesalers/new.html.erb +13 -0
  20. data/app/views/admin/wholesalers/show.html.erb +68 -0
  21. data/app/views/hooks/_wholesale_static_content.html.erb +3 -0
  22. data/app/views/shared/_address_form.html.erb +77 -0
  23. data/app/views/shared/_store_menu.html.erb +4 -0
  24. data/app/views/wholesalers/_fields.html.erb +91 -0
  25. data/app/views/wholesalers/index.html.erb +21 -0
  26. data/app/views/wholesalers/new.html.erb +8 -0
  27. data/config/locales/en.yml +45 -1
  28. data/config/routes.rb +11 -0
  29. data/db/migrate/install_spree_wholesale.rb +36 -0
  30. data/lib/spree_wholesale/wholesaler_controller.rb +122 -0
  31. data/lib/spree_wholesale_hooks.rb +4 -0
  32. data/lib/tasks/install.rake +0 -14
  33. data/lib/tasks/spree_wholesale.rake +11 -2
  34. data/public/stylesheets/admin/wholesalers.css +14 -0
  35. metadata +28 -6
  36. data/db/migrate/add_wholesale_price_to_variants.rb +0 -9
  37. data/db/migrate/add_wholesale_to_orders.rb +0 -9
@@ -1,3 +1,14 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
+ resources :wholesalers
4
+
5
+ namespace(:admin) do
6
+ resources :wholesalers do
7
+ member do
8
+ get :approve
9
+ get :reject
10
+ end
11
+ end
12
+ end
13
+
3
14
  end
@@ -0,0 +1,36 @@
1
+ class InstallSpreeWholesale < ActiveRecord::Migration
2
+
3
+ def self.up
4
+
5
+ create_table :wholesalers do |t|
6
+ t.references :user
7
+ t.integer :billing_address_id
8
+ t.integer :shipping_address_id
9
+ t.string :company
10
+ t.string :buyer_contact
11
+ t.string :manager_contact
12
+ t.string :phone
13
+ t.string :fax
14
+ t.string :resale_number
15
+ t.string :taxid
16
+ t.string :web_address
17
+ t.string :terms
18
+ t.string :alternate_email
19
+ t.text :notes
20
+ end
21
+
22
+ add_index :wholesalers, [:billing_address_id, :shipping_address_id]
23
+
24
+ add_column :orders, :wholesale, :boolean, :default => false
25
+ add_column :variants, :wholesale_price, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0
26
+
27
+ end
28
+
29
+ def self.down
30
+ remove_column :variants, :wholesale_price
31
+ remove_column :orders, :wholesale
32
+
33
+ drop_table :wholesalers
34
+ end
35
+
36
+ end
@@ -0,0 +1,122 @@
1
+ module SpreeWholesale
2
+ module WholesalerController
3
+
4
+
5
+ def self.included(mod)
6
+ mod.instance_eval do
7
+ resource_controller
8
+ before_filter :use_billing?, :only => [ :create, :update ]
9
+ before_filter :setup_defaults, :only => [:new,:create,:edit,:update]
10
+
11
+ index.before :new_wholesale_user
12
+
13
+ helper_method :wholesale_role
14
+
15
+ end
16
+ mod.send(:include, ClassMethods)
17
+ end
18
+
19
+ module ClassMethods
20
+
21
+ #=================================================
22
+ # Overwrite point
23
+
24
+ def after_wholesaler_create
25
+ flash[:notice] = "Thank you for your interest in becoming a wholesaler! We'll be in touch shortly."
26
+ redirect_to wholesalers_path
27
+ end
28
+
29
+ def after_wholesaler_failed_create
30
+ flash[:error] = "Wholesale account could not be created!"
31
+ render :action => :new
32
+ end
33
+
34
+ #=================================================
35
+
36
+ def wholesale_role
37
+ @wholesale_role ||= Role.find_or_create_by_name("wholesaler")
38
+ end
39
+
40
+ def new_wholesale_user
41
+ @user = User.new
42
+ end
43
+
44
+ def validate_wholesaler_parts
45
+ uv = @user.valid?
46
+ bv = @bill_address.valid?
47
+ sv = @ship_address.valid?
48
+ valid = uv && bv && sv
49
+ if valid
50
+ @wholesaler.user = @user if @user.save
51
+ @wholesaler.bill_address = @bill_address if @bill_address.save
52
+ @wholesaler.ship_address = @ship_address if @ship_address.save
53
+ end
54
+ @wholesaler.valid? && valid
55
+ end
56
+
57
+ def create
58
+ if validate_wholesaler_parts && @wholesaler.valid? && @wholesaler.save
59
+ return after_wholesaler_create
60
+ else
61
+ return after_wholesaler_failed_create
62
+ end
63
+ end
64
+
65
+ def update
66
+ validate_wholesaler_parts
67
+ @wholesaler.save
68
+ super
69
+ end
70
+
71
+
72
+
73
+ def use_billing?
74
+ @use_billing ||= params[:wholesaler].delete(:use_billing).to_i == 1
75
+ end
76
+
77
+ def setup_defaults
78
+
79
+ params[:wholesaler] ||= {}
80
+
81
+ if request.get? && params[:dev]
82
+ params[:wholesaler] = {"company"=>"Test Company", "buyer_contact"=>"Mr Contacter", "manager_contact"=>"Mr Manager", "phone"=>"555-555-5555", "fax"=>"555-555-5555 ext 1", "resale_number"=>"13414214", "taxid"=>"555-55-5555", "web_address"=>"testcompany.com", "terms"=>"Credit Card", "notes"=>""}
83
+ params[:user] = {"email"=>"wholesale-#{rand(100)}@example.com", :password => "password" , :password_confirmation => "password" }
84
+ params[:bill_address] = {"firstname"=>"Mister","lastname"=>"Accountant","address1"=>"123 Anystreet", "address2"=>"", "city"=>"Anytown", "state_id"=>"276110813", "zipcode"=>"98765", "country_id"=>"214", "phone"=>"555-555-5555"}
85
+ end
86
+
87
+ @roles = Role.all
88
+
89
+ case params[:action]
90
+ when 'new', 'create'
91
+ @wholesaler = Wholesaler.new(params[:wholesaler])
92
+ @user = User.new(params[:user])
93
+ @bill_address = Address.new((params[:bill_address] || {}).merge(:country => default_country))
94
+
95
+ if use_billing?
96
+ @ship_address = @bill_address
97
+ else
98
+ @ship_address = Address.new((params[:ship_address] || {}).merge(:country => default_country))
99
+ end
100
+
101
+ when 'edit', 'update', 'destroy'
102
+ @wholesaler = Wholesaler.find(params[:id])
103
+ @user = @wholesaler.user
104
+ @bill_address = @wholesaler.bill_address
105
+ @ship_address = @wholesaler.ship_address
106
+ end
107
+
108
+ if params[:action] == 'update'
109
+ if !use_billing? && @bill_address.id == @ship_address.id
110
+ @ship_address = Address.new((params[:ship_address] || {}).merge(:country => default_country))
111
+ elsif use_billing? && @bill_address.id != @ship_address.id
112
+ @wholesaler.ship_address.destroy
113
+ @ship_address = @bill_address
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ end
120
+
121
+ end
122
+ end
@@ -12,4 +12,8 @@ class SpreeWholesaleHooks < Spree::ThemeSupport::HookListener
12
12
  insert_after :admin_orders_index_rows, 'admin/hooks/admin_orders_index_rows'
13
13
  insert_after :admin_orders_index_search, 'admin/hooks/admin_orders_index_search'
14
14
 
15
+ insert_after :admin_tabs, 'admin/hooks/wholesale_tab'
16
+
17
+
18
+
15
19
  end
@@ -1,14 +1,8 @@
1
1
  namespace :spree_wholesale do
2
2
 
3
- def load_environment
4
- puts "loading environment..."
5
- require File.join(Rails.root, 'config', 'environment')
6
- end
7
-
8
3
  desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
9
4
  task :install do
10
5
  Rake::Task['spree_wholesale:install:migrations'].invoke
11
- Rake::Task['spree_wholesale:install:assets'].invoke
12
6
  end
13
7
 
14
8
  namespace :install do
@@ -37,14 +31,6 @@ namespace :spree_wholesale do
37
31
  end
38
32
  end
39
33
  end
40
-
41
- desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
42
- task :assets do
43
- source = File.join(File.dirname(__FILE__), '..', '..', 'public')
44
- destination = File.join(Rails.root, 'public')
45
- puts "INFO: Mirroring assets from #{source} to #{destination}"
46
- Spree::FileUtilz.mirror_files(source, destination)
47
- end
48
34
  end
49
35
 
50
36
  end
@@ -1,5 +1,10 @@
1
1
  namespace :spree_wholesale do
2
2
 
3
+ def load_environment
4
+ puts "Loading environment..."
5
+ require File.join(Rails.root, 'config', 'environment')
6
+ end
7
+
3
8
  desc "Creates wholesale role"
4
9
  task :create_role do
5
10
 
@@ -26,10 +31,14 @@ namespace :spree_wholesale do
26
31
  load_environment
27
32
 
28
33
  Variant.all.each do |variant|
29
- variant.wholesale_price = variant.price * 0.66
30
- variant.save
34
+ price = variant.price * 0.66
35
+ ActiveRecord::Base.connection.execute("UPDATE variants SET wholesale_price = #{price} WHERE id = #{variant.id}")
31
36
  end
32
37
 
33
38
  end
39
+
40
+
41
+
42
+
34
43
 
35
44
  end
@@ -0,0 +1,14 @@
1
+ input.required, select.required {
2
+ color: #222;
3
+ }
4
+
5
+ .leftie, .rightie {
6
+ display: block;
7
+ width: 49%;
8
+ }
9
+ .leftie {
10
+ float: left;
11
+ }
12
+ .rightie {
13
+ float: right;
14
+ }
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 40
8
8
  - 0
9
9
  - beta4
10
- - 1
11
- version: 0.40.0.beta4.1
10
+ - 2
11
+ version: 0.40.0.beta4.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Spencer Steffen
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-01-12 00:00:00 -08:00
19
+ date: 2011-01-14 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -62,32 +62,54 @@ files:
62
62
  - LICENSE
63
63
  - config/locales/en.yml
64
64
  - config/routes.rb
65
+ - lib/spree_wholesale/wholesaler_controller.rb
65
66
  - lib/spree_wholesale.rb
66
67
  - lib/spree_wholesale_hooks.rb
67
68
  - lib/tasks/install.rake
68
69
  - lib/tasks/spree_wholesale.rake
69
70
  - lib/wholesale_products_helper.rb
71
+ - app/controllers/admin/base_controller_decorator.rb
70
72
  - app/controllers/admin/orders_controller_decorator.rb
71
- - app/models/application_controller_decorator.rb
73
+ - app/controllers/admin/wholesalers_controller.rb
74
+ - app/controllers/checkout_controller_decorator.rb
75
+ - app/controllers/wholesalers_controller.rb
76
+ - app/models/ability.rb
77
+ - app/models/application_helper_decorator.rb
78
+ - app/models/country_decorator.rb
72
79
  - app/models/line_item_decorator.rb
73
80
  - app/models/order_decorator.rb
74
81
  - app/models/product_decorator.rb
75
82
  - app/models/products_helper_decorator.rb
76
83
  - app/models/spree_current_order_decorator.rb
84
+ - app/models/user_decorator.rb
77
85
  - app/models/variant_decorator.rb
86
+ - app/models/wholesaler.rb
78
87
  - app/views/admin/hooks/_admin_orders_index_headers.html.erb
79
88
  - app/views/admin/hooks/_admin_orders_index_rows.html.erb
80
89
  - app/views/admin/hooks/_admin_orders_index_search.html.erb
81
90
  - app/views/admin/hooks/_product_form_right.html.erb
91
+ - app/views/admin/hooks/_wholesale_tab.html.erb
82
92
  - app/views/admin/variants/_form.html.erb
93
+ - app/views/admin/wholesalers/_form.html.erb
94
+ - app/views/admin/wholesalers/_user_options.html.erb
95
+ - app/views/admin/wholesalers/edit.html.erb
96
+ - app/views/admin/wholesalers/index.html.erb
97
+ - app/views/admin/wholesalers/new.html.erb
98
+ - app/views/admin/wholesalers/show.html.erb
83
99
  - app/views/checkout/_summary.html.erb
84
100
  - app/views/hooks/_cart_item_price.html.erb
85
101
  - app/views/hooks/_cart_item_total.html.erb
86
102
  - app/views/hooks/_wholesale_customer_id.html.erb
103
+ - app/views/hooks/_wholesale_static_content.html.erb
87
104
  - app/views/orders/show.html.erb
105
+ - app/views/shared/_address_form.html.erb
88
106
  - app/views/shared/_products.html.erb
89
- - db/migrate/add_wholesale_price_to_variants.rb
90
- - db/migrate/add_wholesale_to_orders.rb
107
+ - app/views/shared/_store_menu.html.erb
108
+ - app/views/wholesalers/_fields.html.erb
109
+ - app/views/wholesalers/index.html.erb
110
+ - app/views/wholesalers/new.html.erb
111
+ - db/migrate/install_spree_wholesale.rb
112
+ - public/stylesheets/admin/wholesalers.css
91
113
  - public/stylesheets/wholesale.css
92
114
  - Rakefile
93
115
  has_rdoc: false
@@ -1,9 +0,0 @@
1
- class AddWholesalePriceToVariants < ActiveRecord::Migration
2
- def self.up
3
- add_column :variants, :wholesale_price, :decimal, :precision => 8, :scale => 2, :null => false, :default => 0.0
4
- end
5
-
6
- def self.down
7
- remove_column :variants, :wholesale_price
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class AddWholesaleToOrders < ActiveRecord::Migration
2
- def self.up
3
- add_column :orders, :wholesale, :boolean, :default => false
4
- end
5
-
6
- def self.down
7
- remove_column :orders, :wholesale
8
- end
9
- end