solidus_volume_pricing 1.2.0 → 2.0.0
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.
- checksums.yaml +4 -4
- data/.git-blame-ignore-revs +3 -0
- data/.github/workflows/lint.yml +25 -0
- data/.github/workflows/test.yml +59 -0
- data/.rubocop.yml +0 -5
- data/Gemfile +21 -23
- data/Guardfile +8 -8
- data/README.md +1 -1
- data/Rakefile +3 -3
- data/app/models/solidus_volume_pricing/pricer.rb +9 -9
- data/app/models/solidus_volume_pricing/pricing_options.rb +2 -2
- data/app/models/spree/volume_price.rb +8 -8
- data/app/patches/helpers/solidus_volume_pricing/spree_base_helper_patch.rb +29 -0
- data/app/patches/models/solidus_volume_pricing/spree_line_item_patch.rb +18 -0
- data/app/patches/models/solidus_volume_pricing/spree_variant_patch.rb +21 -0
- data/bin/rails-engine +6 -6
- data/bin/rails-sandbox +4 -4
- data/config/routes.rb +1 -1
- data/db/migrate/20150603143015_create_spree_volume_price_models.rb +2 -2
- data/lib/generators/solidus_volume_pricing/install/install_generator.rb +4 -4
- data/lib/patches/backend/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb +38 -0
- data/lib/solidus_volume_pricing/engine.rb +22 -11
- data/lib/solidus_volume_pricing/range_from_string.rb +4 -4
- data/lib/solidus_volume_pricing/testing_support/factories.rb +5 -5
- data/lib/solidus_volume_pricing/version.rb +1 -1
- data/lib/solidus_volume_pricing.rb +9 -9
- data/solidus_volume_pricing.gemspec +20 -21
- metadata +41 -63
- data/.circleci/config.yml +0 -73
- data/.rubocop_todo.yml +0 -68
- data/app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb +0 -42
- data/app/decorators/helpers/solidus_volume_pricing/spree/base_helper_decorator.rb +0 -31
- data/app/decorators/models/solidus_volume_pricing/spree/line_item_decorator.rb +0 -18
- data/app/decorators/models/solidus_volume_pricing/spree/variant_decorator.rb +0 -23
- data/spec/controllers/spree/admin/variants_controller_spec.rb +0 -30
- data/spec/features/manage_volume_price_models_feature_spec.rb +0 -24
- data/spec/features/manage_volume_prices_feature_spec.rb +0 -33
- data/spec/helpers/base_helper_spec.rb +0 -24
- data/spec/lib/solidus_volume_pricing/range_from_string_spec.rb +0 -61
- data/spec/models/solidus_volume_pricing/pricer_spec.rb +0 -669
- data/spec/models/solidus_volume_pricing/pricing_options_spec.rb +0 -57
- data/spec/models/spree/line_item_spec.rb +0 -36
- data/spec/models/spree/order_spec.rb +0 -51
- data/spec/models/spree/variant_spec.rb +0 -6
- data/spec/models/spree/volume_price_spec.rb +0 -216
- data/spec/spec_helper.rb +0 -32
- data/spec/support/shoulda.rb +0 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d4b9c4e9d82bacce19b43bf6e8bca28b72b0caec7bc188cff10eac7ed2ca99f0
|
|
4
|
+
data.tar.gz: 24f362ea97f9538968ace48ee5fdf9889b68909fc2a7f9ccdbe24a346734a743
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa54524394df01a87eae968ae4494737295c465b20add1f550cb3f4b38340850e4c1148da3cf0aac017472a7bed7a9a71a5263fd31b8bf4ca58c739f06844691
|
|
7
|
+
data.tar.gz: 61ad6b3fb17aa88af304c150d787014b8b29c4917b7d0ae813b69cf4fc7138d7ee9c58a6724458c6c319f72e8d56da599ff38c9983da74d05c0454dd0048d362
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Lint
|
|
2
|
+
|
|
3
|
+
on: [pull_request]
|
|
4
|
+
|
|
5
|
+
concurrency:
|
|
6
|
+
group: lint-${{ github.ref_name }}
|
|
7
|
+
cancel-in-progress: ${{ github.ref_name != 'main' }}
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
ruby:
|
|
14
|
+
name: Check Ruby
|
|
15
|
+
runs-on: ubuntu-24.04
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout code
|
|
18
|
+
uses: actions/checkout@v3
|
|
19
|
+
- name: Install Ruby and gems
|
|
20
|
+
uses: ruby/setup-ruby@v1
|
|
21
|
+
with:
|
|
22
|
+
ruby-version: "3.2"
|
|
23
|
+
bundler-cache: true
|
|
24
|
+
- name: Lint Ruby files
|
|
25
|
+
run: bundle exec rubocop -ESP
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
schedule:
|
|
9
|
+
- cron: "0 0 * * 4" # every Thursday
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: test-${{ github.ref_name }}
|
|
13
|
+
cancel-in-progress: ${{ github.ref_name != 'main' }}
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
rspec:
|
|
20
|
+
name: Solidus ${{ matrix.solidus-branch }}, Rails ${{ matrix.rails-version }} and Ruby ${{ matrix.ruby-version }} on ${{ matrix.database }}
|
|
21
|
+
runs-on: ubuntu-24.04
|
|
22
|
+
strategy:
|
|
23
|
+
fail-fast: false
|
|
24
|
+
matrix:
|
|
25
|
+
rails-version:
|
|
26
|
+
- "7.2"
|
|
27
|
+
- "8.0"
|
|
28
|
+
ruby-version:
|
|
29
|
+
- "3.1"
|
|
30
|
+
- "3.4"
|
|
31
|
+
solidus-branch:
|
|
32
|
+
- "v4.4"
|
|
33
|
+
- "v4.5"
|
|
34
|
+
- "v4.6"
|
|
35
|
+
database:
|
|
36
|
+
- "postgresql"
|
|
37
|
+
- "mysql"
|
|
38
|
+
- "sqlite"
|
|
39
|
+
exclude:
|
|
40
|
+
- rails-version: "8.0"
|
|
41
|
+
solidus-branch: "v4.4"
|
|
42
|
+
- rails-version: "8.0"
|
|
43
|
+
ruby-version: "3.1"
|
|
44
|
+
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@v4
|
|
47
|
+
- name: Run extension tests
|
|
48
|
+
uses: solidusio/test-solidus-extension@main
|
|
49
|
+
with:
|
|
50
|
+
database: ${{ matrix.database }}
|
|
51
|
+
rails-version: ${{ matrix.rails-version }}
|
|
52
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
53
|
+
solidus-branch: ${{ matrix.solidus-branch }}
|
|
54
|
+
- name: Upload coverage reports to Codecov
|
|
55
|
+
uses: codecov/codecov-action@v5
|
|
56
|
+
continue-on-error: true
|
|
57
|
+
with:
|
|
58
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
59
|
+
files: ./coverage/coverage.xml
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
source
|
|
3
|
+
source "https://rubygems.org"
|
|
4
4
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
branch = ENV.fetch("SOLIDUS_BRANCH", "v4.6")
|
|
9
|
+
gem "solidus", github: "solidusio/solidus", branch: branch
|
|
8
10
|
|
|
9
11
|
# The solidus_frontend gem has been pulled out since v3.2
|
|
10
|
-
gem
|
|
12
|
+
gem "solidus_frontend"
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# See https://github.com/bundler/bundler/issues/6677
|
|
15
|
-
gem 'rails', '>0.a'
|
|
14
|
+
rails_requirement_string = ENV.fetch("RAILS_VERSION", "~> 8.0")
|
|
15
|
+
gem "rails", rails_requirement_string
|
|
16
16
|
|
|
17
17
|
# Provides basic authentication functionality for testing parts of your engine
|
|
18
|
-
gem
|
|
18
|
+
gem "solidus_auth_devise"
|
|
19
19
|
|
|
20
|
-
case ENV.fetch(
|
|
21
|
-
when
|
|
22
|
-
gem
|
|
23
|
-
when
|
|
24
|
-
gem
|
|
20
|
+
case ENV.fetch("DB", nil)
|
|
21
|
+
when "mysql"
|
|
22
|
+
gem "mysql2"
|
|
23
|
+
when "postgresql"
|
|
24
|
+
gem "pg"
|
|
25
25
|
else
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
# While we still support Ruby < 3 we need to workaround a limitation in
|
|
30
|
-
# the 'async' gem that relies on the latest ruby, since RubyGems doesn't
|
|
31
|
-
# resolve gems based on the required ruby version.
|
|
32
|
-
gem 'async', '< 3' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
|
|
26
|
+
rails_version = Gem::Requirement.new(rails_requirement_string).requirements[0][1]
|
|
27
|
+
sqlite_version = (rails_version < Gem::Version.new(7.2)) ? "~> 1.4" : "~> 2.0"
|
|
33
28
|
|
|
34
|
-
|
|
29
|
+
gem "sqlite3", sqlite_version
|
|
30
|
+
end
|
|
35
31
|
|
|
36
32
|
# Use a local Gemfile to include development dependencies that might not be
|
|
37
33
|
# relevant for the project or for other contributors, e.g. pry-byebug.
|
|
38
34
|
#
|
|
39
35
|
# We use `send` instead of calling `eval_gemfile` to work around an issue with
|
|
40
36
|
# how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
|
|
41
|
-
send(:eval_gemfile,
|
|
37
|
+
send(:eval_gemfile, "Gemfile-local") if File.exist? "Gemfile-local"
|
|
38
|
+
|
|
39
|
+
gem "csv", "~> 3.3"
|
data/Guardfile
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
guard
|
|
4
|
-
watch(
|
|
5
|
-
watch(
|
|
6
|
-
watch(
|
|
7
|
-
watch(%r{^spec/(.+)_spec\.rb$})
|
|
8
|
-
watch(%r{^app/(.+)_decorator\.rb$})
|
|
9
|
-
watch(%r{^(app|lib)/(.+)(\.rb|\.erb)$})
|
|
10
|
-
watch(%r{^app/controllers/(.+)_(controller)\.rb$})
|
|
3
|
+
guard "rspec", cmd: "bundle exec rspec" do
|
|
4
|
+
watch("spec/spec_helper.rb") { "spec" }
|
|
5
|
+
watch("config/routes.rb") { "spec/controllers" }
|
|
6
|
+
watch("app/controllers/application_controller.rb") { "spec/controllers" }
|
|
7
|
+
watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
8
|
+
watch(%r{^app/(.+)_decorator\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
9
|
+
watch(%r{^(app|lib)/(.+)(\.rb|\.erb)$}) { |m| "spec/#{m[2]}_spec.rb" }
|
|
10
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
|
|
11
11
|
end
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Volume Pricing
|
|
2
2
|
|
|
3
|
-
[](https://github.com/solidusio-contrib/solidus_volume_pricing/actions/workflows/test.yml)
|
|
4
4
|
[](https://codeclimate.com/github/solidusio-contrib/solidus_volume_pricing)
|
|
5
5
|
|
|
6
6
|
Volume Pricing is an extension to Solidus that uses predefined ranges of quantities to determine the
|
data/Rakefile
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
4
|
|
|
5
|
-
require
|
|
5
|
+
require "solidus_dev_support/rake_tasks"
|
|
6
6
|
SolidusDevSupport::RakeTasks.install
|
|
7
7
|
|
|
8
|
-
task default:
|
|
8
|
+
task default: "extension:specs"
|
|
@@ -54,11 +54,11 @@ module SolidusVolumePricing
|
|
|
54
54
|
|
|
55
55
|
def computed_price
|
|
56
56
|
case volume_price&.discount_type
|
|
57
|
-
when
|
|
57
|
+
when "price"
|
|
58
58
|
volume_price.amount
|
|
59
|
-
when
|
|
59
|
+
when "dollar"
|
|
60
60
|
variant.price - volume_price.amount
|
|
61
|
-
when
|
|
61
|
+
when "percent"
|
|
62
62
|
variant.price * (1 - volume_price.amount)
|
|
63
63
|
else
|
|
64
64
|
variant.price
|
|
@@ -67,11 +67,11 @@ module SolidusVolumePricing
|
|
|
67
67
|
|
|
68
68
|
def computed_earning
|
|
69
69
|
case volume_price&.discount_type
|
|
70
|
-
when
|
|
70
|
+
when "price"
|
|
71
71
|
variant.price - volume_price.amount
|
|
72
|
-
when
|
|
72
|
+
when "dollar"
|
|
73
73
|
volume_price.amount
|
|
74
|
-
when
|
|
74
|
+
when "percent"
|
|
75
75
|
variant.price - (variant.price * (1 - volume_price.amount))
|
|
76
76
|
else
|
|
77
77
|
0
|
|
@@ -80,12 +80,12 @@ module SolidusVolumePricing
|
|
|
80
80
|
|
|
81
81
|
def computed_earning_percent
|
|
82
82
|
case volume_price&.discount_type
|
|
83
|
-
when
|
|
83
|
+
when "price"
|
|
84
84
|
diff = variant.price - volume_price.amount
|
|
85
85
|
diff * 100 / variant.price
|
|
86
|
-
when
|
|
86
|
+
when "dollar"
|
|
87
87
|
volume_price.amount * 100 / variant.price
|
|
88
|
-
when
|
|
88
|
+
when "percent"
|
|
89
89
|
volume_price.amount * 100
|
|
90
90
|
else
|
|
91
91
|
0
|
|
@@ -5,13 +5,13 @@ module SolidusVolumePricing
|
|
|
5
5
|
attr_accessor :quantity, :user
|
|
6
6
|
|
|
7
7
|
def initialize(options = {})
|
|
8
|
-
super
|
|
8
|
+
super(options.except(:quantity, :user))
|
|
9
9
|
@quantity = options.delete(:quantity)
|
|
10
10
|
@user = options.delete(:user)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def self.from_line_item(line_item)
|
|
14
|
-
pricing_options = super
|
|
14
|
+
pricing_options = super
|
|
15
15
|
pricing_options.quantity = line_item.quantity
|
|
16
16
|
pricing_options.user = line_item.order.user
|
|
17
17
|
pricing_options
|
|
@@ -4,14 +4,14 @@ module Spree
|
|
|
4
4
|
class VolumePrice < ApplicationRecord
|
|
5
5
|
belongs_to :variant, touch: true, optional: true
|
|
6
6
|
belongs_to :volume_price_model, touch: true, optional: true
|
|
7
|
-
belongs_to :spree_role, class_name:
|
|
7
|
+
belongs_to :spree_role, class_name: "Spree::Role", foreign_key: "role_id", optional: true
|
|
8
8
|
acts_as_list scope: [:variant_id, :volume_price_model_id]
|
|
9
9
|
|
|
10
10
|
validates :amount, presence: true
|
|
11
11
|
validates :discount_type,
|
|
12
12
|
presence: true,
|
|
13
13
|
inclusion: {
|
|
14
|
-
in: %w
|
|
14
|
+
in: %w[price dollar percent]
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
validate :range_format
|
|
@@ -21,19 +21,19 @@ module Spree
|
|
|
21
21
|
user&.spree_roles&.each { |r| roles << r.id }
|
|
22
22
|
|
|
23
23
|
where(
|
|
24
|
-
arel_table[:variant_id].eq(variant.id)
|
|
25
|
-
or(
|
|
24
|
+
arel_table[:variant_id].eq(variant.id)
|
|
25
|
+
.or(
|
|
26
26
|
arel_table[:volume_price_model_id].in(variant.volume_price_model_ids)
|
|
27
27
|
)
|
|
28
|
-
)
|
|
29
|
-
where(role_id: roles)
|
|
30
|
-
order(position: :asc, amount: :asc)
|
|
28
|
+
)
|
|
29
|
+
.where(role_id: roles)
|
|
30
|
+
.order(position: :asc, amount: :asc)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
delegate :include?, to: :range_from_string
|
|
34
34
|
|
|
35
35
|
def display_range
|
|
36
|
-
range.gsub(/\.+/, "-").gsub(/\(|\)/,
|
|
36
|
+
range.gsub(/\.+/, "-").gsub(/\(|\)/, "")
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
private
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SolidusVolumePricing
|
|
4
|
+
module SpreeBaseHelperPatch
|
|
5
|
+
def self.prepended(base)
|
|
6
|
+
base.module_eval do
|
|
7
|
+
def display_volume_price(variant, quantity = 1, user = nil)
|
|
8
|
+
price_display(variant, quantity: quantity, user: user).price_string
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def display_volume_price_earning_percent(variant, quantity = 1, user = nil)
|
|
12
|
+
price_display(variant, quantity: quantity, user: user).earning_percent_string
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def display_volume_price_earning_amount(variant, quantity = 1, user = nil)
|
|
16
|
+
price_display(variant, quantity: quantity, user: user).earning_amount_string
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def price_display(variant, quantity:, user:)
|
|
22
|
+
SolidusVolumePricing::PriceDisplay.new(variant, quantity: quantity, user: user)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
::Spree::BaseHelper.prepend self
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SolidusVolumePricing
|
|
4
|
+
module SpreeLineItemPatch
|
|
5
|
+
def self.prepended(base)
|
|
6
|
+
base.before_validation :set_volume_pricing_attributes, if: :quantity_changed?
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def set_volume_pricing_attributes
|
|
12
|
+
options = SolidusVolumePricing::PricingOptions.from_line_item(self)
|
|
13
|
+
self.money_price = SolidusVolumePricing::Pricer.new(variant).price_for(options)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
::Spree::LineItem.prepend self
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SolidusVolumePricing
|
|
4
|
+
module SpreeVariantPatch
|
|
5
|
+
def self.prepended(base)
|
|
6
|
+
base.class_eval do
|
|
7
|
+
has_and_belongs_to_many :volume_price_models
|
|
8
|
+
has_many :volume_prices, -> { order(position: :asc) }, dependent: :destroy
|
|
9
|
+
has_many :model_volume_prices, -> {
|
|
10
|
+
order(position: :asc)
|
|
11
|
+
}, class_name: "::Spree::VolumePrice", through: :volume_price_models, source: :volume_prices
|
|
12
|
+
accepts_nested_attributes_for :volume_prices, allow_destroy: true,
|
|
13
|
+
reject_if: proc { |volume_price|
|
|
14
|
+
volume_price[:amount].blank? && volume_price[:range].blank?
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
::Spree::Variant.prepend self
|
|
20
|
+
end
|
|
21
|
+
end
|
data/bin/rails-engine
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
# This command will automatically be run when you run "rails" with Rails gems
|
|
3
3
|
# installed from the root of your application.
|
|
4
4
|
|
|
5
|
-
ENGINE_ROOT = File.expand_path(
|
|
6
|
-
ENGINE_PATH = File.expand_path(
|
|
5
|
+
ENGINE_ROOT = File.expand_path("..", __dir__)
|
|
6
|
+
ENGINE_PATH = File.expand_path("../lib/solidus_volume_pricing/engine", __dir__)
|
|
7
7
|
|
|
8
8
|
# Set up gems listed in the Gemfile.
|
|
9
|
-
ENV[
|
|
10
|
-
require
|
|
9
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
10
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
|
11
11
|
|
|
12
|
-
require
|
|
13
|
-
require
|
|
12
|
+
require "rails/all"
|
|
13
|
+
require "rails/engine/commands"
|
data/bin/rails-sandbox
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
app_root =
|
|
3
|
+
app_root = "sandbox"
|
|
4
4
|
|
|
5
5
|
unless File.exist? "#{app_root}/bin/rails"
|
|
6
|
-
warn
|
|
6
|
+
warn "Creating the sandbox app..."
|
|
7
7
|
Dir.chdir "#{__dir__}/.." do
|
|
8
8
|
system "#{__dir__}/sandbox" or begin
|
|
9
|
-
warn
|
|
9
|
+
warn "Automatic creation of the sandbox app failed"
|
|
10
10
|
exit 1
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
Dir.chdir app_root
|
|
16
|
-
exec
|
|
16
|
+
exec "bin/rails", *ARGV
|
data/config/routes.rb
CHANGED
|
@@ -15,7 +15,7 @@ class CreateSpreeVolumePriceModels < ActiveRecord::Migration[4.2]
|
|
|
15
15
|
|
|
16
16
|
add_reference :spree_volume_prices, :volume_price_model
|
|
17
17
|
|
|
18
|
-
add_index :spree_variants_volume_price_models, :volume_price_model_id, name:
|
|
19
|
-
add_index :spree_variants_volume_price_models, :variant_id, name:
|
|
18
|
+
add_index :spree_variants_volume_price_models, :volume_price_model_id, name: "volume_price_model_id"
|
|
19
|
+
add_index :spree_variants_volume_price_models, :variant_id, name: "variant_id"
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -10,15 +10,15 @@ module SolidusVolumePricing
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def add_migrations
|
|
13
|
-
run
|
|
13
|
+
run "bin/rails railties:install:migrations FROM=solidus_volume_pricing"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def run_migrations
|
|
17
|
-
run_migrations = options[:auto_run_migrations] || [
|
|
17
|
+
run_migrations = options[:auto_run_migrations] || ["", "y", "Y"].include?(ask("Would you like to run the migrations now? [Y/n]")) # rubocop:disable Layout/LineLength
|
|
18
18
|
if run_migrations
|
|
19
|
-
run
|
|
19
|
+
run "bin/rails db:migrate"
|
|
20
20
|
else
|
|
21
|
-
puts
|
|
21
|
+
puts "Skipping bin/rails db:migrate, don't forget to run it!" # rubocop:disable Rails/Output
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
data/lib/patches/backend/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SolidusVolumePricing
|
|
4
|
+
module SpreeAdminVariantsControllerPatch
|
|
5
|
+
def edit
|
|
6
|
+
@variant.volume_prices.build if @variant.volume_prices.empty?
|
|
7
|
+
super
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def volume_prices
|
|
11
|
+
@product = @variant.product
|
|
12
|
+
@variant.volume_prices.build if @variant.volume_prices.empty?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
# this loads the variant for the master variant volume price editing
|
|
18
|
+
def load_resource_instance
|
|
19
|
+
parent
|
|
20
|
+
|
|
21
|
+
if new_actions.include?(params[:action].to_sym)
|
|
22
|
+
build_resource
|
|
23
|
+
elsif params[:id]
|
|
24
|
+
::Spree::Variant.find(params[:id])
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def location_after_save
|
|
29
|
+
if @product.master.id == @variant.id && params[:variant].key?(:volume_prices_attributes)
|
|
30
|
+
return volume_prices_admin_product_variant_url(@product, @variant)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
super
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
::Spree::Admin::VariantsController.prepend self
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require "spree/core"
|
|
4
|
+
require "solidus_support"
|
|
5
5
|
|
|
6
6
|
module SolidusVolumePricing
|
|
7
7
|
class Engine < Rails::Engine
|
|
@@ -9,24 +9,35 @@ module SolidusVolumePricing
|
|
|
9
9
|
|
|
10
10
|
isolate_namespace ::Spree
|
|
11
11
|
|
|
12
|
-
engine_name
|
|
12
|
+
engine_name "solidus_volume_pricing"
|
|
13
13
|
|
|
14
|
-
initializer
|
|
14
|
+
initializer "solidus_volume_pricing.preferences", before: "spree.environment" do
|
|
15
15
|
::Spree::AppConfiguration.class_eval do
|
|
16
16
|
preference :use_master_variant_volume_pricing, :boolean, default: false
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
if SolidusSupport.backend_available?
|
|
21
|
+
initializer "solidus_volume_pricing.admin_menu_item", after: "solidus_volume_pricing.preferences" do
|
|
22
|
+
Spree::Backend::Config.configure do |config|
|
|
23
|
+
settings_menu_item = config.menu_items.detect { |mi| mi.label == :settings }
|
|
24
|
+
|
|
25
|
+
# The API of the MenuItem class changes in Solidus 4.2.0
|
|
26
|
+
if settings_menu_item.respond_to?(:children)
|
|
27
|
+
settings_menu_item.children.concat([
|
|
28
|
+
Spree::BackendConfiguration::MenuItem.new(
|
|
29
|
+
label: :volume_price_models,
|
|
30
|
+
url: :admin_volume_price_models_path,
|
|
31
|
+
match_path: %r{admin/volume_price_models}
|
|
32
|
+
)
|
|
33
|
+
])
|
|
34
|
+
else
|
|
35
|
+
::Spree::BackendConfiguration::CONFIGURATION_TABS << :volume_price_models
|
|
36
|
+
end
|
|
37
|
+
end
|
|
24
38
|
end
|
|
25
|
-
::Spree::BackendConfiguration::CONFIGURATION_TABS << :volume_price_models
|
|
26
39
|
end
|
|
27
40
|
|
|
28
|
-
config.to_prepare(&method(:activate).to_proc)
|
|
29
|
-
|
|
30
41
|
# use rspec for tests
|
|
31
42
|
config.generators do |g|
|
|
32
43
|
g.test_framework :rspec
|
|
@@ -4,8 +4,8 @@ module SolidusVolumePricing
|
|
|
4
4
|
class RangeFromString
|
|
5
5
|
attr_reader :range_string
|
|
6
6
|
|
|
7
|
-
RANGE_FORMAT = /\A\(?(\d+)(\.{2,3})(\d+)\)?\z
|
|
8
|
-
OPEN_ENDED = /\(?[0-9]+\+\)
|
|
7
|
+
RANGE_FORMAT = /\A\(?(\d+)(\.{2,3})(\d+)\)?\z/
|
|
8
|
+
OPEN_ENDED = /\(?[0-9]+\+\)?/
|
|
9
9
|
|
|
10
10
|
def initialize(range_string)
|
|
11
11
|
@range_string = range_string
|
|
@@ -20,7 +20,7 @@ module SolidusVolumePricing
|
|
|
20
20
|
def options_from_string
|
|
21
21
|
case range_string
|
|
22
22
|
when OPEN_ENDED
|
|
23
|
-
[range_string.tr("^0-9",
|
|
23
|
+
[range_string.tr("^0-9", "").to_i, Float::INFINITY]
|
|
24
24
|
when RANGE_FORMAT
|
|
25
25
|
[
|
|
26
26
|
Regexp.last_match[1].to_i,
|
|
@@ -29,7 +29,7 @@ module SolidusVolumePricing
|
|
|
29
29
|
]
|
|
30
30
|
else
|
|
31
31
|
raise ArgumentError,
|
|
32
|
-
I18n.t(:could_not_convert_to_range, scope:
|
|
32
|
+
I18n.t(:could_not_convert_to_range, scope: "activerecord.errors.messages", string: range_string)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
FactoryBot.define do
|
|
4
|
-
factory :volume_price, class:
|
|
4
|
+
factory :volume_price, class: "Spree::VolumePrice" do
|
|
5
5
|
amount { 10 }
|
|
6
|
-
discount_type {
|
|
7
|
-
range {
|
|
6
|
+
discount_type { "price" }
|
|
7
|
+
range { "(1..5)" }
|
|
8
8
|
association :variant
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
factory :volume_price_model, class:
|
|
12
|
-
name {
|
|
11
|
+
factory :volume_price_model, class: "Spree::VolumePriceModel" do
|
|
12
|
+
name { "name" }
|
|
13
13
|
end
|
|
14
14
|
end
|