Skip to content

Commit

Permalink
Run legacy promotion handler "cart" if legacy promo system present
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mamhoff committed Jan 13, 2025
1 parent f78e322 commit 0f2fcd8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/solidus_subscriptions/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/solidus_subscriptions/subscription_line_item_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0f2fcd8

Please sign in to comment.