summaryrefslogtreecommitdiff
path: root/lib/solidus_subscriptions/processor.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/solidus_subscriptions/processor.rb')
-rw-r--r--lib/solidus_subscriptions/processor.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/solidus_subscriptions/processor.rb b/lib/solidus_subscriptions/processor.rb
index cae2ad6..4c1268b 100644
--- a/lib/solidus_subscriptions/processor.rb
+++ b/lib/solidus_subscriptions/processor.rb
@@ -1,6 +1,7 @@
# This class is responsible for finding subscriptions and installments
# which need to be processed. It will group them together by user and attempts
-# to process them together.
+# to process them together. Subscriptions will also be grouped by their
+# shiping address id.
#
# This class passes the reponsibility of actually creating the order off onto
# the consolidated installment class.
@@ -55,7 +56,15 @@ module SolidusSubscriptions
# Create `ProcessInstallmentsJob`s for the users used to initalize the
# instance
def build_jobs
- users.map { |user| ProcessInstallmentsJob.perform_later installments(user).map(&:id) }
+ users.map do |user|
+ installemts_by_address_and_user = installments(user).group_by do |i|
+ i.subscription.shipping_address_id
+ end
+
+ installemts_by_address_and_user.values.each do |grouped_installments|
+ ProcessInstallmentsJob.perform_later grouped_installments.map(&:id)
+ end
+ end
end
private
@@ -63,7 +72,7 @@ module SolidusSubscriptions
def subscriptions_by_id
@subscriptions_by_id ||= Subscription.
actionable.
- includes(:line_item, :user).
+ includes(:line_items, :user).
where(user_id: user_ids).
group_by(&:user_id)
end