diff options
Diffstat (limited to 'lib/solidus_subscriptions/subscription_line_item_builder.rb')
-rw-r--r-- | lib/solidus_subscriptions/subscription_line_item_builder.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/solidus_subscriptions/subscription_line_item_builder.rb b/lib/solidus_subscriptions/subscription_line_item_builder.rb new file mode 100644 index 0000000..7354102 --- /dev/null +++ b/lib/solidus_subscriptions/subscription_line_item_builder.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + module SubscriptionLineItemBuilder + private + + def create_subscription_line_item(line_item) + SolidusSubscriptions::LineItem.create!( + subscription_params.merge(spree_line_item: line_item) + ) + + # Rerun the promotion handler to pickup subscription promotions + ::Spree::PromotionHandler::Cart.new(line_item.order).activate + line_item.order.recalculate + end + + def subscription_params + params.require(:subscription_line_item).permit( + SolidusSubscriptions.configuration.subscription_line_item_attributes + ) + end + end +end |