spree_wholesale 0.40.0.beta3 → 0.40.0.beta4.1

Sign up to get free protection for your applications and to get access to all the features.
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.beta3'" >> Gemfile
22
+ echo "gem 'spree_wholesale', '0.40.0.beta4'" >> Gemfile
23
23
 
24
24
  rake spree_wholesale:install
25
25
  rake db:migrate
@@ -51,7 +51,7 @@ To create a demo of SpreeWholesaleExample
51
51
  cd spree_wholesale_example
52
52
 
53
53
  echo "gem 'spree', '0.40.0'" >> Gemfile
54
- echo "gem 'spree_wholesale', '0.40.0.beta3'" >> Gemfile
54
+ echo "gem 'spree_wholesale', '0.40.0.beta4'" >> Gemfile
55
55
  rm public/index.html
56
56
 
57
57
  bundle install
@@ -65,7 +65,7 @@ To create a demo of SpreeWholesaleExample
65
65
 
66
66
  or shorthand:
67
67
 
68
- rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.0'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.0.beta2.3'" >> Gemfile; rm public/index.html
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'" >> Gemfile; rm public/index.html
69
69
  rake spree:install spree_wholesale:install db:migrate db:seed spree_wholesale:create_role
70
70
 
71
71
  If you want sample data:
@@ -86,11 +86,18 @@ Then finish by booting up the rails server:
86
86
  rails s
87
87
 
88
88
 
89
+
90
+
89
91
  All in one swoop:
90
92
 
91
- rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.0'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.0.beta2.3'" >> 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.0'" >> Gemfile; echo "gem 'spree_wholesale', '0.40.0.beta4'" >> 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
92
94
 
93
95
 
96
+ To do the same as above but install from the source instead, run:
97
+
98
+ rails new spree_wholesale_example; cd spree_wholesale_example; echo "gem 'spree', '0.40.0'" >> Gemfile; echo "gem 'spree_wholesale', :git => 'git://github.com/citrus/spree_wholesale.git'" >> 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
99
+
100
+
94
101
 
95
102
  Once the server has loaded add the wholesaler role to your wholesale user(s). Navigate back to the store and check the prices!
96
103
 
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- require File.expand_path('../../config/application', __FILE__)
2
-
3
1
  require 'rubygems'
4
2
  require 'rake'
5
3
  require 'rake/testtask'
@@ -8,6 +6,7 @@ require 'rake/gempackagetask'
8
6
 
9
7
 
10
8
  spec = eval(File.read('spree_wholesale.gemspec'))
9
+ env = File.expand_path('../../config/environment', __FILE__)
11
10
 
12
11
  Rake::GemPackageTask.new(spec) do |p|
13
12
  p.gem_spec = spec
@@ -16,6 +15,8 @@ end
16
15
 
17
16
  desc "Test Spree Wholesale Extension"
18
17
  task :test_extension do
18
+
19
+ require env
19
20
  require File.expand_path('../test/test_helper', __FILE__)
20
21
 
21
22
  Dir["test/**/*.rb"].reject{|file| file.match(/test_helper/) != nil }.each do |file|
@@ -26,5 +27,11 @@ task :test_extension do
26
27
  end
27
28
 
28
29
 
29
- desc "Default Task"
30
- task :default => [ :test_extension ]
30
+ if File.exists?(env)
31
+ desc "Default Task"
32
+ task :default => [ :test_extension ]
33
+ else
34
+ desc "Default Task"
35
+ task :default => []
36
+ puts "environment.rb not found! Try modifying the path to your rails application."
37
+ end
@@ -1,8 +1,8 @@
1
1
  ApplicationHelper.module_eval do
2
2
 
3
-
4
3
  def wholesaler_signed_in?
5
4
  current_user && current_user.has_role?("wholesaler")
6
5
  end
7
6
 
7
+
8
8
  end
@@ -8,5 +8,5 @@ LineItem.class_eval do
8
8
  self.price = (order.is_wholesale? && variant.is_wholesaleable? ? variant.wholesale_price : variant.price) if variant && self.price.nil?
9
9
 
10
10
  end
11
-
11
+
12
12
  end
@@ -4,8 +4,28 @@ Order.class_eval do
4
4
  wholesale == true
5
5
  end
6
6
 
7
+ def set_line_item_prices(use_price=:price)
8
+ line_items.includes(:variant).each do |line_item|
9
+ line_item.price = line_item.variant.send(use_price)
10
+ line_item.save
11
+ end
12
+ end
7
13
 
8
-
14
+ def to_fullsale!
15
+ puts "TO FULLSALE"
16
+ self.wholesale = false
17
+ set_line_item_prices(:price)
18
+ update!
19
+ save
20
+ end
21
+
22
+ def to_wholesale!
23
+ puts "TO WHOLESALE"
24
+ self.wholesale = true
25
+ set_line_item_prices(:wholesale_price)
26
+ update!
27
+ save
28
+ end
9
29
 
10
30
  def add_variant(variant, quantity = 1)
11
31
  current_item = contains?(variant)
@@ -1,18 +1,48 @@
1
- Spree::CurrentOrder.module_eval do
1
+ #Spree::CurrentOrder.module_eval do
2
+ #
3
+ # def before_save_new_order
4
+ #
5
+ # if current_user
6
+ # @current_order.user ||= current_user
7
+ # @current_order.wholesale = current_user.has_role?("wholesaler")
8
+ # end
9
+ #
10
+ # end
11
+ #
12
+ #end
2
13
 
3
- def before_save_new_order
4
-
5
- if current_user
6
- @current_order.user = current_user
7
- @current_order.wholesale = current_user.has_role?("wholesaler")
14
+ module Spree
15
+ module CurrentOrder
16
+
17
+ # This should be overridden by an auth-related extension which would then have the opporutnity to associate the new order with the
18
+ # current user before saving.
19
+ def before_save_new_order
20
+ if current_user
21
+ @current_order.user ||= current_user
22
+ @current_order.wholesale = current_user.has_role?("wholesaler")
23
+ end
8
24
  end
9
-
10
- #puts "before_save_new_order!!!!!"
11
-
12
- #puts current_user
13
-
14
- #puts @current_order.inspect
15
-
16
- end
17
25
 
26
+ # The current incomplete order from the session for use in cart and during checkout
27
+ def current_order(create_order_if_necessary = false)
28
+ @current_order = Order.find_by_id(session[:order_id], :include => :adjustments)
29
+ if create_order_if_necessary and (@current_order.nil? or @current_order.completed?)
30
+ @current_order = Order.new
31
+ before_save_new_order
32
+ @current_order.save!
33
+ end
34
+
35
+ if current_user && @current_order
36
+ if current_user.has_role?("wholesaler") && !@current_order.is_wholesale?
37
+ @current_order.to_wholesale!
38
+ elsif !current_user.has_role?("wholesaler") && @current_order.is_wholesale?
39
+ @current_order.to_fullsale!
40
+ end
41
+ end
42
+
43
+ session[:order_id] = @current_order ? @current_order.id : nil
44
+
45
+ @current_order
46
+ end
47
+ end
18
48
  end
@@ -1 +1,4 @@
1
- <h4 class="wholesale-customer-id"><%= t('wholesale_customer', { :id => (@order || order).user_id }) %></h4>
1
+ <% order = (@order || order) %>
2
+ <% if order.is_wholesale? %>
3
+ <h4 class="wholesale-customer-id"><%= t('wholesale_customer', { :id => order.user_id }) %></h4>
4
+ <% end %>
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+
3
+ end
@@ -0,0 +1,26 @@
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)
metadata CHANGED
@@ -6,8 +6,9 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 40
8
8
  - 0
9
- - beta3
10
- version: 0.40.0.beta3
9
+ - beta4
10
+ - 1
11
+ version: 0.40.0.beta4.1
11
12
  platform: ruby
12
13
  authors:
13
14
  - Spencer Steffen
@@ -20,6 +21,7 @@ default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: spree_core
24
+ prerelease: false
23
25
  requirement: &id001 !ruby/object:Gem::Requirement
24
26
  none: false
25
27
  requirements:
@@ -31,10 +33,10 @@ dependencies:
31
33
  - 0
32
34
  version: 0.40.0
33
35
  type: :runtime
34
- prerelease: false
35
36
  version_requirements: *id001
36
37
  - !ruby/object:Gem::Dependency
37
38
  name: spree_auth
39
+ prerelease: false
38
40
  requirement: &id002 !ruby/object:Gem::Requirement
39
41
  none: false
40
42
  requirements:
@@ -46,7 +48,6 @@ dependencies:
46
48
  - 0
47
49
  version: 0.40.0
48
50
  type: :runtime
49
- prerelease: false
50
51
  version_requirements: *id002
51
52
  description: Spree Wholesale adds a wholesale_price field to variants and allows users with a "wholesaler" role to access these prices.
52
53
  email: spencer@citrusme.com
@@ -60,10 +61,12 @@ files:
60
61
  - README.md
61
62
  - LICENSE
62
63
  - config/locales/en.yml
64
+ - config/routes.rb
63
65
  - lib/spree_wholesale.rb
64
66
  - lib/spree_wholesale_hooks.rb
65
67
  - lib/tasks/install.rake
66
68
  - lib/tasks/spree_wholesale.rake
69
+ - lib/wholesale_products_helper.rb
67
70
  - app/controllers/admin/orders_controller_decorator.rb
68
71
  - app/models/application_controller_decorator.rb
69
72
  - app/models/line_item_decorator.rb