diff --git a/Gemfile b/Gemfile index dd357ea99bf..3b31729a798 100644 --- a/Gemfile +++ b/Gemfile @@ -68,6 +68,7 @@ end group :legacy_promotions, :promotions do gem 'solidus_legacy_promotions', path: 'legacy_promotions', require: false gem 'solidus_backend', path: 'backend', require: false + gem 'solidus_support', github: "mamhoff/solidus_support", branch: "re-enable-flickwerk" end group :promotions do diff --git a/core/app/models/spree/core/state_machines/order.rb b/core/app/models/spree/core/state_machines/order.rb index 691b20e212a..49db2035dd6 100644 --- a/core/app/models/spree/core/state_machines/order.rb +++ b/core/app/models/spree/core/state_machines/order.rb @@ -8,214 +8,6 @@ def self.included(klass) klass.extend ClassMethods end - module ClassMethods - attr_accessor :previous_states - attr_writer :next_event_transitions, :checkout_steps, :removed_transitions - - def checkout_flow(&block) - if block_given? - @checkout_flow = block - define_state_machine! - else - @checkout_flow - end - end - - def define_state_machine! - self.checkout_steps = {} - self.next_event_transitions = [] - self.previous_states = [:cart] - self.removed_transitions = [] - - # Build the checkout flow using the checkout_flow defined either - # within the Order class, or a decorator for that class. - # - # This method may be called multiple times depending on if the - # checkout_flow is re-defined in a decorator or not. - instance_eval(&checkout_flow) - - klass = self - - # To avoid multiple occurrences of the same transition being defined - # On first definition, state_machines will not be defined - state_machines.clear if respond_to?(:state_machines) - state_machine :state, initial: :cart, use_transactions: false do - klass.next_event_transitions.each { |state| transition(state.merge(on: :next)) } - - # Persist the state on the order - after_transition do |order, transition| - # Hard to say if this is really necessary, it was introduced in this commit: - # https://github.com/mamhoff/solidus/commit/fa1d66c42e4c04ee7cd1c20d87e4cdb74a226d3d - # But it seems to be harmless, so we'll keep it for now. - order.state = order.state # rubocop:disable Lint/SelfAssignment - - order.state_changes.create( - previous_state: transition.from, - next_state: transition.to, - name: 'order', - user_id: order.user_id - ) - order.save - end - - event :cancel do - transition to: :canceled, if: :allow_cancel?, from: :complete - end - - event :return do - transition to: :returned, from: [:complete, :awaiting_return], if: :all_inventory_units_returned? - end - - event :resume do - transition to: :resumed, from: :canceled, if: :canceled? - end - - event :authorize_return do - transition to: :awaiting_return, from: :complete - end - - event :complete do - transition to: :complete, from: klass.checkout_steps.keys.last - end - - if states[:payment] - event :payment_failed do - transition to: :payment, from: :confirm - end - - after_transition to: :complete, do: :add_payment_sources_to_wallet - before_transition to: :payment, do: :add_default_payment_from_wallet - before_transition to: :payment, do: :ensure_billing_address - - before_transition to: :confirm, do: :add_store_credit_payments - - # see also process_payments_before_complete below which needs to - # be added in the correct sequence. - end - - before_transition from: :cart, do: :ensure_line_items_present - - if states[:address] - before_transition to: :address, do: :assign_default_user_addresses - before_transition from: :address, do: :persist_user_address! - end - - if states[:delivery] - before_transition to: :delivery, do: :ensure_shipping_address - before_transition to: :delivery, do: :create_proposed_shipments - before_transition to: :delivery, do: :ensure_available_shipping_rates - end - - before_transition to: :resumed, do: :ensure_line_item_variants_are_not_deleted - before_transition to: :resumed, do: :validate_line_item_availability - - # Sequence of before_transition to: :complete - # calls matter so that we do not process payments - # until validations have passed - before_transition to: :complete, do: :validate_line_item_availability - before_transition to: :complete, do: :ensure_promotions_eligible - before_transition to: :complete, do: :ensure_line_item_variants_are_not_deleted - before_transition to: :complete, do: :ensure_inventory_units - if states[:payment] - before_transition to: :complete, do: :process_payments_before_complete - end - - after_transition to: :complete, do: :finalize - after_transition to: :resumed, do: :after_resume - after_transition to: :canceled, do: :after_cancel - - after_transition from: any - :cart, to: any - [:confirm, :complete] do |order| - order.recalculate - end - - after_transition do |order, transition| - order.logger.debug "Order #{order.number} transitioned from #{transition.from} to #{transition.to} via #{transition.event}" - end - - after_failure do |order, transition| - order.logger.debug "Order #{order.number} halted transition on event #{transition.event} state #{transition.from}: #{order.errors.full_messages.join}" - end - end - end - - def go_to_state(name, options = {}) - checkout_steps[name] = options - previous_states.each do |state| - add_transition({ from: state, to: name }.merge(options)) - end - if options[:if] - previous_states << name - else - self.previous_states = [name] - end - end - - def insert_checkout_step(name, options = {}) - before = options.delete(:before) - after = options.delete(:after) unless before - after = checkout_steps.keys.last unless before || after - - cloned_steps = checkout_steps.clone - cloned_removed_transitions = removed_transitions.clone - checkout_flow do - cloned_steps.each_pair do |key, value| - go_to_state(name, options) if key == before - go_to_state(key, value) - go_to_state(name, options) if key == after - end - cloned_removed_transitions.each do |transition| - remove_transition(transition) - end - end - end - - def remove_checkout_step(name) - cloned_steps = checkout_steps.clone - cloned_removed_transitions = removed_transitions.clone - checkout_flow do - cloned_steps.each_pair do |key, value| - go_to_state(key, value) unless key == name - end - cloned_removed_transitions.each do |transition| - remove_transition(transition) - end - end - end - - def remove_transition(options = {}) - removed_transitions << options - next_event_transitions.delete(find_transition(options)) - end - - def find_transition(options = {}) - return nil if options.nil? || !options.include?(:from) || !options.include?(:to) - - next_event_transitions.detect do |transition| - transition[options[:from].to_sym] == options[:to].to_sym - end - end - - def next_event_transitions - @next_event_transitions ||= [] - end - - def checkout_steps - @checkout_steps ||= {} - end - - def checkout_step_names - checkout_steps.keys - end - - def add_transition(options) - next_event_transitions << { options.delete(:from) => options.delete(:to) }.merge(options) - end - - def removed_transitions - @removed_transitions ||= [] - end - end - def checkout_steps steps = self.class.checkout_steps.each_with_object([]) { |(step, options), checkout_steps| next if options.include?(:if) && !options[:if].call(self) diff --git a/core/app/models/spree/core/state_machines/order/class_methods.rb b/core/app/models/spree/core/state_machines/order/class_methods.rb new file mode 100644 index 00000000000..689e4f18659 --- /dev/null +++ b/core/app/models/spree/core/state_machines/order/class_methods.rb @@ -0,0 +1,217 @@ +# frozen_string_literal: true + +module Spree + module Core + class StateMachines + module Order + module ClassMethods + attr_accessor :previous_states + attr_writer :next_event_transitions, :checkout_steps, :removed_transitions + + def checkout_flow(&block) + if block_given? + @checkout_flow = block + define_state_machine! + else + @checkout_flow + end + end + + def define_state_machine! + self.checkout_steps = {} + self.next_event_transitions = [] + self.previous_states = [:cart] + self.removed_transitions = [] + + # Build the checkout flow using the checkout_flow defined either + # within the Order class, or a decorator for that class. + # + # This method may be called multiple times depending on if the + # checkout_flow is re-defined in a decorator or not. + instance_eval(&checkout_flow) + + klass = self + + # To avoid multiple occurrences of the same transition being defined + # On first definition, state_machines will not be defined + state_machines.clear if respond_to?(:state_machines) + state_machine :state, initial: :cart, use_transactions: false do + klass.next_event_transitions.each { |state| transition(state.merge(on: :next)) } + + # Persist the state on the order + after_transition do |order, transition| + # Hard to say if this is really necessary, it was introduced in this commit: + # https://github.com/mamhoff/solidus/commit/fa1d66c42e4c04ee7cd1c20d87e4cdb74a226d3d + # But it seems to be harmless, so we'll keep it for now. + order.state = order.state # rubocop:disable Lint/SelfAssignment + + order.state_changes.create( + previous_state: transition.from, + next_state: transition.to, + name: 'order', + user_id: order.user_id + ) + order.save + end + + event :cancel do + transition to: :canceled, if: :allow_cancel?, from: :complete + end + + event :return do + transition to: :returned, from: [:complete, :awaiting_return], if: :all_inventory_units_returned? + end + + event :resume do + transition to: :resumed, from: :canceled, if: :canceled? + end + + event :authorize_return do + transition to: :awaiting_return, from: :complete + end + + event :complete do + transition to: :complete, from: klass.checkout_steps.keys.last + end + + if states[:payment] + event :payment_failed do + transition to: :payment, from: :confirm + end + + after_transition to: :complete, do: :add_payment_sources_to_wallet + before_transition to: :payment, do: :add_default_payment_from_wallet + before_transition to: :payment, do: :ensure_billing_address + + before_transition to: :confirm, do: :add_store_credit_payments + + # see also process_payments_before_complete below which needs to + # be added in the correct sequence. + end + + before_transition from: :cart, do: :ensure_line_items_present + + if states[:address] + before_transition to: :address, do: :assign_default_user_addresses + before_transition from: :address, do: :persist_user_address! + end + + if states[:delivery] + before_transition to: :delivery, do: :ensure_shipping_address + before_transition to: :delivery, do: :create_proposed_shipments + before_transition to: :delivery, do: :ensure_available_shipping_rates + end + + before_transition to: :resumed, do: :ensure_line_item_variants_are_not_deleted + before_transition to: :resumed, do: :validate_line_item_availability + + # Sequence of before_transition to: :complete + # calls matter so that we do not process payments + # until validations have passed + before_transition to: :complete, do: :validate_line_item_availability + before_transition to: :complete, do: :ensure_promotions_eligible + before_transition to: :complete, do: :ensure_line_item_variants_are_not_deleted + before_transition to: :complete, do: :ensure_inventory_units + if states[:payment] + before_transition to: :complete, do: :process_payments_before_complete + end + + after_transition to: :complete, do: :finalize + after_transition to: :resumed, do: :after_resume + after_transition to: :canceled, do: :after_cancel + + after_transition from: any - :cart, to: any - [:confirm, :complete] do |order| + order.recalculate + end + + after_transition do |order, transition| + order.logger.debug "Order #{order.number} transitioned from #{transition.from} to #{transition.to} via #{transition.event}" + end + + after_failure do |order, transition| + order.logger.debug "Order #{order.number} halted transition on event #{transition.event} state #{transition.from}: #{order.errors.full_messages.join}" + end + end + end + + def go_to_state(name, options = {}) + checkout_steps[name] = options + previous_states.each do |state| + add_transition({ from: state, to: name }.merge(options)) + end + if options[:if] + previous_states << name + else + self.previous_states = [name] + end + end + + def insert_checkout_step(name, options = {}) + before = options.delete(:before) + after = options.delete(:after) unless before + after = checkout_steps.keys.last unless before || after + + cloned_steps = checkout_steps.clone + cloned_removed_transitions = removed_transitions.clone + checkout_flow do + cloned_steps.each_pair do |key, value| + go_to_state(name, options) if key == before + go_to_state(key, value) + go_to_state(name, options) if key == after + end + cloned_removed_transitions.each do |transition| + remove_transition(transition) + end + end + end + + def remove_checkout_step(name) + cloned_steps = checkout_steps.clone + cloned_removed_transitions = removed_transitions.clone + checkout_flow do + cloned_steps.each_pair do |key, value| + go_to_state(key, value) unless key == name + end + cloned_removed_transitions.each do |transition| + remove_transition(transition) + end + end + end + + def remove_transition(options = {}) + removed_transitions << options + next_event_transitions.delete(find_transition(options)) + end + + def find_transition(options = {}) + return nil if options.nil? || !options.include?(:from) || !options.include?(:to) + + next_event_transitions.detect do |transition| + transition[options[:from].to_sym] == options[:to].to_sym + end + end + + def next_event_transitions + @next_event_transitions ||= [] + end + + def checkout_steps + @checkout_steps ||= {} + end + + def checkout_step_names + checkout_steps.keys + end + + def add_transition(options) + next_event_transitions << { options.delete(:from) => options.delete(:to) }.merge(options) + end + + def removed_transitions + @removed_transitions ||= [] + end + end + end + end + end +end diff --git a/core/lib/spree/preferences/configuration.rb b/core/lib/spree/preferences/configuration.rb index 3f7336e7e94..b8cca7ea0e3 100644 --- a/core/lib/spree/preferences/configuration.rb +++ b/core/lib/spree/preferences/configuration.rb @@ -173,6 +173,10 @@ def self.class_name_attribute(name, default:) class_name = class_name.constantize if class_name.is_a?(String) class_name end + + define_method("#{name}_name") do + instance_variable_get(ivar) || default + end end def self.by_version(*args) diff --git a/core/spec/models/spree/preferences/configuration_spec.rb b/core/spec/models/spree/preferences/configuration_spec.rb index 572ad357778..59df1e12133 100644 --- a/core/spec/models/spree/preferences/configuration_spec.rb +++ b/core/spec/models/spree/preferences/configuration_spec.rb @@ -7,6 +7,7 @@ Class.new(Spree::Preferences::Configuration) do preference :color, :string, default: :blue versioned_preference :foo, :boolean, initial_value: true, boundaries: { "3.0" => false } + class_name_attribute :order_recalculator_class, default: 'Spree::OrderUpdater' end.new end @@ -84,4 +85,16 @@ end end end + + describe ".class_name_attribute" do + it "allows getting the constant of a configurable class" do + config.order_recalculator_class = 'Spree::OrderUpdater' + expect(config.order_recalculator_class).to eq Spree::OrderUpdater + end + + it "allows getting the string name of the class" do + config.order_recalculator_class = 'Spree::OrderUpdater' + expect(config.order_recalculator_class_name).to eq 'Spree::OrderUpdater' + end + end end diff --git a/legacy_promotions/app/decorators/controllers/solidus_legacy_promotions/solidus_admin_adjustments_controller_decorator.rb b/legacy_promotions/app/patches/controllers/solidus_legacy_promotions/solidus_admin_adjustments_controller_patch.rb similarity index 88% rename from legacy_promotions/app/decorators/controllers/solidus_legacy_promotions/solidus_admin_adjustments_controller_decorator.rb rename to legacy_promotions/app/patches/controllers/solidus_legacy_promotions/solidus_admin_adjustments_controller_patch.rb index 5b489bfa34c..52d294b7a73 100644 --- a/legacy_promotions/app/decorators/controllers/solidus_legacy_promotions/solidus_admin_adjustments_controller_decorator.rb +++ b/legacy_promotions/app/patches/controllers/solidus_legacy_promotions/solidus_admin_adjustments_controller_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusLegacyPromotions - module SolidusAdminAdjustmentsControllerDecorator + module SolidusAdminAdjustmentsControllerPatch private def load_adjustments diff --git a/legacy_promotions/app/decorators/lib/solidus_legacy_promotions/spree_order_state_machine_decorator.rb b/legacy_promotions/app/patches/lib/solidus_legacy_promotions/spree_order_state_machine_patch.rb similarity index 90% rename from legacy_promotions/app/decorators/lib/solidus_legacy_promotions/spree_order_state_machine_decorator.rb rename to legacy_promotions/app/patches/lib/solidus_legacy_promotions/spree_order_state_machine_patch.rb index 91548a9f539..bde14ebe30c 100644 --- a/legacy_promotions/app/decorators/lib/solidus_legacy_promotions/spree_order_state_machine_decorator.rb +++ b/legacy_promotions/app/patches/lib/solidus_legacy_promotions/spree_order_state_machine_patch.rb @@ -3,7 +3,7 @@ require_dependency "spree/core/state_machines/order" module SolidusLegacyPromotions - module SpreeOrderStateMachineDecorator + module SpreeOrderStateMachinePatch def define_state_machine! super state_machine do diff --git a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_adjustment_decorator.rb b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_adjustment_patch.rb similarity index 98% rename from legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_adjustment_decorator.rb rename to legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_adjustment_patch.rb index 658158ec1e6..79641cf9295 100644 --- a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_adjustment_decorator.rb +++ b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_adjustment_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusLegacyPromotions - module SpreeAdjustmentDecorator + module SpreeAdjustmentPatch def self.prepended(base) base.belongs_to :promotion_code, class_name: 'Spree::PromotionCode', optional: true base.validates :promotion_code, presence: true, if: :require_promotion_code? diff --git a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_calculator_returns_default_refund_amount_decorator.rb b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_calculator_returns_default_refund_amount_patch.rb similarity index 84% rename from legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_calculator_returns_default_refund_amount_decorator.rb rename to legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_calculator_returns_default_refund_amount_patch.rb index 0a1726a9c6c..15ea311dc12 100644 --- a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_calculator_returns_default_refund_amount_decorator.rb +++ b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_calculator_returns_default_refund_amount_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusLegacyPromotions - module SpreeCalculatorReturnsDefaultRefundAmountDecorator + module SpreeCalculatorReturnsDefaultRefundAmountPatch private def weighted_order_adjustment_amount(inventory_unit) diff --git a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_line_item_decorator.rb b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_line_item_patch.rb similarity index 92% rename from legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_line_item_decorator.rb rename to legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_line_item_patch.rb index 58147729943..be67bcd529a 100644 --- a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_line_item_decorator.rb +++ b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_line_item_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusLegacyPromotions - module SpreeLineItemDecorator + module SpreeLineItemPatch def self.prepended(base) base.has_many :line_item_actions, dependent: :destroy base.has_many :actions, through: :line_item_actions diff --git a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_order_decorator.rb b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_order_patch.rb similarity index 96% rename from legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_order_decorator.rb rename to legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_order_patch.rb index 278c565fa75..94660d25c3f 100644 --- a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_order_decorator.rb +++ b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_order_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusLegacyPromotions - module SpreeOrderDecorator + module SpreeOrderPatch module ClassMethods def allowed_ransackable_associations super + ["promotions", "order_promotions"] diff --git a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_order_updater_decorator.rb b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_order_updater_patch.rb similarity index 97% rename from legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_order_updater_decorator.rb rename to legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_order_updater_patch.rb index e8e18ee9cff..53fec61d4d9 100644 --- a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_order_updater_decorator.rb +++ b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_order_updater_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusLegacyPromotions - module SpreeOrderUpdaterDecorator + module SpreeOrderUpdaterPatch def update_adjustment_total recalculate_adjustments diff --git a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_product_decorator.rb b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_product_patch.rb similarity index 92% rename from legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_product_decorator.rb rename to legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_product_patch.rb index 73b52cb7aff..691224ac257 100644 --- a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_product_decorator.rb +++ b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_product_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusLegacyPromotions - module SpreeProductDecorator + module SpreeProductPatch def self.prepended(base) base.has_many :product_promotion_rules, dependent: :destroy base.has_many :promotion_rules, through: :product_promotion_rules diff --git a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_shipment_decorator.rb b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_shipment_patch.rb similarity index 91% rename from legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_shipment_decorator.rb rename to legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_shipment_patch.rb index 6d13ebfdf2b..84daa3a3ff4 100644 --- a/legacy_promotions/app/decorators/models/solidus_legacy_promotions/spree_shipment_decorator.rb +++ b/legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_shipment_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusLegacyPromotions - module SpreeShipmentDecorator + module SpreeShipmentPatch # @return [BigDecimal] the amount of this item, taking into consideration # all non-tax eligible adjustments. def total_before_tax diff --git a/promotions/app/decorators/models/solidus_promotions/adjustment_decorator.rb b/promotions/app/patches/models/solidus_promotions/adjustment_patch.rb similarity index 88% rename from promotions/app/decorators/models/solidus_promotions/adjustment_decorator.rb rename to promotions/app/patches/models/solidus_promotions/adjustment_patch.rb index 87295179251..45563819cab 100644 --- a/promotions/app/decorators/models/solidus_promotions/adjustment_decorator.rb +++ b/promotions/app/patches/models/solidus_promotions/adjustment_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusPromotions - module AdjustmentDecorator + module AdjustmentPatch def self.prepended(base) base.scope :solidus_promotion, -> { where(source_type: "SolidusPromotions::Benefit") } end diff --git a/promotions/app/decorators/models/solidus_promotions/line_item_decorator.rb b/promotions/app/patches/models/solidus_promotions/line_item_patch.rb similarity index 96% rename from promotions/app/decorators/models/solidus_promotions/line_item_decorator.rb rename to promotions/app/patches/models/solidus_promotions/line_item_patch.rb index a1169f0e7ee..1e79d97009e 100644 --- a/promotions/app/decorators/models/solidus_promotions/line_item_decorator.rb +++ b/promotions/app/patches/models/solidus_promotions/line_item_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusPromotions - module LineItemDecorator + module LineItemPatch def self.prepended(base) base.attr_accessor :quantity_setter base.belongs_to :managed_by_order_benefit, class_name: "SolidusPromotions::Benefit", optional: true diff --git a/promotions/app/decorators/models/solidus_promotions/order_decorator.rb b/promotions/app/patches/models/solidus_promotions/order_patch.rb similarity index 98% rename from promotions/app/decorators/models/solidus_promotions/order_decorator.rb rename to promotions/app/patches/models/solidus_promotions/order_patch.rb index 08cc180e030..75e79bfa36d 100644 --- a/promotions/app/decorators/models/solidus_promotions/order_decorator.rb +++ b/promotions/app/patches/models/solidus_promotions/order_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusPromotions - module OrderDecorator + module OrderPatch module ClassMethods def allowed_ransackable_associations super + ["solidus_promotions", "solidus_order_promotions"] diff --git a/promotions/app/decorators/models/solidus_promotions/order_recalculator_decorator.rb b/promotions/app/patches/models/solidus_promotions/order_recalculator_patch.rb similarity index 92% rename from promotions/app/decorators/models/solidus_promotions/order_recalculator_decorator.rb rename to promotions/app/patches/models/solidus_promotions/order_recalculator_patch.rb index ff497e9dba0..d8820d54e21 100644 --- a/promotions/app/decorators/models/solidus_promotions/order_recalculator_decorator.rb +++ b/promotions/app/patches/models/solidus_promotions/order_recalculator_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusPromotions - module OrderRecalculatorDecorator + module OrderRecalculatorPatch # This is only needed for stores upgrading from the legacy promotion system. # Once we've removed support for the legacy promotion system, we can remove this. def recalculate diff --git a/promotions/app/decorators/models/solidus_promotions/shipment_decorator.rb b/promotions/app/patches/models/solidus_promotions/shipment_patch.rb similarity index 90% rename from promotions/app/decorators/models/solidus_promotions/shipment_decorator.rb rename to promotions/app/patches/models/solidus_promotions/shipment_patch.rb index 9df47adb33e..c73b14f7da1 100644 --- a/promotions/app/decorators/models/solidus_promotions/shipment_decorator.rb +++ b/promotions/app/patches/models/solidus_promotions/shipment_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusPromotions - module ShipmentDecorator + module ShipmentPatch Spree::Shipment.prepend SolidusPromotions::DiscountableAmount def reset_current_discounts diff --git a/promotions/app/decorators/models/solidus_promotions/shipping_rate_decorator.rb b/promotions/app/patches/models/solidus_promotions/shipping_rate_patch.rb similarity index 95% rename from promotions/app/decorators/models/solidus_promotions/shipping_rate_decorator.rb rename to promotions/app/patches/models/solidus_promotions/shipping_rate_patch.rb index c0687fa6948..69d232062e1 100644 --- a/promotions/app/decorators/models/solidus_promotions/shipping_rate_decorator.rb +++ b/promotions/app/patches/models/solidus_promotions/shipping_rate_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module SolidusPromotions - module ShippingRateDecorator + module ShippingRatePatch def self.prepended(base) base.class_eval do has_many :discounts, diff --git a/promotions/lib/solidus_promotions/engine.rb b/promotions/lib/solidus_promotions/engine.rb index 29df050ba6d..7cdba2661c9 100644 --- a/promotions/lib/solidus_promotions/engine.rb +++ b/promotions/lib/solidus_promotions/engine.rb @@ -6,6 +6,7 @@ module SolidusPromotions class Engine < Rails::Engine include SolidusSupport::EngineExtensions + Flickwerk.aliases["Spree::Config.order_recalculator_class"] = Spree::Config.order_recalculator_class_name isolate_namespace ::SolidusPromotions