Sha256: 698b7e093540f0249bfb265892547062da510677be0d0dabb57d4e077a74c50e

Contents?: true

Size: 1.64 KB

Versions: 16

Compression:

Stored size: 1.64 KB

Contents

module Workarea
  module Api
    module Storefront
      module CurrentCheckout
        def current_order
          return @current_order if defined?(@current_order)

          options = { id: params[:cart_id].presence || params[:id] }
          options[:user_id] = current_user.id if authentication?
          order = Order.carts.find_by(options)

          if order.user_id.present? && current_user.id.to_s != order.user_id
            raise Authentication::InvalidError
          end

          @current_order = order
        end

        def current_checkout
          @current_checkout ||=
            if authentication?
              Workarea::Checkout.new(current_order, current_user)
            else
              Workarea::Checkout.new(current_order)
            end
        end

        private

        def set_checkout_view_models
          @cart = Workarea::Storefront::CartViewModel.new(
            current_order,
            view_model_options
          )

          @summary = Workarea::Storefront::Checkout::SummaryViewModel.new(
            current_checkout,
            view_model_options
          )

          @order = Workarea::Storefront::OrderViewModel.new(
            current_order,
            view_model_options
          )
        end

        def remove_unpurchasable_items
          cleaner = CartCleaner.new(current_order)
          cleaner.clean
          flash[:info] = cleaner.messages if cleaner.message?
        end

        def check_inventory
          reservation = InventoryAdjustment.new(current_order).tap(&:perform)
          flash[:error] = reservation.errors if reservation.errors.present?
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
workarea-api-4.5.6 storefront/app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-storefront-4.5.6 app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-4.5.5 storefront/app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-storefront-4.5.5 app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-4.5.4 storefront/app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-storefront-4.5.4 app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-4.5.3 storefront/app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-storefront-4.5.3 app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-4.5.2 storefront/app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-storefront-4.5.2 app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-4.5.0 storefront/app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-storefront-4.5.0 app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-4.4.7 storefront/app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-storefront-4.4.7 app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-4.4.6 storefront/app/controllers/workarea/api/storefront/current_checkout.rb
workarea-api-storefront-4.4.6 app/controllers/workarea/api/storefront/current_checkout.rb