Sha256: ffcfd98273a1ff39b74f571ef0dac042efca0100325ab2d4aef22c42cfd3b7a3

Contents?: true

Size: 1.32 KB

Versions: 16

Compression:

Stored size: 1.32 KB

Contents

module Workarea
  module Api
    module Storefront
      class CartsController < Api::Storefront::ApplicationController
        include CurrentCheckout

        before_action :set_checkout_view_models, except: [:index, :create]
        before_action :remove_unpurchasable_items, except: [:index, :create]
        before_action :check_inventory, except: [:index, :create]

        def index
          @orders = Workarea::Storefront::OrderViewModel.wrap(
            Order.carts.where(user_id: current_user.id).to_a
          )
        end

        def create
          order = Order.new
          order.user_id = current_user.id if authentication?
          order.save!

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

          render :show
        end

        def show
          Pricing.perform(current_order, current_checkout.shipping)
        end

        def add_promo_code
          if Pricing.valid_promo_code?(params[:promo_code], current_checkout.email)
            current_order.add_promo_code(params[:promo_code])
          else
            flash[:error] = t('workarea.storefront.flash_messages.promo_code_error')
          end

          Pricing.perform(current_order, current_checkout.shipping)
          render :show
        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/carts_controller.rb
workarea-api-storefront-4.5.6 app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-4.5.5 storefront/app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-storefront-4.5.5 app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-4.5.4 storefront/app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-storefront-4.5.4 app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-4.5.3 storefront/app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-storefront-4.5.3 app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-4.5.2 storefront/app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-storefront-4.5.2 app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-4.5.0 storefront/app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-storefront-4.5.0 app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-4.4.7 storefront/app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-storefront-4.4.7 app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-4.4.6 storefront/app/controllers/workarea/api/storefront/carts_controller.rb
workarea-api-storefront-4.4.6 app/controllers/workarea/api/storefront/carts_controller.rb