solidus_volume_pricing 0.2.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +35 -0
- data/.gem_release.yml +5 -0
- data/.github/dependabot.yml +7 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +14 -9
- data/.rspec +2 -2
- data/.rubocop.yml +3 -7
- data/.rubocop_todo.yml +126 -0
- data/CHANGELOG.md +86 -0
- data/Gemfile +25 -2
- data/Guardfile +3 -1
- data/{LICENSE.md → LICENSE} +2 -2
- data/README.md +55 -50
- data/Rakefile +4 -19
- data/app/assets/javascripts/spree/backend/solidus_volume_pricing.js +1 -15
- data/app/controllers/spree/admin/volume_price_models_controller.rb +2 -1
- data/app/controllers/spree/admin/volume_prices_controller.rb +3 -1
- data/app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb +42 -0
- data/app/decorators/helpers/solidus_volume_pricing/spree/base_helper_decorator.rb +31 -0
- data/app/decorators/models/solidus_volume_pricing/spree/line_item_decorator.rb +18 -0
- data/app/decorators/models/solidus_volume_pricing/spree/variant_decorator.rb +21 -0
- data/app/models/solidus_volume_pricing/price_display.rb +47 -0
- data/app/models/solidus_volume_pricing/pricer.rb +95 -0
- data/app/models/solidus_volume_pricing/pricing_options.rb +20 -0
- data/app/models/spree/volume_price.rb +43 -26
- data/app/models/spree/volume_price_model.rb +6 -4
- data/app/overrides/spree/admin/shared/_settings_sub_menu/add_volume_price_model_admin_menu_links.html.erb.deface +5 -0
- data/app/overrides/views_decorator.rb +2 -0
- data/app/views/spree/admin/shared/_vp_product_tab.html.erb +2 -2
- data/app/views/spree/admin/variants/_edit_fields.html.erb +5 -32
- data/app/views/spree/admin/variants/volume_prices.html.erb +9 -36
- data/app/views/spree/admin/volume_price_models/_form.html.erb +6 -2
- data/app/views/spree/admin/volume_price_models/_list.html.erb +8 -4
- data/app/views/spree/admin/volume_price_models/_select.html.erb +17 -0
- data/app/views/spree/admin/volume_price_models/edit.html.erb +7 -6
- data/app/views/spree/admin/volume_price_models/index.html.erb +7 -5
- data/app/views/spree/admin/volume_price_models/new.html.erb +5 -5
- data/app/views/spree/admin/volume_prices/_table.html.erb +26 -0
- data/app/views/spree/admin/volume_prices/_volume_price_fields.html.erb +10 -8
- data/app/views/spree/products/_volume_pricing.html.erb +8 -8
- data/bin/console +17 -0
- data/bin/rails +12 -4
- data/bin/setup +8 -0
- data/config/locales/de.yml +17 -3
- data/config/locales/en.yml +21 -2
- data/config/locales/pt.yml +6 -2
- data/config/locales/ru.yml +6 -2
- data/config/locales/sv.yml +6 -2
- data/config/locales/tr.yml +6 -2
- data/config/routes.rb +3 -1
- data/db/migrate/20081119145604_create_volume_prices.rb +3 -1
- data/db/migrate/20110203174010_change_display_name_for_volume_prices.rb +3 -1
- data/db/migrate/20111206173307_prefix_volume_pricing_table_names.rb +3 -1
- data/db/migrate/20121115043422_add_discount_type_column.rb +3 -1
- data/db/migrate/20150513200904_add_role_to_volume_price.rb +3 -1
- data/db/migrate/20150603143015_create_spree_volume_price_models.rb +3 -1
- data/lib/generators/solidus_volume_pricing/install/install_generator.rb +5 -5
- data/lib/solidus_volume_pricing/engine.rb +16 -24
- data/lib/solidus_volume_pricing/range_from_string.rb +36 -0
- data/lib/solidus_volume_pricing/testing_support/factories.rb +14 -0
- data/lib/solidus_volume_pricing/version.rb +3 -16
- data/lib/solidus_volume_pricing.rb +6 -1
- data/solidus_volume_pricing.gemspec +26 -23
- data/spec/controllers/spree/admin/variants_controller_spec.rb +18 -15
- data/spec/features/manage_volume_price_models_feature_spec.rb +5 -7
- data/spec/features/manage_volume_prices_feature_spec.rb +9 -8
- data/spec/helpers/base_helper_spec.rb +3 -1
- data/spec/lib/solidus_volume_pricing/range_from_string_spec.rb +61 -0
- data/spec/models/solidus_volume_pricing/pricer_spec.rb +669 -0
- data/spec/models/solidus_volume_pricing/pricing_options_spec.rb +57 -0
- data/spec/models/spree/line_item_spec.rb +23 -21
- data/spec/models/spree/order_spec.rb +4 -2
- data/spec/models/spree/variant_spec.rb +3 -303
- data/spec/models/spree/volume_price_spec.rb +145 -50
- data/spec/spec_helper.rb +15 -35
- data/spec/support/shoulda.rb +11 -0
- metadata +83 -161
- data/.hound.yml +0 -40
- data/.travis.yml +0 -12
- data/CONTRIBUTING.md +0 -81
- data/app/controllers/spree/admin/variants_controller_decorator.rb +0 -32
- data/app/helpers/spree/base_helper_decorator.rb +0 -19
- data/app/models/spree/line_item_decorator.rb +0 -13
- data/app/models/spree/user_decorator.rb +0 -10
- data/app/models/spree/variant_decorator.rb +0 -104
- data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_volume_price_model_admin_menu_links.html.erb.deface +0 -3
- data/app/views/spree/admin/volume_prices/_edit_fields.html.erb +0 -31
- data/spec/factories/volume_price_factory.rb +0 -12
- data/spec/support/capybara.rb +0 -12
- data/spec/support/database_cleaner.rb +0 -21
- data/spec/support/factory_girl.rb +0 -7
- data/spec/support/spree.rb +0 -10
@@ -1,104 +0,0 @@
|
|
1
|
-
Spree::Variant.class_eval do
|
2
|
-
has_and_belongs_to_many :volume_price_models
|
3
|
-
has_many :volume_prices, -> { order(position: :asc) }, dependent: :destroy
|
4
|
-
has_many :model_volume_prices, -> { order(position: :asc) }, class_name: 'Spree::VolumePrice', through: :volume_price_models, source: :volume_prices
|
5
|
-
accepts_nested_attributes_for :volume_prices, allow_destroy: true,
|
6
|
-
reject_if: proc { |volume_price|
|
7
|
-
volume_price[:amount].blank? && volume_price[:range].blank?
|
8
|
-
}
|
9
|
-
|
10
|
-
def join_volume_prices(user = nil)
|
11
|
-
table = Spree::VolumePrice.arel_table
|
12
|
-
|
13
|
-
if user
|
14
|
-
Spree::VolumePrice.where(
|
15
|
-
(table[:variant_id].eq(id)
|
16
|
-
.or(table[:volume_price_model_id].in(volume_price_models.ids)))
|
17
|
-
.and(table[:role_id].eq(user.resolve_role))
|
18
|
-
)
|
19
|
-
.order(position: :asc)
|
20
|
-
else
|
21
|
-
Spree::VolumePrice.where(
|
22
|
-
(table[:variant_id]
|
23
|
-
.eq(id)
|
24
|
-
.or(table[:volume_price_model_id].in(volume_price_models.ids)))
|
25
|
-
.and(table[:role_id].eq(nil))
|
26
|
-
).order(position: :asc)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# calculates the price based on quantity
|
31
|
-
def volume_price(quantity, user = nil)
|
32
|
-
compute_volume_price_quantities :volume_price, price, quantity, user
|
33
|
-
end
|
34
|
-
|
35
|
-
# return percent of earning
|
36
|
-
def volume_price_earning_percent(quantity, user = nil)
|
37
|
-
compute_volume_price_quantities :volume_price_earning_percent, 0, quantity, user
|
38
|
-
end
|
39
|
-
|
40
|
-
# return amount of earning
|
41
|
-
def volume_price_earning_amount(quantity, user = nil)
|
42
|
-
compute_volume_price_quantities :volume_price_earning_amount, 0, quantity, user
|
43
|
-
end
|
44
|
-
|
45
|
-
protected
|
46
|
-
|
47
|
-
def use_master_variant_volume_pricing?
|
48
|
-
Spree::Config.use_master_variant_volume_pricing && !(product.master.join_volume_prices.count == 0)
|
49
|
-
end
|
50
|
-
|
51
|
-
def compute_volume_price_quantities(type, default_price, quantity, user)
|
52
|
-
volume_prices = join_volume_prices user
|
53
|
-
if volume_prices.count == 0
|
54
|
-
if use_master_variant_volume_pricing?
|
55
|
-
product.master.send(type, quantity, user)
|
56
|
-
else
|
57
|
-
return default_price
|
58
|
-
end
|
59
|
-
else
|
60
|
-
volume_prices.each do |volume_price|
|
61
|
-
if volume_price.include?(quantity)
|
62
|
-
return send "compute_#{type}".to_sym, volume_price
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# No price ranges matched.
|
67
|
-
default_price
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def compute_volume_price(volume_price)
|
72
|
-
case volume_price.discount_type
|
73
|
-
when 'price'
|
74
|
-
return volume_price.amount
|
75
|
-
when 'dollar'
|
76
|
-
return price - volume_price.amount
|
77
|
-
when 'percent'
|
78
|
-
return price * (1 - volume_price.amount)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def compute_volume_price_earning_percent(volume_price)
|
83
|
-
case volume_price.discount_type
|
84
|
-
when 'price'
|
85
|
-
diff = price - volume_price.amount
|
86
|
-
return (diff * 100 / price).round
|
87
|
-
when 'dollar'
|
88
|
-
return (volume_price.amount * 100 / price).round
|
89
|
-
when 'percent'
|
90
|
-
return (volume_price.amount * 100).round
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def compute_volume_price_earning_amount(volume_price)
|
95
|
-
case volume_price.discount_type
|
96
|
-
when 'price'
|
97
|
-
return price - volume_price.amount
|
98
|
-
when 'dollar'
|
99
|
-
return volume_price.amount
|
100
|
-
when 'percent'
|
101
|
-
return price - (price * (1 - volume_price.amount))
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
<% content_for :page_actions do %>
|
2
|
-
<span id="new_add_volume_price" data-hook>
|
3
|
-
<%= button_link_to Spree.t(:add_volume_price), 'javascript:;', {
|
4
|
-
icon: 'add',
|
5
|
-
:'data-target' => 'tbody#volume_prices',
|
6
|
-
class: 'btn-success spree_add_fields',
|
7
|
-
id: 'add_volume_price'
|
8
|
-
} %>
|
9
|
-
</span>
|
10
|
-
<% end %>
|
11
|
-
|
12
|
-
<h3><%= Spree.t(:volume_prices) %></h3>
|
13
|
-
<table class="table">
|
14
|
-
<thead>
|
15
|
-
<tr>
|
16
|
-
<th><%= Spree.t(:name) %></th>
|
17
|
-
<th><%= Spree.t(:discount_type) %></th>
|
18
|
-
<th><%= Spree.t(:range) %></th>
|
19
|
-
<th><%= Spree.t(:amount) %></th>
|
20
|
-
<th><%= Spree.t(:position) %></th>
|
21
|
-
<th><%= Spree.t(:role) %></th>
|
22
|
-
<th class="actions"></th>
|
23
|
-
</tr>
|
24
|
-
</thead>
|
25
|
-
<tbody id="volume_prices">
|
26
|
-
<%= f.fields_for :volume_prices do |vp_form| %>
|
27
|
-
<%= render partial: 'spree/admin/volume_prices/volume_price_fields', locals: { f: vp_form } %>
|
28
|
-
<% end %>
|
29
|
-
</tbody>
|
30
|
-
</table>
|
31
|
-
<br/><br/>
|
data/spec/support/capybara.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'capybara'
|
2
|
-
require 'capybara/rspec'
|
3
|
-
require 'capybara/rails'
|
4
|
-
require 'capybara/poltergeist'
|
5
|
-
|
6
|
-
RSpec.configure do
|
7
|
-
Capybara.javascript_driver = :poltergeist
|
8
|
-
|
9
|
-
Capybara.register_driver(:poltergeist) do |app|
|
10
|
-
Capybara::Poltergeist::Driver.new app, js_errors: true, timeout: 60
|
11
|
-
end
|
12
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'database_cleaner'
|
2
|
-
|
3
|
-
RSpec.configure do |config|
|
4
|
-
|
5
|
-
config.before :suite do
|
6
|
-
DatabaseCleaner.clean_with :truncation
|
7
|
-
end
|
8
|
-
|
9
|
-
config.prepend_before(:each) do
|
10
|
-
if RSpec.current_example.metadata[:js]
|
11
|
-
DatabaseCleaner.strategy = :truncation
|
12
|
-
else
|
13
|
-
DatabaseCleaner.strategy = :transaction
|
14
|
-
end
|
15
|
-
DatabaseCleaner.start
|
16
|
-
end
|
17
|
-
|
18
|
-
config.append_after(:each) do
|
19
|
-
DatabaseCleaner.clean
|
20
|
-
end
|
21
|
-
end
|
data/spec/support/spree.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'spree/testing_support/factories'
|
2
|
-
require 'spree/testing_support/controller_requests'
|
3
|
-
require 'spree/testing_support/authorization_helpers'
|
4
|
-
require 'spree/testing_support/url_helpers'
|
5
|
-
require 'spree/testing_support/capybara_ext'
|
6
|
-
|
7
|
-
RSpec.configure do |config|
|
8
|
-
config.include Spree::TestingSupport::ControllerRequests, type: :controller
|
9
|
-
config.include Spree::TestingSupport::UrlHelpers
|
10
|
-
end
|