summaryrefslogtreecommitdiff
path: root/lib/solidus_subscriptions/subscription_generator.rb
diff options
context:
space:
mode:
authorAlessandro Desantis <desa.alessandro@gmail.com>2021-02-26 18:25:01 +0100
committerGitHub <noreply@github.com>2021-02-26 18:25:01 +0100
commit4d4bb04d14b0afd970f0f359f70ba13a8c5d5d5a (patch)
tree833b61da47ffdb403f4f694323544eeb82dd0539 /lib/solidus_subscriptions/subscription_generator.rb
parent5d965b6ac0b2b9fcb69d3b40cd274c3c9eef6355 (diff)
parent11fa55f3c6a6a6b95314d1967f354f48b3c17416 (diff)
Merge pull request #202 from solidusio-contrib/mr/cleanup-duplicated-fields-on-order-finalize
Cleanup the duplicated fields on subscription creation
Diffstat (limited to 'lib/solidus_subscriptions/subscription_generator.rb')
-rw-r--r--lib/solidus_subscriptions/subscription_generator.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/solidus_subscriptions/subscription_generator.rb b/lib/solidus_subscriptions/subscription_generator.rb
index 4f675a7..4910c7c 100644
--- a/lib/solidus_subscriptions/subscription_generator.rb
+++ b/lib/solidus_subscriptions/subscription_generator.rb
@@ -35,6 +35,8 @@ module SolidusSubscriptions
Subscription.create!(subscription_attributes) do |sub|
sub.actionable_date = sub.next_actionable_date
+ end.tap do |_subscription|
+ cleanup_subscription_line_items(subscription_line_items)
end
end
@@ -55,6 +57,15 @@ module SolidusSubscriptions
private
+ def cleanup_subscription_line_items(subscription_line_items)
+ ids = subscription_line_items.pluck :id
+ SolidusSubscriptions::LineItem.where(id: ids).update_all(
+ interval_length: nil,
+ interval_units: nil,
+ end_date: nil
+ )
+ end
+
def subscription_configuration(subscription_line_item)
SubscriptionConfiguration.new(
subscription_line_item.interval_length,