Sha256: 0da1286b34713ddeb0fa7a1ded33f5381208bafe325e992099add2a6eccaec81

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

# 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)

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_subscriptions-2.0.2 lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb
solidus_subscriptions-2.0.1 lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb
solidus_subscriptions-2.0.0 lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb
solidus_subscriptions-1.1.0 lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb
solidus_subscriptions-1.0.1 lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb
solidus_subscriptions-1.0.0 lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb
solidus_subscriptions-1.0.0.rc1 app/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb