Skip to content

Commit

Permalink
Add promotion-specific configuration to Spree::Core::PromotionConfigu…
Browse files Browse the repository at this point in the history
…ration

We want to be able to move all promotion-related things out of
`solidus_core` in PR solidusio#5634. However, Spree::AppConfiguration also does
all the promotion-specific things, and we can't move the app
configuration out of core.

In solidusio#5658, we've added a promotion configuration object as a nucleus for
core's promotion system's configuration,
`Spree::Core::PromotionConfiguration`. This implements all the
promotion-specific configuration preferences from
`Spree::AppConfiguration` there.
  • Loading branch information
mamhoff authored and spaghetticode committed Feb 26, 2024
1 parent 28c97ca commit dc3e15a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
37 changes: 36 additions & 1 deletion core/lib/spree/core/promotion_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,44 @@

module Spree
module Core
class PromotionConfiguration
class PromotionConfiguration < Spree::Preferences::Configuration
include Core::EnvironmentExtension

# @!attribute [rw] promotions_per_page
# @return [Integer] Promotions to show per-page in the admin (default: +15+)
preference :promotions_per_page, :integer, default: 15

# promotion_chooser_class allows extensions to provide their own PromotionChooser
class_name_attribute :promotion_chooser_class, default: 'Spree::PromotionChooser'

# promotion_adjuster_class allows extensions to provide their own Promotion Adjuster
class_name_attribute :promotion_adjuster_class, default: 'Spree::Promotion::OrderAdjustmentsRecalculator'

# Allows providing a different shipping promotion handler.
# @!attribute [rw] shipping_promotion_handler_class
# @see Spree::PromotionHandler::Shipping
# @return [Class] an object that conforms to the API of
# the standard shipping promotion handler class
# Spree::PromotionHandler::Coupon.
class_name_attribute :shipping_promotion_handler_class, default: 'Spree::PromotionHandler::Shipping'

# Allows providing your own Mailer for promotion code batch mailer.
#
# @!attribute [rw] promotion_code_batch_mailer_class
# @return [ActionMailer::Base] an object that responds to "promotion_code_batch_finished",
# and "promotion_code_batch_errored"
# (e.g. an ActionMailer with a "promotion_code_batch_finished" method) with the same
# signature as Spree::PromotionCodeBatchMailer.promotion_code_batch_finished.
class_name_attribute :promotion_code_batch_mailer_class, default: 'Spree::PromotionCodeBatchMailer'

# Allows providing a different coupon code handler.
# @!attribute [rw] coupon_code_handler_class
# @see Spree::PromotionHandler::Coupon
# @return [Class] an object that conforms to the API of
# the standard coupon code handler class
# Spree::PromotionHandler::Coupon.
class_name_attribute :coupon_code_handler_class, default: 'Spree::PromotionHandler::Coupon'

add_nested_class_set :calculators, default: {
"Spree::Promotion::Actions::CreateAdjustment" => %w[
Spree::Calculator::FlatPercentItemTotal
Expand Down
20 changes: 19 additions & 1 deletion core/spec/lib/spree/core/promotion_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@
require "rails_helper"

RSpec.describe Spree::Core::PromotionConfiguration do
subject(:config) { described_class.new }

it "uses base searcher class by default" do
expect(config.promotion_chooser_class).to eq Spree::PromotionChooser
end

it "uses order adjustments recalculator class by default" do
expect(config.promotion_adjuster_class).to eq Spree::Promotion::OrderAdjustmentsRecalculator
end

it "uses promotion handler coupon class by default" do
expect(config.coupon_code_handler_class).to eq Spree::PromotionHandler::Coupon
end

it "uses promotion handler shipping class by default" do
expect(config.shipping_promotion_handler_class).to eq Spree::PromotionHandler::Shipping
end

describe "#calculators" do
subject { described_class.new.calculators[promotion_action] }
subject { config.calculators[promotion_action] }

context "for Spree::Promotion::Actions::CreateAdjustment" do
let(:promotion_action) { Spree::Promotion::Actions::CreateAdjustment }
Expand Down

0 comments on commit dc3e15a

Please sign in to comment.