# Once an order is finalized its subscriptions line items should be converted
# into active subscritptions. 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 Spree
  module Orders
    module FinalizeCreatesSubscriptions
      def finalize!
        SolidusSubscriptions::SubscriptionGenerator.activate(subscription_line_items)
        super
      end
    end
  end
end

Spree::Order.prepend Spree::Orders::FinalizeCreatesSubscriptions

# Once an order is finalized its subscriptions line items should be converted
# into active subscritptions. 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 Spree
  module Orders
    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

Spree::Order.prepend Spree::Orders::FinalizeCreatesSubscriptions

Create a subscription per subscription_line_item group
Create a subscription per subscription_line_item group

A separate subscription should be created for each group of similar
subscription line items.

ex. subscription line items with different fulfillment intervals cannot
be fulfilled by the same subscription. But if the line items have all
the same subscription configuration option, they can be fulfilled by the
same subscription
