From f8b35037afeccc04cad88ffb11c29e029ed626b0 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Sat, 21 Dec 2024 15:56:41 +0100 Subject: [PATCH] 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 +- .../spree_adjustment_patch.rb} | 2 +- ..._calculator_returns_default_refund_amount_patch.rb} | 2 +- .../spree_line_item_patch.rb} | 2 +- .../solidus_legacy_promotions/spree_order_patch.rb} | 2 +- .../spree_order_updater_patch.rb} | 2 +- .../solidus_legacy_promotions/spree_product_patch.rb} | 2 +- .../solidus_legacy_promotions/spree_shipment_patch.rb} | 2 +- .../lib/solidus_legacy_promotions/engine.rb | 10 +++++++++- legacy_promotions/solidus_legacy_promotions.gemspec | 1 + 11 files changed, 19 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 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/legacy_promotions/lib/solidus_legacy_promotions/engine.rb b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb index ba7fe49583e..0902cb315ef 100644 --- a/legacy_promotions/lib/solidus_legacy_promotions/engine.rb +++ b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb @@ -1,11 +1,19 @@ # 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.patch_state_machine" do + config.to_prepare do + SolidusLegacyPromotions::SpreeOrderStateMachinePatch + end + end + 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 847a100ff0b..ddd475066af 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'