Class: PowerShop::CartController

Inherits:
ApplicationController show all
Defined in:
app/controllers/power_shop/cart_controller.rb

Overview

Controller represents methods for cart

Instance Method Summary collapse

Methods inherited from ApplicationController

#cart

Instance Method Details

#add_productObject

Public: add products to shopping cart if request is simple post redirects back if request is ajax respond with json message

Returns text/html or text/json



13
14
15
16
17
18
19
20
21
# File 'app/controllers/power_shop/cart_controller.rb', line 13

def add_product
  cart.add(@product, @product.price, params.fetch(:quantity, 1))

  if request.xhr?
    render_json_cart
  else
    redirect_to :back
  end
end

#delete_productObject



23
24
25
26
27
# File 'app/controllers/power_shop/cart_controller.rb', line 23

def delete_product
  # TODO: 99 - its hack for remove all items :)
  cart.remove(@product, 99)
  redirect_to :back
end

#showObject

Pubclic: show cart page TODO: preload associations

Returns text/html



33
34
35
# File 'app/controllers/power_shop/cart_controller.rb', line 33

def show
  @cart = cart
end