From d4236339b927c5a5f4e9cd2a508e5f0eda7d5e70 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 15 Jan 2025 11:18:45 +0100 Subject: [PATCH 1/6] Extract ClassMethods constant into autoloadable file Otherwise, patching it does not work. --- .../models/spree/core/state_machines/order.rb | 208 ----------------- .../state_machines/order/class_methods.rb | 217 ++++++++++++++++++ 2 files changed, 217 insertions(+), 208 deletions(-) create mode 100644 core/app/models/spree/core/state_machines/order/class_methods.rb diff --git a/core/app/models/spree/core/state_machines/order.rb b/core/app/models/spree/core/state_machines/order.rb index 691b20e212..49db2035dd 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 0000000000..689e4f1865 --- /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 From f4b32efb2aa796e8ef5ec3717b214844d9e87054 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Sat, 21 Dec 2024 15:25:27 +0100 Subject: [PATCH 2/6] Add Flickwerk dependency to promotions gem --- promotions/solidus_promotions.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/promotions/solidus_promotions.gemspec b/promotions/solidus_promotions.gemspec index 1838e94dfa..e1f10a5703 100644 --- a/promotions/solidus_promotions.gemspec +++ b/promotions/solidus_promotions.gemspec @@ -24,6 +24,7 @@ Gem::Specification.new do |spec| files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") } spec.files = files.grep_v(%r{^(spec|bin)/}) + spec.add_dependency "flickwerk", "~> 0.3.1" spec.add_dependency "importmap-rails", "~> 1.2" spec.add_dependency "ransack-enum", "~> 1.0" spec.add_dependency "solidus_core", [">= 4.0.0", "< 5"] From 85c2ac35cfa5eae486a21143221ed590cd165a39 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Sat, 21 Dec 2024 15:37:42 +0100 Subject: [PATCH 3/6] Add getter for configured class names When configuring Flickwerk, we need a way to get at class names without constantizing (i.e. loading) those classes. This adds some specs for the `class_name_attribute` class method on Spree::Preferences::Configuration, and generates a new getter that has `_name` attached to the method to get just the string name. --- core/lib/spree/preferences/configuration.rb | 4 ++++ .../models/spree/preferences/configuration_spec.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/core/lib/spree/preferences/configuration.rb b/core/lib/spree/preferences/configuration.rb index 3f7336e7e9..b8cca7ea0e 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 572ad35777..59df1e1213 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 From fca2dc3a07ceba75b1b6abd56713b536a60182e2 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Sat, 21 Dec 2024 15:43:55 +0100 Subject: [PATCH 4/6] Move decorators to patches/, configure Flickwerk This stops us from loading line item, order, adjustment, shipment, shipping rate, and the order recalculator on app startup. --- .../models/solidus_promotions/adjustment_patch.rb} | 2 +- .../models/solidus_promotions/line_item_patch.rb} | 2 +- .../models/solidus_promotions/order_patch.rb} | 2 +- .../models/solidus_promotions/order_recalculator_patch.rb} | 2 +- .../models/solidus_promotions/shipment_patch.rb} | 2 +- .../models/solidus_promotions/shipping_rate_patch.rb} | 2 +- promotions/lib/solidus_promotions/engine.rb | 3 +++ 7 files changed, 9 insertions(+), 6 deletions(-) rename promotions/app/{decorators/models/solidus_promotions/adjustment_decorator.rb => patches/models/solidus_promotions/adjustment_patch.rb} (88%) rename promotions/app/{decorators/models/solidus_promotions/line_item_decorator.rb => patches/models/solidus_promotions/line_item_patch.rb} (96%) rename promotions/app/{decorators/models/solidus_promotions/order_decorator.rb => patches/models/solidus_promotions/order_patch.rb} (98%) rename promotions/app/{decorators/models/solidus_promotions/order_recalculator_decorator.rb => patches/models/solidus_promotions/order_recalculator_patch.rb} (92%) rename promotions/app/{decorators/models/solidus_promotions/shipment_decorator.rb => patches/models/solidus_promotions/shipment_patch.rb} (90%) rename promotions/app/{decorators/models/solidus_promotions/shipping_rate_decorator.rb => patches/models/solidus_promotions/shipping_rate_patch.rb} (95%) 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 8729517925..45563819ca 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 a1169f0e7e..1e79d97009 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 08cc180e03..75e79bfa36 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 ff497e9dba..d8820d54e2 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 9df47adb33..c73b14f7da 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 c0687fa694..69d232062e 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 29df050ba6..a69aa708f2 100644 --- a/promotions/lib/solidus_promotions/engine.rb +++ b/promotions/lib/solidus_promotions/engine.rb @@ -2,10 +2,13 @@ require "solidus_core" require "solidus_support" +require "flickwerk" module SolidusPromotions class Engine < Rails::Engine include SolidusSupport::EngineExtensions + include Flickwerk + Flickwerk.aliases["Spree::Config.order_recalculator_class"] = Spree::Config.order_recalculator_class_name isolate_namespace ::SolidusPromotions From 2faf6a866dad3ef25ee7d20262565916ba3f0f21 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Sat, 21 Dec 2024 15:56:41 +0100 Subject: [PATCH 5/6] Legacy Promotions: Use Flickwerk for patches This should stop us from loading order, line items, adjustment, calculators, the order updater, product, and shipment on app startup. --- .../solidus_admin_adjustments_controller_patch.rb} | 2 +- .../spree_order_state_machine_patch.rb} | 2 +- .../solidus_legacy_promotions/spree_adjustment_patch.rb} | 2 +- .../spree_calculator_returns_default_refund_amount_patch.rb} | 2 +- .../solidus_legacy_promotions/spree_line_item_patch.rb} | 2 +- .../models/solidus_legacy_promotions/spree_order_patch.rb} | 2 +- .../solidus_legacy_promotions/spree_order_updater_patch.rb} | 2 +- .../models/solidus_legacy_promotions/spree_product_patch.rb} | 2 +- .../models/solidus_legacy_promotions/spree_shipment_patch.rb} | 2 +- legacy_promotions/lib/solidus_legacy_promotions/engine.rb | 4 +++- legacy_promotions/solidus_legacy_promotions.gemspec | 1 + 11 files changed, 13 insertions(+), 10 deletions(-) rename legacy_promotions/app/{decorators/controllers/solidus_legacy_promotions/solidus_admin_adjustments_controller_decorator.rb => patches/controllers/solidus_legacy_promotions/solidus_admin_adjustments_controller_patch.rb} (88%) rename legacy_promotions/app/{decorators/lib/solidus_legacy_promotions/spree_order_state_machine_decorator.rb => patches/lib/solidus_legacy_promotions/spree_order_state_machine_patch.rb} (90%) rename legacy_promotions/app/{decorators/models/solidus_legacy_promotions/spree_adjustment_decorator.rb => patches/models/solidus_legacy_promotions/spree_adjustment_patch.rb} (98%) rename legacy_promotions/app/{decorators/models/solidus_legacy_promotions/spree_calculator_returns_default_refund_amount_decorator.rb => patches/models/solidus_legacy_promotions/spree_calculator_returns_default_refund_amount_patch.rb} (84%) rename legacy_promotions/app/{decorators/models/solidus_legacy_promotions/spree_line_item_decorator.rb => patches/models/solidus_legacy_promotions/spree_line_item_patch.rb} (92%) rename legacy_promotions/app/{decorators/models/solidus_legacy_promotions/spree_order_decorator.rb => patches/models/solidus_legacy_promotions/spree_order_patch.rb} (96%) rename legacy_promotions/app/{decorators/models/solidus_legacy_promotions/spree_order_updater_decorator.rb => patches/models/solidus_legacy_promotions/spree_order_updater_patch.rb} (97%) rename legacy_promotions/app/{decorators/models/solidus_legacy_promotions/spree_product_decorator.rb => patches/models/solidus_legacy_promotions/spree_product_patch.rb} (92%) rename legacy_promotions/app/{decorators/models/solidus_legacy_promotions/spree_shipment_decorator.rb => patches/models/solidus_legacy_promotions/spree_shipment_patch.rb} (91%) 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 5b489bfa34..52d294b7a7 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 91548a9f53..bde14ebe30 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 658158ec1e..79641cf929 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 0a1726a9c6..15ea311dc1 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 5814772994..be67bcd529 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 278c565fa7..94660d25c3 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 e8e18ee9cf..53fec61d4d 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 73b52cb7af..691224ac25 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 6d13ebfdf2..84daa3a3ff 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/legacy_promotions/lib/solidus_legacy_promotions/engine.rb b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb index ba7fe49583..2fae52907e 100644 --- a/legacy_promotions/lib/solidus_legacy_promotions/engine.rb +++ b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb @@ -1,11 +1,13 @@ # frozen_string_literal: true require 'solidus_legacy_promotions' - +require 'flickwerk' module SolidusLegacyPromotions class Engine < ::Rails::Engine include SolidusSupport::EngineExtensions + include Flickwerk + initializer "solidus_legacy_promotions.add_backend_menu_item" do if SolidusSupport.backend_available? promotions_menu_item = Spree::BackendConfiguration::MenuItem.new( diff --git a/legacy_promotions/solidus_legacy_promotions.gemspec b/legacy_promotions/solidus_legacy_promotions.gemspec index 847a100ff0..ddd475066a 100644 --- a/legacy_promotions/solidus_legacy_promotions.gemspec +++ b/legacy_promotions/solidus_legacy_promotions.gemspec @@ -23,6 +23,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 3.1.0' s.required_rubygems_version = '>= 1.8.23' + s.add_dependency 'flickwerk', '~> 0.3.1' s.add_dependency 'solidus_api', s.version s.add_dependency 'solidus_core', s.version s.add_dependency 'solidus_support', '>= 0.12.0' From 230478e76b67192b315a58412c80710913520be9 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 14 Jan 2025 10:56:43 +0100 Subject: [PATCH 6/6] Temp: Use unrelease solidus_support version --- Gemfile | 1 + legacy_promotions/lib/solidus_legacy_promotions/engine.rb | 4 +--- legacy_promotions/solidus_legacy_promotions.gemspec | 1 - promotions/lib/solidus_promotions/engine.rb | 2 -- promotions/solidus_promotions.gemspec | 1 - 5 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index dd357ea99b..3b31729a79 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/legacy_promotions/lib/solidus_legacy_promotions/engine.rb b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb index 2fae52907e..ba7fe49583 100644 --- a/legacy_promotions/lib/solidus_legacy_promotions/engine.rb +++ b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb @@ -1,13 +1,11 @@ # frozen_string_literal: true require 'solidus_legacy_promotions' -require 'flickwerk' + module SolidusLegacyPromotions class Engine < ::Rails::Engine include SolidusSupport::EngineExtensions - include Flickwerk - initializer "solidus_legacy_promotions.add_backend_menu_item" do if SolidusSupport.backend_available? promotions_menu_item = Spree::BackendConfiguration::MenuItem.new( diff --git a/legacy_promotions/solidus_legacy_promotions.gemspec b/legacy_promotions/solidus_legacy_promotions.gemspec index ddd475066a..847a100ff0 100644 --- a/legacy_promotions/solidus_legacy_promotions.gemspec +++ b/legacy_promotions/solidus_legacy_promotions.gemspec @@ -23,7 +23,6 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 3.1.0' s.required_rubygems_version = '>= 1.8.23' - s.add_dependency 'flickwerk', '~> 0.3.1' s.add_dependency 'solidus_api', s.version s.add_dependency 'solidus_core', s.version s.add_dependency 'solidus_support', '>= 0.12.0' diff --git a/promotions/lib/solidus_promotions/engine.rb b/promotions/lib/solidus_promotions/engine.rb index a69aa708f2..7cdba2661c 100644 --- a/promotions/lib/solidus_promotions/engine.rb +++ b/promotions/lib/solidus_promotions/engine.rb @@ -2,12 +2,10 @@ require "solidus_core" require "solidus_support" -require "flickwerk" module SolidusPromotions class Engine < Rails::Engine include SolidusSupport::EngineExtensions - include Flickwerk Flickwerk.aliases["Spree::Config.order_recalculator_class"] = Spree::Config.order_recalculator_class_name isolate_namespace ::SolidusPromotions diff --git a/promotions/solidus_promotions.gemspec b/promotions/solidus_promotions.gemspec index e1f10a5703..1838e94dfa 100644 --- a/promotions/solidus_promotions.gemspec +++ b/promotions/solidus_promotions.gemspec @@ -24,7 +24,6 @@ Gem::Specification.new do |spec| files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") } spec.files = files.grep_v(%r{^(spec|bin)/}) - spec.add_dependency "flickwerk", "~> 0.3.1" spec.add_dependency "importmap-rails", "~> 1.2" spec.add_dependency "ransack-enum", "~> 1.0" spec.add_dependency "solidus_core", [">= 4.0.0", "< 5"]