spree_wholesale 0.40.0.beta4.2 → 0.40.2.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -7
- data/Rakefile +45 -50
- data/app/models/wholesaler_ability_decorator.rb +17 -0
- data/app/views/wholesalers/_fields.html.erb +2 -4
- data/lib/spree_wholesale_hooks.rb +0 -2
- metadata +8 -10
- data/app/models/ability.rb +0 -71
- data/lib/wholesale_products_helper.rb +0 -26
data/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Install from the source:
|
|
|
19
19
|
Or install the (beta) gem:
|
|
20
20
|
|
|
21
21
|
gem install spree_wholesale --pre
|
|
22
|
-
echo "gem 'spree_wholesale', '0.40.0.beta4.
|
|
22
|
+
echo "gem 'spree_wholesale', '0.40.0.beta4.2'" >> Gemfile
|
|
23
23
|
|
|
24
24
|
rake spree_wholesale:install
|
|
25
25
|
rake db:migrate
|
|
@@ -32,9 +32,11 @@ If you want to generate sample wholesale prices:
|
|
|
32
32
|
This will assume 66% wholesale discount.
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
If you'd like run tests
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
If you'd like run tests:
|
|
36
|
+
|
|
37
|
+
git clone git://github.com/citrus/spree_wholesale.git
|
|
38
|
+
cd spree_wholesale
|
|
39
|
+
rake test_app
|
|
38
40
|
rake
|
|
39
41
|
|
|
40
42
|
(TO DO: Write some more tests!)
|
|
@@ -51,7 +53,7 @@ To create a demo of SpreeWholesaleExample
|
|
|
51
53
|
cd spree_wholesale_example
|
|
52
54
|
|
|
53
55
|
echo "gem 'spree', '0.40.0'" >> Gemfile
|
|
54
|
-
echo "gem 'spree_wholesale', '0.40.0.beta4.
|
|
56
|
+
echo "gem 'spree_wholesale', '0.40.0.beta4.2'" >> Gemfile
|
|
55
57
|
rm public/index.html
|
|
56
58
|
|
|
57
59
|
bundle install
|
|
@@ -65,7 +67,7 @@ To create a demo of SpreeWholesaleExample
|
|
|
65
67
|
|
|
66
68
|
or shorthand:
|
|
67
69
|
|
|
68
|
-
rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.0'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.0.beta4.
|
|
70
|
+
rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.0'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.0.beta4.2'" >> Gemfile; rm public/index.html
|
|
69
71
|
rake spree:install spree_wholesale:install db:migrate db:seed spree_wholesale:create_role
|
|
70
72
|
|
|
71
73
|
If you want sample data:
|
|
@@ -90,7 +92,7 @@ Then finish by booting up the rails server:
|
|
|
90
92
|
|
|
91
93
|
All in one swoop:
|
|
92
94
|
|
|
93
|
-
rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.0'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.0.beta4.
|
|
95
|
+
rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.0'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.0.beta4.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
|
|
94
96
|
|
|
95
97
|
|
|
96
98
|
To do the same as above but install from the source instead, run:
|
data/Rakefile
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
require 'rake'
|
|
3
|
-
require 'rake/testtask'
|
|
4
|
-
require 'rake/packagetask'
|
|
3
|
+
#require 'rake/testtask'
|
|
4
|
+
#require 'rake/packagetask'
|
|
5
5
|
require 'rake/gempackagetask'
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
root = ENV["RAILS_ROOT"] || File.expand_path('../spec/test_app', __FILE__)
|
|
9
|
-
|
|
10
|
-
env = File.join(root, 'config', 'environment.rb')
|
|
11
|
-
|
|
12
|
-
puts "(Rails Root: #{root})"
|
|
13
|
-
|
|
14
|
-
|
|
15
8
|
spec = eval(File.read('spree_wholesale.gemspec'))
|
|
16
|
-
|
|
17
9
|
Rake::GemPackageTask.new(spec) do |p|
|
|
18
10
|
p.gem_spec = spec
|
|
19
11
|
end
|
|
20
12
|
|
|
21
13
|
|
|
14
|
+
|
|
22
15
|
namespace :spree_wholesale do
|
|
23
16
|
desc "Test Spree Wholesale Extension"
|
|
24
17
|
task :test do
|
|
18
|
+
|
|
19
|
+
root = ENV["RAILS_ROOT"] || File.expand_path('../spec/test_app', __FILE__)
|
|
20
|
+
env = File.join(root, 'config', 'environment.rb')
|
|
21
|
+
puts "(Rails Root: #{root})"
|
|
25
22
|
|
|
26
23
|
require env
|
|
27
24
|
require File.expand_path('../test/test_helper', __FILE__)
|
|
28
|
-
|
|
29
25
|
Dir["test/**/*.rb"].reject{|file| file.match(/test_helper/) != nil }.each do |file|
|
|
30
26
|
puts "Loading #{file}"
|
|
31
27
|
load file
|
|
@@ -34,19 +30,8 @@ namespace :spree_wholesale do
|
|
|
34
30
|
end
|
|
35
31
|
end
|
|
36
32
|
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#if File.exists?(env)
|
|
40
|
-
# desc "Default Task"
|
|
41
|
-
# task :default => [ :test_extension ]
|
|
42
|
-
#else
|
|
43
|
-
# desc "Default Task"
|
|
44
|
-
# task :default => []
|
|
45
|
-
# puts "environment.rb not found! Try modifying the path to your rails application."
|
|
46
|
-
#end
|
|
47
|
-
|
|
48
33
|
desc "Default Task"
|
|
49
|
-
task :default => [ :
|
|
34
|
+
task :default => [ "spree_wholesale:test" ]
|
|
50
35
|
|
|
51
36
|
|
|
52
37
|
|
|
@@ -56,38 +41,48 @@ desc "Regenerates a Rails 3 app for testing"
|
|
|
56
41
|
task :test_app do
|
|
57
42
|
# TODO - this path requires a certain directory structure -- need
|
|
58
43
|
# to think about how to refactor
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
files = `gem contents spree`.split("\n").select{|file| file.match("test_app_generator")}
|
|
47
|
+
if files.length == 1
|
|
48
|
+
require files.first
|
|
49
|
+
class WishlistTestAppGenerator < Spree::Generators::TestAppGenerator
|
|
50
|
+
def tweak_gemfile
|
|
51
|
+
append_file "Gemfile" ,
|
|
52
|
+
<<-gems
|
|
53
|
+
gem 'activemerchant'
|
|
65
54
|
gem 'spree_core', '>=0.40.0'
|
|
66
55
|
gem 'spree_auth', '>=0.40.0'
|
|
67
|
-
gem 'spree_wholesale', :path => "#{File.dirname(__FILE__)}"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
56
|
+
gem 'spree_wholesale', :path => "#{File.dirname(__FILE__)}"
|
|
57
|
+
gems
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def install_spree_gems
|
|
61
|
+
|
|
62
|
+
puts "-----------------------------------------"
|
|
63
|
+
puts "Installing gems..."
|
|
64
|
+
`bundle install --gemfile=spec/test_app/Gemfile`
|
|
65
|
+
puts "-----------------------------------------"
|
|
66
|
+
|
|
67
|
+
inside "test_app" do
|
|
68
|
+
run 'rake spree_core:install'
|
|
69
|
+
run 'rake spree_auth:install'
|
|
70
|
+
run 'rake spree_wholesale:install'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def migrate_db
|
|
75
|
+
run_migrations
|
|
77
76
|
end
|
|
78
77
|
end
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def migrate_db
|
|
87
|
-
run_migrations
|
|
88
|
-
end
|
|
78
|
+
|
|
79
|
+
WishlistTestAppGenerator.start
|
|
80
|
+
|
|
81
|
+
puts "spec/test_app created. "
|
|
82
|
+
|
|
83
|
+
else
|
|
84
|
+
puts "Failed: Could not find lib/generators/spree/test_app_generator.rb"
|
|
89
85
|
end
|
|
90
|
-
WishlistTestAppGenerator.start
|
|
91
86
|
end
|
|
92
87
|
|
|
93
88
|
namespace :test_app do
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class WholesalerAbilityDecorator
|
|
2
|
+
|
|
3
|
+
include CanCan::Ability
|
|
4
|
+
|
|
5
|
+
def initialize(user)
|
|
6
|
+
user ||= User.new
|
|
7
|
+
can :index, Wholesaler
|
|
8
|
+
can :new, Wholesaler
|
|
9
|
+
can :create, Wholesaler
|
|
10
|
+
can :read, Wholesaler do |resource|
|
|
11
|
+
resource.user == user
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Ability.register_ability(WholesalerAbilityDecorator)
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
<fieldset>
|
|
12
12
|
<legend>Company Information</legend>
|
|
13
|
+
|
|
13
14
|
<%= render "shared/error_messages", :target => @wholesaler %>
|
|
15
|
+
|
|
14
16
|
<p>
|
|
15
17
|
<%= form.label :company %><br/>
|
|
16
18
|
<%= form.text_field :company, :class => 'required' %><span class="req">*</span>
|
|
@@ -51,10 +53,6 @@
|
|
|
51
53
|
</fieldset>
|
|
52
54
|
|
|
53
55
|
<fieldset class="rightie">
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
<br/>
|
|
58
56
|
|
|
59
57
|
<fieldset>
|
|
60
58
|
<legend>Billing Address</legend>
|
metadata
CHANGED
|
@@ -5,10 +5,9 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 40
|
|
8
|
-
- 0
|
|
9
|
-
- beta4
|
|
10
8
|
- 2
|
|
11
|
-
|
|
9
|
+
- beta
|
|
10
|
+
version: 0.40.2.beta
|
|
12
11
|
platform: ruby
|
|
13
12
|
authors:
|
|
14
13
|
- Spencer Steffen
|
|
@@ -16,7 +15,7 @@ autorequire:
|
|
|
16
15
|
bindir: bin
|
|
17
16
|
cert_chain: []
|
|
18
17
|
|
|
19
|
-
date: 2011-01-
|
|
18
|
+
date: 2011-01-20 00:00:00 -08:00
|
|
20
19
|
default_executable:
|
|
21
20
|
dependencies:
|
|
22
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -30,8 +29,8 @@ dependencies:
|
|
|
30
29
|
segments:
|
|
31
30
|
- 0
|
|
32
31
|
- 40
|
|
33
|
-
-
|
|
34
|
-
version: 0.40.
|
|
32
|
+
- 2
|
|
33
|
+
version: 0.40.2
|
|
35
34
|
type: :runtime
|
|
36
35
|
version_requirements: *id001
|
|
37
36
|
- !ruby/object:Gem::Dependency
|
|
@@ -45,8 +44,8 @@ dependencies:
|
|
|
45
44
|
segments:
|
|
46
45
|
- 0
|
|
47
46
|
- 40
|
|
48
|
-
-
|
|
49
|
-
version: 0.40.
|
|
47
|
+
- 2
|
|
48
|
+
version: 0.40.2
|
|
50
49
|
type: :runtime
|
|
51
50
|
version_requirements: *id002
|
|
52
51
|
description: Spree Wholesale adds a wholesale_price field to variants and allows users with a "wholesaler" role to access these prices.
|
|
@@ -67,13 +66,11 @@ files:
|
|
|
67
66
|
- lib/spree_wholesale_hooks.rb
|
|
68
67
|
- lib/tasks/install.rake
|
|
69
68
|
- lib/tasks/spree_wholesale.rake
|
|
70
|
-
- lib/wholesale_products_helper.rb
|
|
71
69
|
- app/controllers/admin/base_controller_decorator.rb
|
|
72
70
|
- app/controllers/admin/orders_controller_decorator.rb
|
|
73
71
|
- app/controllers/admin/wholesalers_controller.rb
|
|
74
72
|
- app/controllers/checkout_controller_decorator.rb
|
|
75
73
|
- app/controllers/wholesalers_controller.rb
|
|
76
|
-
- app/models/ability.rb
|
|
77
74
|
- app/models/application_helper_decorator.rb
|
|
78
75
|
- app/models/country_decorator.rb
|
|
79
76
|
- app/models/line_item_decorator.rb
|
|
@@ -84,6 +81,7 @@ files:
|
|
|
84
81
|
- app/models/user_decorator.rb
|
|
85
82
|
- app/models/variant_decorator.rb
|
|
86
83
|
- app/models/wholesaler.rb
|
|
84
|
+
- app/models/wholesaler_ability_decorator.rb
|
|
87
85
|
- app/views/admin/hooks/_admin_orders_index_headers.html.erb
|
|
88
86
|
- app/views/admin/hooks/_admin_orders_index_rows.html.erb
|
|
89
87
|
- app/views/admin/hooks/_admin_orders_index_search.html.erb
|
data/app/models/ability.rb
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# Implementation class for Cancan gem. Instead of overriding this class, consider adding new permissions
|
|
2
|
-
# using the special +register_ability+ method which allows extensions to add their own abilities.
|
|
3
|
-
#
|
|
4
|
-
# See http://github.com/ryanb/cancan for more details on cancan.
|
|
5
|
-
class Ability
|
|
6
|
-
include CanCan::Ability
|
|
7
|
-
|
|
8
|
-
class_attribute :abilities
|
|
9
|
-
self.abilities = Set.new
|
|
10
|
-
|
|
11
|
-
# Allows us to go beyond the standard cancan initialize method which makes it difficult for engines to
|
|
12
|
-
# modify the default +Ability+ of an application. The +ability+ argument must be a class that includes
|
|
13
|
-
# the +CanCan::Ability+ module. The registered ability should behave properly as a stand-alone class
|
|
14
|
-
# and therefore should be easy to test in isolation.
|
|
15
|
-
def self.register_ability(ability)
|
|
16
|
-
self.abilities.add(ability)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def initialize(user)
|
|
20
|
-
self.clear_aliased_actions
|
|
21
|
-
|
|
22
|
-
# override cancan default aliasing (we don't want to differentiate between read and index)
|
|
23
|
-
alias_action :edit, :to => :update
|
|
24
|
-
alias_action :new, :to => :create
|
|
25
|
-
alias_action :new_action, :to => :create
|
|
26
|
-
alias_action :show, :to => :read
|
|
27
|
-
|
|
28
|
-
user ||= User.new
|
|
29
|
-
if user.has_role? 'admin'
|
|
30
|
-
can :manage, :all
|
|
31
|
-
else
|
|
32
|
-
#############################
|
|
33
|
-
can :read, User do |resource|
|
|
34
|
-
resource == user
|
|
35
|
-
end
|
|
36
|
-
can :update, User do |resource|
|
|
37
|
-
resource == user
|
|
38
|
-
end
|
|
39
|
-
can :create, User
|
|
40
|
-
#############################
|
|
41
|
-
can :read, Order do |order, token|
|
|
42
|
-
order.user == user || order.token && token == order.token
|
|
43
|
-
end
|
|
44
|
-
can :update, Order do |order, token|
|
|
45
|
-
order.user == user || order.token && token == order.token
|
|
46
|
-
end
|
|
47
|
-
can :create, Order
|
|
48
|
-
#############################
|
|
49
|
-
can :read, Product
|
|
50
|
-
can :index, Product
|
|
51
|
-
#############################
|
|
52
|
-
can :read, Taxon
|
|
53
|
-
can :index, Taxon
|
|
54
|
-
#############################
|
|
55
|
-
can :index, Wholesaler
|
|
56
|
-
can :new, Wholesaler
|
|
57
|
-
can :create, Wholesaler
|
|
58
|
-
can :read, Wholesaler do |resource|
|
|
59
|
-
resource.user == user
|
|
60
|
-
end
|
|
61
|
-
#############################
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
#include any abilities registered by extensions, etc.
|
|
65
|
-
Ability.abilities.each do |clazz|
|
|
66
|
-
ability = clazz.send(:new, user)
|
|
67
|
-
@can_definitions = abilities + ability.send(:abilities)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
end
|
|
71
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
#module WholesaleProductsHelper
|
|
2
|
-
#
|
|
3
|
-
# # returns the price of the product to show for display purposes
|
|
4
|
-
# def product_price(product_or_variant, options={})
|
|
5
|
-
# options.assert_valid_keys(:format_as_currency, :show_vat_text)
|
|
6
|
-
# options.reverse_merge! :format_as_currency => true, :show_vat_text => Spree::Config[:show_price_inc_vat]
|
|
7
|
-
#
|
|
8
|
-
# puts "-----"
|
|
9
|
-
# puts current_user.roles.inspect
|
|
10
|
-
#
|
|
11
|
-
# if current_user.has_role?("wholesaler")
|
|
12
|
-
# _amount = product_or_variant.wholesale_price
|
|
13
|
-
# amount = _amount if 0.0 < _amount
|
|
14
|
-
# end
|
|
15
|
-
#
|
|
16
|
-
# amount ||= product_or_variant.price
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# amount += Calculator::Vat.calculate_tax_on(product_or_variant) if Spree::Config[:show_price_inc_vat]
|
|
21
|
-
# options.delete(:format_as_currency) ? format_price(amount, options) : amount
|
|
22
|
-
# end
|
|
23
|
-
#
|
|
24
|
-
#end
|
|
25
|
-
#
|
|
26
|
-
#ProductsHelper.send(:include, WholesaleProductsHelper)
|