Skip to content

Commit

Permalink
Legacy Promotions: Use Flickwerk for patches
Browse files Browse the repository at this point in the history
This should stop us from loading order, line items, adjustment,
calculators, the order updater, product, and shipment on app startup.
  • Loading branch information
mamhoff committed Jan 3, 2025
1 parent d1f57b6 commit f8b3503
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SolidusLegacyPromotions
module SolidusAdminAdjustmentsControllerDecorator
module SolidusAdminAdjustmentsControllerPatch
private

def load_adjustments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SolidusLegacyPromotions
module SpreeCalculatorReturnsDefaultRefundAmountDecorator
module SpreeCalculatorReturnsDefaultRefundAmountPatch
private

def weighted_order_adjustment_amount(inventory_unit)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SolidusLegacyPromotions
module SpreeOrderDecorator
module SpreeOrderPatch
module ClassMethods
def allowed_ransackable_associations
super + ["promotions", "order_promotions"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SolidusLegacyPromotions
module SpreeOrderUpdaterDecorator
module SpreeOrderUpdaterPatch
def update_adjustment_total
recalculate_adjustments

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 9 additions & 1 deletion legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
1 change: 1 addition & 0 deletions legacy_promotions/solidus_legacy_promotions.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit f8b3503

Please sign in to comment.