Class: Comable::CartsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/comable/carts_controller.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#current_customer

Instance Method Details

#addObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/comable/carts_controller.rb', line 6

def add
  product = Comable::Product.where(id: params[:product_id]).first
  return redirect_by_product_not_found unless product

  if product.sku?
    stock = product.stocks.where(id: params[:stock_id]).first
    return redirect_by_product_not_found unless stock
  end

  # TODO: 在庫確認
  current_customer.add_cart_item(stock || product, quantity: params[:quantity].to_i)

  flash[:notice] = I18n.t('comable.carts.add_product')
  redirect_to cart_path
end

#showObject



3
4
# File 'app/controllers/comable/carts_controller.rb', line 3

def show
end

#updateObject



22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/comable/carts_controller.rb', line 22

def update
  stock = Comable::Stock.where(id: params[:stock_id]).first
  return redirect_by_product_not_found unless stock

  # TODO: 在庫確認
  current_customer.reset_cart_item(stock, quantity: params[:quantity].to_i)

  flash[:notice] = I18n.t('comable.carts.update')
  redirect_to cart_path
end