Class: Workarea::Api::Storefront::CartsController

Inherits:
ApplicationController
  • Object
show all
Includes:
CurrentCheckout
Defined in:
app/controllers/workarea/api/storefront/carts_controller.rb

Instance Method Summary collapse

Methods included from CurrentCheckout

#current_checkout, #current_order

Methods inherited from ApplicationController

#assert_current_metrics_id, #cache_page, #skip_session

Methods included from Authentication

#authentication?, #current_user, find_user

Instance Method Details

#add_promo_codeObject



34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/workarea/api/storefront/carts_controller.rb', line 34

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

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/workarea/api/storefront/carts_controller.rb', line 17

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

#indexObject



11
12
13
14
15
# File 'app/controllers/workarea/api/storefront/carts_controller.rb', line 11

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

#showObject



30
31
32
# File 'app/controllers/workarea/api/storefront/carts_controller.rb', line 30

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