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

Make promotion handler classes configurable #5466

Merged
merged 2 commits into from
Oct 30, 2023
Merged
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
4 changes: 2 additions & 2 deletions api/app/controllers/spree/api/coupon_codes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def create
authorize! :update, @order, order_token

@order.coupon_code = params[:coupon_code]
@handler = PromotionHandler::Coupon.new(@order).apply
@handler = Spree::Config.coupon_code_handler_class.new(@order).apply

if @handler.successful?
render 'spree/api/promotions/handler', status: 200
Expand All @@ -24,7 +24,7 @@ def destroy
authorize! :update, @order, order_token

@order.coupon_code = params[:id]
@handler = PromotionHandler::Coupon.new(@order).remove
@handler = Spree::Config.coupon_code_handler_class.new(@order).remove

if @handler.successful?
render 'spree/api/promotions/handler', status: 200
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def create_shipments_for_line_item(line_item)
end

def apply_shipping_promotions
Spree::PromotionHandler::Shipping.new(self).activate
Spree::Config.shipping_promotion_handler_class.new(self).activate
recalculate
end

Expand Down
16 changes: 16 additions & 0 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,22 @@ def default_pricing_options
# Spree::OrderUpdater.
class_name_attribute :order_recalculator_class, default: 'Spree::OrderUpdater'

# 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 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
Expand Down
8 changes: 8 additions & 0 deletions core/spec/lib/spree/app_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
expect(prefs.promotion_adjuster_class).to eq Spree::Promotion::OrderAdjustmentsRecalculator
end

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

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

it "has a getter for the pricing options class provided by the variant price selector class" do
expect(prefs.pricing_options_class).to eq Spree::Variant::PriceSelector.pricing_options_class
end
Expand Down
Loading