Class: Caboose::CartController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::CartController
- Defined in:
- app/controllers/caboose/cart_controller.rb
Instance Method Summary collapse
-
#add ⇒ Object
POST /cart/add.
- #get_line_item ⇒ Object
-
#index ⇒ Object
GET /cart.
-
#item_count ⇒ Object
GET /cart/item-count.
-
#list ⇒ Object
GET /cart/items.
-
#remove ⇒ Object
DELETE cart/delete.
-
#update ⇒ Object
PUT cart/update.
Methods inherited from ApplicationController
#before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#add ⇒ Object
POST /cart/add
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/caboose/cart_controller.rb', line 24 def add if @order.line_items.exists?(:variant_id => params[:variant_id]) @line_item = @order.line_items.find_by_variant_id(params[:variant_id]) @line_item.quantity += params[:quantity] ? params[:quantity].to_i : 1 else @line_item = LineItem.new @line_item.variant_id = params[:variant_id] @line_item.order_id = @order.id @line_item.status = 'pending' @line_item.quantity = params[:quantity] ? params[:quantity].to_i : 1 end render :json => { :success => @line_item.save, :errors => @line_item.errors., :item_count => @order.line_items.count } end |
#get_line_item ⇒ Object
5 6 7 |
# File 'app/controllers/caboose/cart_controller.rb', line 5 def get_line_item @line_item = @order.line_items.find(params[:id]) end |
#index ⇒ Object
GET /cart
10 11 |
# File 'app/controllers/caboose/cart_controller.rb', line 10 def index end |
#item_count ⇒ Object
GET /cart/item-count
19 20 21 |
# File 'app/controllers/caboose/cart_controller.rb', line 19 def item_count render :json => { :item_count => @order.line_items.count } end |
#list ⇒ Object
GET /cart/items
14 15 16 |
# File 'app/controllers/caboose/cart_controller.rb', line 14 def list render :json => { :order => @order } end |
#remove ⇒ Object
DELETE cart/delete
46 47 48 |
# File 'app/controllers/caboose/cart_controller.rb', line 46 def remove render :json => { :success => !!@order.line_items.delete(@line_item), :item_count => @order.line_items.count } end |
#update ⇒ Object
PUT cart/update
40 41 42 43 |
# File 'app/controllers/caboose/cart_controller.rb', line 40 def update @line_item.quantity = params[:quantity].to_i render :json => { :success => @line_item.save, :errors => @line_item.errors., :line_item => @line_item, :order_subtotal => @order.calculate_subtotal } end |