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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.git-blame-ignore-revs +3 -0
  3. data/.github/workflows/lint.yml +25 -0
  4. data/.github/workflows/test.yml +59 -0
  5. data/.rubocop.yml +0 -5
  6. data/Gemfile +21 -23
  7. data/Guardfile +8 -8
  8. data/README.md +1 -1
  9. data/Rakefile +3 -3
  10. data/app/models/solidus_volume_pricing/pricer.rb +9 -9
  11. data/app/models/solidus_volume_pricing/pricing_options.rb +2 -2
  12. data/app/models/spree/volume_price.rb +8 -8
  13. data/app/patches/helpers/solidus_volume_pricing/spree_base_helper_patch.rb +29 -0
  14. data/app/patches/models/solidus_volume_pricing/spree_line_item_patch.rb +18 -0
  15. data/app/patches/models/solidus_volume_pricing/spree_variant_patch.rb +21 -0
  16. data/bin/rails-engine +6 -6
  17. data/bin/rails-sandbox +4 -4
  18. data/config/routes.rb +1 -1
  19. data/db/migrate/20150603143015_create_spree_volume_price_models.rb +2 -2
  20. data/lib/generators/solidus_volume_pricing/install/install_generator.rb +4 -4
  21. data/lib/patches/backend/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb +38 -0
  22. data/lib/solidus_volume_pricing/engine.rb +22 -11
  23. data/lib/solidus_volume_pricing/range_from_string.rb +4 -4
  24. data/lib/solidus_volume_pricing/testing_support/factories.rb +5 -5
  25. data/lib/solidus_volume_pricing/version.rb +1 -1
  26. data/lib/solidus_volume_pricing.rb +9 -9
  27. data/solidus_volume_pricing.gemspec +20 -21
  28. metadata +41 -63
  29. data/.circleci/config.yml +0 -73
  30. data/.rubocop_todo.yml +0 -68
  31. data/app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb +0 -42
  32. data/app/decorators/helpers/solidus_volume_pricing/spree/base_helper_decorator.rb +0 -31
  33. data/app/decorators/models/solidus_volume_pricing/spree/line_item_decorator.rb +0 -18
  34. data/app/decorators/models/solidus_volume_pricing/spree/variant_decorator.rb +0 -23
  35. data/spec/controllers/spree/admin/variants_controller_spec.rb +0 -30
  36. data/spec/features/manage_volume_price_models_feature_spec.rb +0 -24
  37. data/spec/features/manage_volume_prices_feature_spec.rb +0 -33
  38. data/spec/helpers/base_helper_spec.rb +0 -24
  39. data/spec/lib/solidus_volume_pricing/range_from_string_spec.rb +0 -61
  40. data/spec/models/solidus_volume_pricing/pricer_spec.rb +0 -669
  41. data/spec/models/solidus_volume_pricing/pricing_options_spec.rb +0 -57
  42. data/spec/models/spree/line_item_spec.rb +0 -36
  43. data/spec/models/spree/order_spec.rb +0 -51
  44. data/spec/models/spree/variant_spec.rb +0 -6
  45. data/spec/models/spree/volume_price_spec.rb +0 -216
  46. data/spec/spec_helper.rb +0 -32
  47. data/spec/support/shoulda.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4851ed1cbff2d8a6b293bb4e13004c3d029904ac9b77f184d18d25c0165868d9
4
- data.tar.gz: 3a8471044299dff716a3d99551dfe353d6aff0b41213288e7e808ec8a7d0f0ad
3
+ metadata.gz: d4b9c4e9d82bacce19b43bf6e8bca28b72b0caec7bc188cff10eac7ed2ca99f0
4
+ data.tar.gz: 24f362ea97f9538968ace48ee5fdf9889b68909fc2a7f9ccdbe24a346734a743
5
5
  SHA512:
6
- metadata.gz: eb6a8e0e5e693b25583d7648a42375c6a11ae0afdbd7a6435306ec9cfc159848ce062a0b1f73ca953bbf9ddf48b12266bd95fcdda5e0d3a04a0aca28205c193f
7
- data.tar.gz: 30aff993f5ed9e502533377c770d252064e5fd77b503024e5cab0759dc9a445396f0bad14b81da672d2bafdccef67d73d5ab295af9459de470da4e4c53d13d9a
6
+ metadata.gz: fa54524394df01a87eae968ae4494737295c465b20add1f550cb3f4b38340850e4c1148da3cf0aac017472a7bed7a9a71a5263fd31b8bf4ca58c739f06844691
7
+ data.tar.gz: 61ad6b3fb17aa88af304c150d787014b8b29c4917b7d0ae813b69cf4fc7138d7ee9c58a6724458c6c319f72e8d56da599ff38c9983da74d05c0454dd0048d362
@@ -0,0 +1,3 @@
1
+ # .git-blame-ignore-revs
2
+ # Convert to standardrb
3
+ 31ef17ec3b4fdbb4c8fce4c34414b914e3bc59b3
@@ -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
@@ -1,7 +1,2 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
1
  require:
4
2
  - solidus_dev_support/rubocop
5
-
6
- AllCops:
7
- NewCops: disable
data/Gemfile CHANGED
@@ -1,41 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
5
 
6
- branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
7
- gem 'solidus', github: 'solidusio/solidus', branch: branch
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 'solidus_frontend'
12
+ gem "solidus_frontend"
11
13
 
12
- # Needed to help Bundler figure out how to resolve dependencies,
13
- # otherwise it takes forever to resolve them.
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 'solidus_auth_devise'
18
+ gem "solidus_auth_devise"
19
19
 
20
- case ENV.fetch('DB', nil)
21
- when 'mysql'
22
- gem 'mysql2'
23
- when 'postgresql'
24
- gem 'pg'
20
+ case ENV.fetch("DB", nil)
21
+ when "mysql"
22
+ gem "mysql2"
23
+ when "postgresql"
24
+ gem "pg"
25
25
  else
26
- gem 'sqlite3'
27
- end
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
- gemspec
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, 'Gemfile-local') if File.exist? 'Gemfile-local'
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 '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" }
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
- [![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_volume_pricing.svg?style=svg)](https://circleci.com/gh/solidusio-contrib/solidus_volume_pricing)
3
+ [![Test](https://github.com/solidusio-contrib/solidus_volume_pricing/actions/workflows/test.yml/badge.svg)](https://github.com/solidusio-contrib/solidus_volume_pricing/actions/workflows/test.yml)
4
4
  [![Code Climate](https://codeclimate.com/github/solidusio-contrib/solidus_volume_pricing/badges/gpa.svg)](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 'bundler/gem_tasks'
3
+ require "bundler/gem_tasks"
4
4
 
5
- require 'solidus_dev_support/rake_tasks'
5
+ require "solidus_dev_support/rake_tasks"
6
6
  SolidusDevSupport::RakeTasks.install
7
7
 
8
- task default: 'extension:specs'
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 'price'
57
+ when "price"
58
58
  volume_price.amount
59
- when 'dollar'
59
+ when "dollar"
60
60
  variant.price - volume_price.amount
61
- when 'percent'
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 'price'
70
+ when "price"
71
71
  variant.price - volume_price.amount
72
- when 'dollar'
72
+ when "dollar"
73
73
  volume_price.amount
74
- when 'percent'
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 'price'
83
+ when "price"
84
84
  diff = variant.price - volume_price.amount
85
85
  diff * 100 / variant.price
86
- when 'dollar'
86
+ when "dollar"
87
87
  volume_price.amount * 100 / variant.price
88
- when 'percent'
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 options.except(:quantity, :user)
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(line_item)
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: 'Spree::Role', foreign_key: 'role_id', optional: true
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(price dollar percent)
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('..', __dir__)
6
- ENGINE_PATH = File.expand_path('../lib/solidus_volume_pricing/engine', __dir__)
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['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
10
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
9
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
10
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
11
11
 
12
- require 'rails/all'
13
- require 'rails/engine/commands'
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 = 'sandbox'
3
+ app_root = "sandbox"
4
4
 
5
5
  unless File.exist? "#{app_root}/bin/rails"
6
- warn 'Creating the sandbox app...'
6
+ warn "Creating the sandbox app..."
7
7
  Dir.chdir "#{__dir__}/.." do
8
8
  system "#{__dir__}/sandbox" or begin
9
- warn 'Automatic creation of the sandbox app failed'
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 'bin/rails', *ARGV
16
+ exec "bin/rails", *ARGV
data/config/routes.rb CHANGED
@@ -8,7 +8,7 @@ Spree::Core::Engine.routes.draw do
8
8
  end
9
9
  end
10
10
 
11
- delete '/volume_prices/:id', to: 'volume_prices#destroy', as: :volume_price
11
+ delete "/volume_prices/:id", to: "volume_prices#destroy", as: :volume_price
12
12
  resources :volume_price_models
13
13
  end
14
14
  end
@@ -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: 'volume_price_model_id'
19
- add_index :spree_variants_volume_price_models, :variant_id, name: 'variant_id'
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 'bin/rails railties:install:migrations FROM=solidus_volume_pricing'
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] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
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 'bin/rails db:migrate'
19
+ run "bin/rails db:migrate"
20
20
  else
21
- puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
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
@@ -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 'spree/core'
4
- require 'solidus_support'
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 'solidus_volume_pricing'
12
+ engine_name "solidus_volume_pricing"
13
13
 
14
- initializer 'solidus_volume_pricing.preferences', before: 'spree.environment' do
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
- def self.activate
21
- Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')).sort.each do |c|
22
- Rails.configuration.cache_classes ? require(c) : load(c)
23
- Rails.autoloaders.main.ignore(c) if Rails.autoloaders.zeitwerk_enabled?
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/.freeze
8
- OPEN_ENDED = /\(?[0-9]+\+\)?/.freeze
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", '').to_i, Float::INFINITY]
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: 'activerecord.errors.messages', string: range_string)
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: 'Spree::VolumePrice' do
4
+ factory :volume_price, class: "Spree::VolumePrice" do
5
5
  amount { 10 }
6
- discount_type { 'price' }
7
- range { '(1..5)' }
6
+ discount_type { "price" }
7
+ range { "(1..5)" }
8
8
  association :variant
9
9
  end
10
10
 
11
- factory :volume_price_model, class: 'Spree::VolumePriceModel' do
12
- name { 'name' }
11
+ factory :volume_price_model, class: "Spree::VolumePriceModel" do
12
+ name { "name" }
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusVolumePricing
4
- VERSION = '1.2.0'
4
+ VERSION = "2.0.0"
5
5
  end