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

[pull] main from solidusio:main #398

Merged
merged 26 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5eabcfe
Use routing proxy in locale selection
mamhoff Jan 22, 2024
49af699
Deprecate Spree::Adjustment#recalculate
mamhoff Jan 27, 2024
7ff5b8c
Adjustment factory: Don't use #recalculate
mamhoff Jan 27, 2024
d9971f3
Remove promotion from cancellations spec
mamhoff Jan 27, 2024
4015a30
Extract shared examples for order factory
mamhoff Jan 27, 2024
b61f3c8
Make calculator shared examples requirable
mamhoff Jan 26, 2024
fc95b15
Make DummyAbility require-able
mamhoff Jan 26, 2024
8823049
Extract "working factories" into lib/
mamhoff Jan 26, 2024
545a0e8
Add promotion-specific configuration to Spree::Core::PromotionConfigu…
mamhoff Jan 29, 2024
e494ec2
Deprecate and delegate promotion-specific config from Spree::Config
mamhoff Jan 29, 2024
ec19538
Deprecate and delegate Spree::Core::Environment::Promotions
mamhoff Jan 29, 2024
df737dd
Use new promotion configuration across the project
mamhoff Jan 29, 2024
4b4f8ea
Make Spree::Deprecator available in unit tests
mamhoff Feb 17, 2024
05ad736
Add extension point for promotion source types
mamhoff Jan 25, 2024
d0bf433
Use new extension point for promotion adjustment source types
mamhoff Jan 25, 2024
28c97ca
Merge pull request #5665 from mamhoff/legacy-promos-prep/configurable…
kennyadsl Feb 22, 2024
91544f4
Merge pull request #5635 from mamhoff/promotion-configuration
kennyadsl Feb 22, 2024
637dbad
Merge pull request #5639 from mamhoff/legacy-promos-prep/simplify-can…
kennyadsl Feb 22, 2024
e3adb71
Add extension point: Promotion Configuration class
mamhoff Feb 17, 2024
da78680
Introduce a NullAdjuster
mamhoff Jan 26, 2024
dac45b7
Introduce Null Promotion Handler
mamhoff Jan 26, 2024
e29983f
Add a Null promotion configuration
mamhoff Feb 17, 2024
2f2bd69
Merge pull request #5667 from mamhoff/null-promo-config
kennyadsl Feb 27, 2024
b8a277d
Merge pull request #5640 from mamhoff/legacy-promos-prep/extract-shar…
tvdeyen Feb 27, 2024
b532f94
Merge pull request #5611 from mamhoff/locale-selecation-solidus-admin…
tvdeyen Feb 27, 2024
928781f
Merge pull request #5632 from mamhoff/deprecate-adjustment-recalculate
tvdeyen Feb 27, 2024
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 = Spree::Config.coupon_code_handler_class.new(@order).apply
@handler = Spree::Config.promotions.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 = Spree::Config.coupon_code_handler_class.new(@order).remove
@handler = Spree::Config.promotions.coupon_code_handler_class.new(@order).remove

if @handler.successful?
render 'spree/api/promotions/handler', status: 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def load_promotion

def validate_promotion_action_type
requested_type = params[:action_type]
promotion_action_types = Rails.application.config.spree.promotions.actions
promotion_action_types = Spree::Config.promotions.actions
@promotion_action_type = promotion_action_types.detect do |klass|
klass.name == requested_type
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def model_class

def validate_promotion_rule_type
requested_type = params[:promotion_rule].delete(:type)
promotion_rule_types = Rails.application.config.spree.promotions.rules
promotion_rule_types = Spree::Config.promotions.rules
@promotion_rule_type = promotion_rule_types.detect do |klass|
klass.name == requested_type
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def collection
@collection = @search.result(distinct: true).
includes(promotion_includes).
page(params[:page]).
per(params[:per_page] || Spree::Config[:promotions_per_page])
per(params[:per_page] || Spree::Config.promotions.promotions_per_page)

@collection
end
Expand Down
2 changes: 1 addition & 1 deletion backend/app/helpers/spree/promotion_rules_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Spree
module PromotionRulesHelper
def options_for_promotion_rule_types(promotion)
existing = promotion.rules.map { |rule| rule.class.name }
rules = Rails.application.config.spree.promotions.rules.reject { |rule| existing.include? rule.name }
rules = Spree::Config.promotions.rules.reject { |rule| existing.include? rule.name }
options = rules.map { |rule| [rule.model_name.human, rule.name] }
options_for_select(options)
end
Expand Down
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/promotions/_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<fieldset id="action_fields" class="no-border-top">

<%= form_tag spree.admin_promotion_promotion_actions_path(@promotion), remote: true, id: 'new_promotion_action_form' do %>
<% options = options_for_select( Rails.application.config.spree.promotions.actions.map {|action| [ action.model_name.human, action.name] } ) %>
<% options = options_for_select(Spree::Config.promotions.actions.map {|action| [ action.model_name.human, action.name] } ) %>
<fieldset>
<legend align="center"><%= t('spree.promotion_actions') %></legend>
<% if can?(:update, @promotion) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
}.sort %>

<% if available_locale_options_for_select.size > 1 %>
<%= form_tag(admin_set_locale_path(format: :html), method: :put, style: "width: 100%;") do %>
<%= form_tag(spree.admin_set_locale_path(format: :html), method: :put, style: "width: 100%;") do %>
<label class="admin-navbar-selection admin-locale-selection">
<i class="fa fa-globe fa-fw" title="<%= I18n.t('spree.choose_dashboard_locale') %>"></i>
<select class="custom-select fullwidth" onchange="this.form.requestSubmit()">
Expand Down
6 changes: 3 additions & 3 deletions backend/spec/features/admin/promotion_adjustments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ def self.description
"Complex Calculator"
end
end
@calculators = Rails.application.config.spree.calculators.promotion_actions_create_item_adjustments
Rails.application.config.spree.calculators.promotion_actions_create_item_adjustments = [ComplexCalculator]
@calculators = Spree::Config.promotions.calculators['Spree::Promotion::Actions::CreateItemAdjustments']
Spree::Config.promotions.calculators['Spree::Promotion::Actions::CreateItemAdjustments'] = [ComplexCalculator]
end

after do
Rails.application.config.spree.calculators.promotion_actions_create_item_adjustments = @calculators
Spree::Config.promotions.calculators['Spree::Promotion::Actions::CreateItemAdjustments'] = @calculators
end

it "does not show array and hash form fields" do
Expand Down
4 changes: 2 additions & 2 deletions core/app/jobs/spree/promotion_code_batch_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def perform(promotion_code_batch)
).build_promotion_codes

if promotion_code_batch.email?
Spree::Config.promotion_code_batch_mailer_class
Spree::Config.promotions.promotion_code_batch_mailer_class
.promotion_code_batch_finished(promotion_code_batch)
.deliver_now
end
rescue StandardError => error
if promotion_code_batch.email?
Spree::Config.promotion_code_batch_mailer_class
Spree::Config.promotions.promotion_code_batch_mailer_class
.promotion_code_batch_errored(promotion_code_batch)
.deliver_now
end
Expand Down
7 changes: 4 additions & 3 deletions core/app/models/spree/adjustment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Adjustment < Spree::Base
scope :charge, -> { where("#{quoted_table_name}.amount >= 0") }
scope :credit, -> { where("#{quoted_table_name}.amount < 0") }
scope :nonzero, -> { where("#{quoted_table_name}.amount != 0") }
scope :promotion, -> { where(source_type: 'Spree::PromotionAction') }
scope :non_promotion, -> { where.not(source_type: 'Spree::PromotionAction') }
scope :promotion, -> { where(source_type: Spree::Config.adjustment_promotion_source_types.map(&:to_s)) }
scope :non_promotion, -> { where.not(source_type: Spree::Config.adjustment_promotion_source_types.map(&:to_s)) }
scope :return_authorization, -> { where(source_type: "Spree::ReturnAuthorization") }
scope :is_included, -> { where(included: true) }
scope :additional, -> { where(included: false) }
Expand Down Expand Up @@ -77,7 +77,7 @@ def currency

# @return [Boolean] true when this is a promotion adjustment (Promotion adjustments have a {PromotionAction} source)
def promotion?
source_type == 'Spree::PromotionAction'
source_type.to_s.in?(Spree::Config.adjustment_promotion_source_types.map(&:to_s))
end

# @return [Boolean] true when this is a tax adjustment (Tax adjustments have a {TaxRate} source)
Expand Down Expand Up @@ -122,6 +122,7 @@ def recalculate
end
amount
end
deprecate :recalculate, deprecator: Spree.deprecator

# Calculates based on attached promotion (if this is a promotion
# adjustment) whether this promotion is still eligible.
Expand Down
13 changes: 13 additions & 0 deletions core/app/models/spree/null_promotion_adjuster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Spree
class NullPromotionAdjuster
def initialize(order)
@order = order
end

def call
@order
end
end
end
36 changes: 36 additions & 0 deletions core/app/models/spree/null_promotion_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module Spree
class NullPromotionHandler
attr_reader :order, :coupon_code

def initialize(order)
@order = order
@coupon_code = order.coupon_code&.downcase
end

def activate
@order
end

def error
nil
end

def success
true
end

def successful?
true
end

def status_code
:coupon_code_applied
end

def status
I18n.t(:coupon_code_applied, scope: [:spree, :null_promotion_handler])
end
end
end
4 changes: 2 additions & 2 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def create_shipments_for_line_item(line_item)
end

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

Expand Down Expand Up @@ -799,7 +799,7 @@ def ensure_inventory_units
end

def ensure_promotions_eligible
Spree::Config.promotion_adjuster_class.new(self).call
Spree::Config.promotions.promotion_adjuster_class.new(self).call

if promo_total_changed?
restart_checkout_flow
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/order_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def log_state_change(name)
end

def update_promotions
Spree::Config.promotion_adjuster_class.new(order).call
Spree::Config.promotions.promotion_adjuster_class.new(order).call
end

def update_taxes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def call
promotion_adjustments = item.adjustments.select(&:promotion?)

promotion_adjustments.each { |adjustment| recalculate(adjustment) }
Spree::Config.promotion_chooser_class.new(promotion_adjustments).update
Spree::Config.promotions.promotion_chooser_class.new(promotion_adjustments).update

item.promo_total = promotion_adjustments.select(&:eligible?).sum(&:amount)
end
Expand All @@ -30,7 +30,7 @@ def call
# line items and/or shipments.
order_promotion_adjustments = order.adjustments.select(&:promotion?)
order_promotion_adjustments.each { |adjustment| recalculate(adjustment) }
Spree::Config.promotion_chooser_class.new(order_promotion_adjustments).update
Spree::Config.promotions.promotion_chooser_class.new(order_promotion_adjustments).update

order.promo_total = all_items.sum(&:promo_total) +
order_promotion_adjustments.
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/promotion_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PromotionAction < Spree::Base
belongs_to :promotion, class_name: 'Spree::Promotion', inverse_of: :promotion_actions, optional: true

scope :of_type, ->(type) { where(type: Array.wrap(type).map(&:to_s)) }
scope :shipping, -> { of_type(Spree::Config.environment.promotions.shipping_actions.to_a) }
scope :shipping, -> { of_type(Spree::Config.promotions.shipping_actions.to_a) }

def preload_relations
[]
Expand Down
2 changes: 2 additions & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,8 @@ en:
product_not_deleted: Product could not be deleted
variant_deleted: Variant has been deleted
variant_not_deleted: Variant could not be deleted
null_promotion_handler:
coupon_code_applied: Coupon code has been applied.
num_orders: "# Orders"
number: Number
number_of_codes: "%{count} codes"
Expand Down
Loading
Loading