From 0f2fcd88dfbac40583680510dfc2caf2529b8258 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Fri, 20 Dec 2024 22:35:06 +0100 Subject: [PATCH] Run legacy promotion handler "cart" if legacy promo system present In the legacy promotion system, there's a separation of tasks between `order.recalculate` and `PromotionHandler::Cart`. `order.recalculate` will only recalculate already existing promotion adjustments, but will not check for any new promotions that might need to be applied. In the new promotion system, both of these tasks are handled by `order.recalculate`. If the legacy promotion system is present, but not active, calling this promotion handler will result in a single database call, which is an acceptable price to pay I think. --- lib/solidus_subscriptions/checkout.rb | 3 +++ lib/solidus_subscriptions/subscription_line_item_builder.rb | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/solidus_subscriptions/checkout.rb b/lib/solidus_subscriptions/checkout.rb index 9b39f3a1..53e05251 100644 --- a/lib/solidus_subscriptions/checkout.rb +++ b/lib/solidus_subscriptions/checkout.rb @@ -42,6 +42,9 @@ def populate_order(order) end def finalize_order(order) + # Rerun the legacy promotion handler + # `solidus_promotions` does not need this handler, and will pickup promotions in `order.recalculate` + ::Spree::PromotionHandler::Cart.new(order).activate if defined?(::Spree::PromotionHandler::Cart) order.recalculate order.checkout_steps[0...-1].each do diff --git a/lib/solidus_subscriptions/subscription_line_item_builder.rb b/lib/solidus_subscriptions/subscription_line_item_builder.rb index 303c4de0..64b06f08 100644 --- a/lib/solidus_subscriptions/subscription_line_item_builder.rb +++ b/lib/solidus_subscriptions/subscription_line_item_builder.rb @@ -9,6 +9,9 @@ def create_subscription_line_item(line_item) subscription_params.merge(spree_line_item: line_item) ) + # Rerun the legacy promotion handler to pickup subscription promotions + # `solidus_promotions` does not need this handler, and will pickup promotions in `order.recalculate` + ::Spree::PromotionHandler::Cart.new(line_item.order).activate if defined?(::Spree::PromotionHandler::Cart) line_item.order.recalculate end