Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename PromotionConfiguration to LegacyPromotionConfiguration #5771

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions core/lib/solidus_legacy_promotions/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# frozen_string_literal: true

module SolidusLegacyPromotions
class Configuration < Spree::Preferences::Configuration
include Spree::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

# @!attribute [rw] promotion_attributes
# @return [Array<Symbol>] Attributes to be returned by the API for a promotion
preference :promotion_api_attributes, :array, default: [
:id,
:name,
:description,
:expires_at,
:starts_at,
:type,
:usage_limit,
:advertise,
:path
]

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

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

# promotion_finder_class allows extensions to provide their own Promotion Finder
class_name_attribute :promotion_finder_class, default: 'Spree::PromotionFinder'

# 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'

# Allows providing a different promotion advertiser.
# @!attribute [rw] advertiser_class
# @see Spree::PromotionAdvertiser
# @return [Class] an object that conforms to the API of
# the standard promotion advertiser class
# Spree::PromotionAdvertiser.
class_name_attribute :advertiser_class, default: 'Spree::PromotionAdvertiser'

add_class_set :rules, default: %w[
Spree::Promotion::Rules::ItemTotal
Spree::Promotion::Rules::Product
Spree::Promotion::Rules::User
Spree::Promotion::Rules::FirstOrder
Spree::Promotion::Rules::UserLoggedIn
Spree::Promotion::Rules::OneUsePerUser
Spree::Promotion::Rules::Taxon
Spree::Promotion::Rules::MinimumQuantity
Spree::Promotion::Rules::NthOrder
Spree::Promotion::Rules::OptionValue
Spree::Promotion::Rules::FirstRepeatPurchaseSince
Spree::Promotion::Rules::UserRole
Spree::Promotion::Rules::Store
]

add_class_set :actions, default: %w[
Spree::Promotion::Actions::CreateAdjustment
Spree::Promotion::Actions::CreateItemAdjustments
Spree::Promotion::Actions::CreateQuantityAdjustments
Spree::Promotion::Actions::FreeShipping
]

add_class_set :shipping_actions, default: %w[
Spree::Promotion::Actions::FreeShipping
]

add_nested_class_set :calculators, default: {
"Spree::Promotion::Actions::CreateAdjustment" => %w[
Spree::Calculator::FlatPercentItemTotal
Spree::Calculator::FlatRate
Spree::Calculator::FlexiRate
Spree::Calculator::TieredPercent
Spree::Calculator::TieredFlatRate
],
"Spree::Promotion::Actions::CreateItemAdjustments" => %w[
Spree::Calculator::DistributedAmount
Spree::Calculator::FlatRate
Spree::Calculator::FlexiRate
Spree::Calculator::PercentOnLineItem
Spree::Calculator::TieredPercent
],
"Spree::Promotion::Actions::CreateQuantityAdjustments" => %w[
Spree::Calculator::PercentOnLineItem
Spree::Calculator::FlatRate
]
}
end
end
8 changes: 5 additions & 3 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,13 @@ def stock

# Allows providing your own promotion configuration instance
# @!attribute [rw] promotions
# @return [Spree::Core::PromotionConfiguration] an object that conforms to the API of
# the standard promotion configuration class Spree::Core::PromotionConfiguration.
# @return [Spree::Core::NullPromotionConfiguration] an object that conforms to the API of
# the example promotion configuration class Spree::Core::NullPromotionConfiguration.
# Currently, this defaults to the legacy promotion configuration, until that system is fully extracted
# to the `solidus_legacy_promotions` gem.
attr_writer :promotions
def promotions
@promotions ||= Spree::Core::PromotionConfiguration.new
@promotions ||= SolidusLegacyPromotions::Configuration.new
end

class << self
Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class GatewayError < RuntimeError; end
require 'spree/core/role_configuration'
require 'spree/core/state_machines'
require 'spree/core/stock_configuration'
require 'spree/core/promotion_configuration'
require 'solidus_legacy_promotions/configuration'
require 'spree/core/null_promotion_configuration'
require 'spree/core/validators/email'
require 'spree/permission_sets'
Expand Down
117 changes: 0 additions & 117 deletions core/lib/spree/core/promotion_configuration.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rails_helper"

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

it "uses base searcher class by default" do
Expand Down
4 changes: 2 additions & 2 deletions core/spec/lib/spree/app_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
end

it "uses core's promotion configuration class by default" do
expect(prefs.promotions).to be_a Spree::Core::PromotionConfiguration
expect(prefs.promotions).to be_a SolidusLegacyPromotions::Configuration
end

context "deprecated preferences" do
Expand Down Expand Up @@ -113,7 +113,7 @@

describe '#promotions' do
subject { prefs.promotions }
it { is_expected.to be_a Spree::Core::PromotionConfiguration }
it { is_expected.to be_a SolidusLegacyPromotions::Configuration }
end

describe '@default_country_iso_code' do
Expand Down
Loading