summaryrefslogtreecommitdiff
path: root/app/decorators/models/solidus_subscriptions/spree/order/finalize_creates_subscriptions.rb
blob: 568e5a8c942e89fd1d87bdcf3892fe51f212185f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

# Once an order is finalized its subscriptions line items should be converted
# into active subscriptions. This hooks into Spree::Order#finalize! and
# passes all subscription_line_items present on the order to the Subscription
# generator which will build and persist the subscriptions
module SolidusSubscriptions
  module Spree
    module Order
      module FinalizeCreatesSubscriptions
        def finalize!
          SolidusSubscriptions::SubscriptionGenerator.group(subscription_line_items).each do |line_items|
            SolidusSubscriptions::SubscriptionGenerator.activate(line_items)
          end

          super
        end
      end
    end
  end
end

Spree::Order.prepend(SolidusSubscriptions::Spree::Order::FinalizeCreatesSubscriptions)