diff options
author | Alessandro Desantis <desa.alessandro@gmail.com> | 2021-02-26 18:25:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-26 18:25:01 +0100 |
commit | 4d4bb04d14b0afd970f0f359f70ba13a8c5d5d5a (patch) | |
tree | 833b61da47ffdb403f4f694323544eeb82dd0539 /lib/solidus_subscriptions/subscription_generator.rb | |
parent | 5d965b6ac0b2b9fcb69d3b40cd274c3c9eef6355 (diff) | |
parent | 11fa55f3c6a6a6b95314d1967f354f48b3c17416 (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.rb | 11 |
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, |