summaryrefslogtreecommitdiff
path: root/app/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb
diff options
context:
space:
mode:
authorcesartalves <cesartalvez@gmail.com>2021-04-16 10:54:58 -0300
committercesartalves <cesartalvez@gmail.com>2021-04-19 12:41:58 -0300
commit394e41b77bf56fecac44165fb6af687fab01b8e0 (patch)
tree365bbd38824df2064b0d62f0efa0134bb4a548ec /app/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb
parent9a9a681ea2e2d1f812267164733da40e1fd2d460 (diff)
Fix Spree::OrdersController decoration
Move all decorators to nested library (api, core, backend, frontend) decorators folder so they don't get loaded unless the library is defined.
Diffstat (limited to 'app/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb')
-rw-r--r--app/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/app/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb b/app/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb
new file mode 100644
index 0000000..6b39b4c
--- /dev/null
+++ b/app/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+# Create new subscription line items associated to the current order, when
+# a line item is added to the cart which includes subscription_line_item
+# params.
+#
+# The Subscriptions::LineItem acts as a line item place holder for a
+# Subscription, indicating that it has been added to the order, but not
+# yet purchased
+module SolidusSubscriptions
+ module Spree
+ module OrdersController
+ module CreateSubscriptionLineItems
+ include SolidusSubscriptions::SubscriptionLineItemBuilder
+
+ def self.prepended(base)
+ base.after_action(
+ :handle_subscription_line_items,
+ only: :populate,
+ if: ->{ params[:subscription_line_item] }
+ )
+ end
+
+ private
+
+ def handle_subscription_line_items
+ line_item = @current_order.line_items.find_by(variant_id: params[:variant_id])
+ create_subscription_line_item(line_item)
+ end
+ end
+ end
+ end
+end
+
+Spree::OrdersController.prepend(SolidusSubscriptions::Spree::OrdersController::CreateSubscriptionLineItems)