spree_wholesale 0.40.2 → 0.40.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -8
- data/Rakefile +23 -95
- data/app/controllers/checkout_controller_decorator.rb +1 -1
- data/app/models/order_decorator.rb +0 -5
- data/app/models/products_helper_decorator.rb +3 -3
- data/app/models/spree_current_order_decorator.rb +33 -30
- data/app/models/user_decorator.rb +8 -0
- data/app/models/wholesaler.rb +1 -1
- data/lib/spree_wholesale.rb +21 -9
- data/lib/spree_wholesale/version.rb +3 -0
- data/{app/models/wholesaler_ability_decorator.rb → lib/spree_wholesale/wholesaler_ability.rb} +2 -2
- data/lib/spree_wholesale_hooks.rb +1 -3
- data/lib/tasks/install.rake +1 -1
- metadata +31 -31
- data/app/models/country_decorator.rb +0 -3
data/README.md
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
Spree Wholesale
|
2
|
-
|
2
|
+
===============
|
3
3
|
|
4
4
|
|
5
|
-
Currently still under development! Check back soon for more details..
|
6
|
-
|
7
5
|
To setup a fresh Spree store follow [these instructions](https://github.com/railsdog/spree/#readme).
|
8
6
|
|
9
7
|
|
@@ -18,8 +16,8 @@ Install from the source:
|
|
18
16
|
|
19
17
|
Or install the (beta) gem:
|
20
18
|
|
21
|
-
gem install spree_wholesale
|
22
|
-
echo "gem 'spree_wholesale', '0.40.2'" >> Gemfile
|
19
|
+
gem install spree_wholesale
|
20
|
+
echo "gem 'spree_wholesale', '0.40.2.1'" >> Gemfile
|
23
21
|
|
24
22
|
rake spree_wholesale:install
|
25
23
|
rake db:migrate
|
@@ -53,7 +51,7 @@ To create a demo of SpreeWholesaleExample
|
|
53
51
|
cd spree_wholesale_example
|
54
52
|
|
55
53
|
echo "gem 'spree', '0.40.2'" >> Gemfile
|
56
|
-
echo "gem 'spree_wholesale', '0.40.2'" >> Gemfile
|
54
|
+
echo "gem 'spree_wholesale', '0.40.2.1'" >> Gemfile
|
57
55
|
rm public/index.html
|
58
56
|
|
59
57
|
bundle install
|
@@ -67,7 +65,7 @@ To create a demo of SpreeWholesaleExample
|
|
67
65
|
|
68
66
|
or shorthand:
|
69
67
|
|
70
|
-
rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.2'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.2'" >> Gemfile; rm public/index.html
|
68
|
+
rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.2'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.2.1'" >> Gemfile; rm public/index.html
|
71
69
|
rake spree:install spree_wholesale:install db:migrate db:seed spree_wholesale:create_role
|
72
70
|
|
73
71
|
If you want sample data:
|
@@ -92,7 +90,7 @@ Then finish by booting up the rails server:
|
|
92
90
|
|
93
91
|
All in one swoop:
|
94
92
|
|
95
|
-
rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.2'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.2'" >> Gemfile; rm public/index.html; bundle install; rake spree:install spree_wholesale:install db:migrate db:seed spree_wholesale:create_role spree_sample:install db:sample spree_wholesale:assume_wholesale_prices; echo "@import url('wholesale.css');"|cat - public/stylesheets/screen.css > /tmp/out && mv /tmp/out public/stylesheets/screen.css; rails s
|
93
|
+
rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.2'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.2.1'" >> Gemfile; rm public/index.html; bundle install; rake spree:install spree_wholesale:install db:migrate db:seed spree_wholesale:create_role spree_sample:install db:sample spree_wholesale:assume_wholesale_prices; echo "@import url('wholesale.css');"|cat - public/stylesheets/screen.css > /tmp/out && mv /tmp/out public/stylesheets/screen.css; rails s
|
96
94
|
|
97
95
|
|
98
96
|
To do the same as above but install from the source instead, run:
|
data/Rakefile
CHANGED
@@ -1,102 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#require 'rubygems'
|
8
|
-
#require 'rake'
|
9
|
-
#require 'rake/testtask'
|
10
|
-
#require 'rake/packagetask'
|
11
|
-
#require 'rake/gempackagetask'
|
12
|
-
|
13
|
-
|
14
|
-
#spec = eval(File.read('spree_wholesale.gemspec'))
|
15
|
-
#Rake::GemPackageTask.new(spec) do |p|
|
16
|
-
# p.gem_spec = spec
|
17
|
-
#end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
namespace :spree_wholesale do
|
22
|
-
desc "Test Spree Wholesale Extension"
|
23
|
-
task :test do
|
24
|
-
|
25
|
-
root = ENV["RAILS_ROOT"] || File.expand_path('../spec/test_app', __FILE__)
|
26
|
-
env = File.join(root, 'config', 'environment.rb')
|
27
|
-
puts "(Rails Root: #{root})"
|
28
|
-
|
29
|
-
require env
|
30
|
-
require File.expand_path('../test/test_helper', __FILE__)
|
31
|
-
Dir["test/**/*.rb"].reject{|file| file.match(/test_helper/) != nil }.each do |file|
|
32
|
-
puts "Loading #{file}"
|
33
|
-
load file
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
37
7
|
end
|
38
8
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
require 'rake/testtask'
|
43
12
|
|
13
|
+
Bundler::GemHelper.install_tasks
|
44
14
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
files = `gem contents spree`.split("\n").select{|file| file.match("test_app_generator")}
|
53
|
-
if files.length == 1
|
54
|
-
require files.first
|
55
|
-
class WishlistTestAppGenerator < Spree::Generators::TestAppGenerator
|
56
|
-
def tweak_gemfile
|
57
|
-
append_file "Gemfile" ,
|
58
|
-
<<-gems
|
59
|
-
gem 'activemerchant'
|
60
|
-
gem 'spree_core', '>=0.40.0'
|
61
|
-
gem 'spree_auth', '>=0.40.0'
|
62
|
-
gem 'spree_wholesale', :path => "#{File.dirname(__FILE__)}"
|
63
|
-
gems
|
64
|
-
end
|
65
|
-
|
66
|
-
def install_spree_gems
|
67
|
-
|
68
|
-
puts "-----------------------------------------"
|
69
|
-
puts "Installing gems..."
|
70
|
-
`bundle install --gemfile=spec/test_app/Gemfile`
|
71
|
-
puts "-----------------------------------------"
|
72
|
-
|
73
|
-
inside "test_app" do
|
74
|
-
run 'rake spree_core:install'
|
75
|
-
run 'rake spree_auth:install'
|
76
|
-
run 'rake spree_wholesale:install'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def migrate_db
|
81
|
-
run_migrations
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
WishlistTestAppGenerator.start
|
86
|
-
|
87
|
-
puts "spec/test_app created. "
|
88
|
-
|
89
|
-
else
|
90
|
-
puts "Failed: Could not find lib/generators/spree/test_app_generator.rb"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
namespace :test_app do
|
95
|
-
desc 'Rebuild test database'
|
96
|
-
task :rebuild_db do
|
97
|
-
system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test")
|
98
|
-
end
|
15
|
+
Rake::TestTask.new(:test) do |t|
|
16
|
+
t.libs << 'lib'
|
17
|
+
t.libs << 'test'
|
18
|
+
t.pattern = 'test/**/*_test.rb'
|
19
|
+
t.verbose = false
|
99
20
|
end
|
100
21
|
|
22
|
+
task :default => :test
|
101
23
|
|
102
|
-
|
24
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
25
|
+
rdoc.rdoc_dir = 'rdoc'
|
26
|
+
rdoc.title = 'SpreeWholesale'
|
27
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
28
|
+
rdoc.rdoc_files.include('README.rdoc')
|
29
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
30
|
+
end
|
@@ -7,7 +7,7 @@ end
|
|
7
7
|
CheckoutController.class_eval do
|
8
8
|
|
9
9
|
def get_addresses
|
10
|
-
return unless current_user.
|
10
|
+
return unless current_user && current_user.wholesaler? && !current_user.wholesaler.nil?
|
11
11
|
@order.bill_address = current_user.wholesaler.bill_address
|
12
12
|
@order.ship_address = current_user.wholesaler.ship_address
|
13
13
|
end
|
@@ -34,8 +34,6 @@ Order.class_eval do
|
|
34
34
|
current_item = LineItem.new(:quantity => quantity)
|
35
35
|
current_item.variant = variant
|
36
36
|
current_item.price = is_wholesale? ? variant.wholesale_price : variant.price
|
37
|
-
|
38
|
-
|
39
37
|
self.line_items << current_item
|
40
38
|
end
|
41
39
|
|
@@ -55,7 +53,4 @@ Order.class_eval do
|
|
55
53
|
current_item
|
56
54
|
end
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
56
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
ProductsHelper.module_eval do
|
2
2
|
|
3
3
|
|
4
|
-
def wholesaler_signed_in?
|
5
|
-
|
6
|
-
end
|
4
|
+
#def wholesaler_signed_in?
|
5
|
+
# current_user && current_user.has_role?("wholesaler")
|
6
|
+
#end
|
7
7
|
|
8
8
|
|
9
9
|
# returns the price of the product to show for display purposes
|
@@ -1,35 +1,38 @@
|
|
1
|
-
|
2
|
-
module CurrentOrder
|
1
|
+
Spree::CurrentOrder.module_eval do
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@current_order.wholesale = current_user.has_role?("wholesaler")
|
10
|
-
end
|
11
|
-
end
|
3
|
+
# Associate the new order with the currently authenticated user before saving
|
4
|
+
def before_save_new_order
|
5
|
+
@current_order.user ||= current_user
|
6
|
+
@current_order.wholesale = current_user.wholesaler? if current_user
|
7
|
+
end
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
9
|
+
def after_save_new_order
|
10
|
+
# make sure the user has permission to access the order (if they are a guest)
|
11
|
+
return if current_user
|
12
|
+
session[:access_token] = @current_order.token
|
13
|
+
end
|
14
|
+
|
15
|
+
# The current incomplete order from the session for use in cart and during checkout
|
16
|
+
def current_order(create_order_if_necessary = false)
|
17
|
+
return @current_order if @current_order
|
18
|
+
@current_order ||= Order.find_by_id(session[:order_id], :include => :adjustments)
|
19
|
+
if create_order_if_necessary and (@current_order.nil? or @current_order.completed?)
|
20
|
+
@current_order = Order.new
|
21
|
+
before_save_new_order
|
22
|
+
@current_order.save!
|
23
|
+
after_save_new_order
|
24
|
+
end
|
25
|
+
|
26
|
+
if current_user && @current_order
|
27
|
+
if current_user.wholesaler? && !@current_order.is_wholesale?
|
28
|
+
@current_order.to_wholesale!
|
29
|
+
elsif !current_user.wholesaler? && @current_order.is_wholesale?
|
30
|
+
@current_order.to_fullsale!
|
28
31
|
end
|
29
|
-
|
30
|
-
session[:order_id] = @current_order ? @current_order.id : nil
|
31
|
-
|
32
|
-
@current_order
|
33
32
|
end
|
33
|
+
|
34
|
+
session[:order_id] = @current_order ? @current_order.id : nil
|
35
|
+
@current_order
|
34
36
|
end
|
35
|
-
|
37
|
+
|
38
|
+
end
|
data/app/models/wholesaler.rb
CHANGED
data/lib/spree_wholesale.rb
CHANGED
@@ -1,25 +1,37 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
1
|
+
if ENV["RAILS_ENV"] != "production"
|
2
|
+
require 'spree_core'
|
3
|
+
require 'spree_auth'
|
4
|
+
end
|
5
5
|
|
6
|
-
|
6
|
+
require 'spree_wholesale_hooks'
|
7
|
+
require 'spree_wholesale/wholesaler_controller'
|
7
8
|
|
9
|
+
|
10
|
+
module SpreeWholesale
|
8
11
|
class Engine < Rails::Engine
|
9
12
|
|
10
13
|
config.autoload_paths += %W(#{config.root}/lib)
|
11
14
|
|
12
15
|
initializer "static assets" do |app|
|
13
|
-
app.middleware.
|
16
|
+
app.middleware.insert_before ::Rack::Lock, ::ActionDispatch::Static, "#{config.root}/public"
|
14
17
|
end
|
15
18
|
|
19
|
+
def self._load(c)
|
20
|
+
Rails.env.production? ? require(c) : load(c)
|
21
|
+
end
|
16
22
|
|
17
23
|
def self.activate
|
18
|
-
|
19
|
-
|
24
|
+
|
25
|
+
if 40 <= Spree.version.split(".")[1].to_i
|
26
|
+
_load File.expand_path("../spree_wholesale/wholesaler_ability.rb", __FILE__)
|
27
|
+
end
|
28
|
+
|
29
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator.rb")) do |c|
|
30
|
+
_load(c)
|
20
31
|
end
|
21
32
|
end
|
22
33
|
|
23
34
|
config.to_prepare &method(:activate).to_proc
|
35
|
+
|
24
36
|
end
|
25
|
-
end
|
37
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
class SpreeWholesaleHooks < Spree::ThemeSupport::HookListener
|
2
|
-
# custom hooks go here
|
3
2
|
|
4
3
|
replace :admin_product_form_right, 'admin/hooks/product_form_right'
|
5
4
|
|
@@ -7,11 +6,10 @@ class SpreeWholesaleHooks < Spree::ThemeSupport::HookListener
|
|
7
6
|
replace :cart_item_total, 'hooks/cart_item_total'
|
8
7
|
|
9
8
|
insert_before :inside_cart_form, 'hooks/wholesale_customer_id'
|
10
|
-
|
9
|
+
|
11
10
|
insert_after :admin_orders_index_headers, 'admin/hooks/admin_orders_index_headers'
|
12
11
|
insert_after :admin_orders_index_rows, 'admin/hooks/admin_orders_index_rows'
|
13
12
|
insert_after :admin_orders_index_search, 'admin/hooks/admin_orders_index_search'
|
14
|
-
|
15
13
|
insert_after :admin_tabs, 'admin/hooks/wholesale_tab'
|
16
14
|
|
17
15
|
end
|
data/lib/tasks/install.rake
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
namespace :spree_wholesale do
|
2
2
|
|
3
|
-
desc "Copies all migrations
|
3
|
+
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
|
4
4
|
task :install do
|
5
5
|
Rake::Task['spree_wholesale:install:migrations'].invoke
|
6
6
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_wholesale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 40
|
8
|
-
- 2
|
9
|
-
version: 0.40.2
|
4
|
+
prerelease:
|
5
|
+
version: 0.40.2.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Spencer Steffen
|
@@ -14,41 +10,45 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-02-07 00:00:00 -08:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
21
17
|
name: spree_core
|
22
|
-
prerelease: false
|
23
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
19
|
none: false
|
25
20
|
requirements:
|
26
21
|
- - ">="
|
27
22
|
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
- 40
|
31
|
-
- 2
|
32
|
-
version: 0.40.2
|
23
|
+
version: 0.30.1
|
33
24
|
type: :runtime
|
25
|
+
prerelease: false
|
34
26
|
version_requirements: *id001
|
35
27
|
- !ruby/object:Gem::Dependency
|
36
28
|
name: spree_auth
|
37
|
-
prerelease: false
|
38
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
30
|
none: false
|
40
31
|
requirements:
|
41
32
|
- - ">="
|
42
33
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
- 0
|
45
|
-
- 40
|
46
|
-
- 2
|
47
|
-
version: 0.40.2
|
34
|
+
version: 0.30.1
|
48
35
|
type: :runtime
|
36
|
+
prerelease: false
|
49
37
|
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: shoulda
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.11.3
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
50
49
|
description: Spree Wholesale adds a wholesale_price field to variants and allows users with a "wholesaler" role to access these prices.
|
51
|
-
email:
|
50
|
+
email:
|
51
|
+
- spencer@citrusme.com
|
52
52
|
executables: []
|
53
53
|
|
54
54
|
extensions: []
|
@@ -60,6 +60,8 @@ files:
|
|
60
60
|
- LICENSE
|
61
61
|
- config/locales/en.yml
|
62
62
|
- config/routes.rb
|
63
|
+
- lib/spree_wholesale/version.rb
|
64
|
+
- lib/spree_wholesale/wholesaler_ability.rb
|
63
65
|
- lib/spree_wholesale/wholesaler_controller.rb
|
64
66
|
- lib/spree_wholesale.rb
|
65
67
|
- lib/spree_wholesale_hooks.rb
|
@@ -71,7 +73,6 @@ files:
|
|
71
73
|
- app/controllers/checkout_controller_decorator.rb
|
72
74
|
- app/controllers/wholesalers_controller.rb
|
73
75
|
- app/models/application_helper_decorator.rb
|
74
|
-
- app/models/country_decorator.rb
|
75
76
|
- app/models/line_item_decorator.rb
|
76
77
|
- app/models/order_decorator.rb
|
77
78
|
- app/models/product_decorator.rb
|
@@ -80,7 +81,6 @@ files:
|
|
80
81
|
- app/models/user_decorator.rb
|
81
82
|
- app/models/variant_decorator.rb
|
82
83
|
- app/models/wholesaler.rb
|
83
|
-
- app/models/wholesaler_ability_decorator.rb
|
84
84
|
- app/views/admin/hooks/_admin_orders_index_headers.html.erb
|
85
85
|
- app/views/admin/hooks/_admin_orders_index_rows.html.erb
|
86
86
|
- app/views/admin/hooks/_admin_orders_index_search.html.erb
|
@@ -109,7 +109,7 @@ files:
|
|
109
109
|
- public/stylesheets/admin/wholesalers.css
|
110
110
|
- public/stylesheets/wholesale.css
|
111
111
|
- Rakefile
|
112
|
-
has_rdoc:
|
112
|
+
has_rdoc: true
|
113
113
|
homepage: http://github.com/citrus/spree_wholesale
|
114
114
|
licenses: []
|
115
115
|
|
@@ -123,25 +123,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
123
|
requirements:
|
124
124
|
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
+
hash: 4546681846651218626
|
126
127
|
segments:
|
127
|
-
-
|
128
|
-
|
129
|
-
- 7
|
130
|
-
version: 1.8.7
|
128
|
+
- 0
|
129
|
+
version: "0"
|
131
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
131
|
none: false
|
133
132
|
requirements:
|
134
133
|
- - ">="
|
135
134
|
- !ruby/object:Gem::Version
|
135
|
+
hash: 4546681846651218626
|
136
136
|
segments:
|
137
137
|
- 0
|
138
138
|
version: "0"
|
139
|
-
requirements:
|
140
|
-
|
139
|
+
requirements: []
|
140
|
+
|
141
141
|
rubyforge_project:
|
142
|
-
rubygems_version: 1.
|
142
|
+
rubygems_version: 1.5.0
|
143
143
|
signing_key:
|
144
144
|
specification_version: 3
|
145
|
-
summary:
|
145
|
+
summary: Wholesale accounts for Spree Commerce.
|
146
146
|
test_files: []
|
147
147
|
|