Sha256: 17076aabc5255c74138cedfa92cb40174a09b2d02a308494c65fea6e6a43bc7e
Contents?: true
Size: 1.71 KB
Versions: 4
Compression:
Stored size: 1.71 KB
Contents
module Caboose class CartController < Caboose::ApplicationController # GET /cart def index end # GET /cart/items def list render :json => @order.as_json(:include => [ { :line_items => { :include => { :variant => { :include => :product }}}}, { :order_packages => { :include => [:shipping_package, :shipping_method] }}, :customer, :shipping_address, :billing_address, :order_transactions ]) end # GET /cart/item-count def item_count render :json => { :item_count => @order.item_count } end # POST /cart def add variant_id = params[:variant_id] qty = params[:quantity] ? params[:quantity].to_i : 1 if @order.line_items.exists?(:variant_id => variant_id) li = @order.line_items.find_by_variant_id(variant_id) li.quantity += qty else li = LineItem.new( :order_id => @order.id, :variant_id => variant_id, :quantity => qty, :status => 'pending' ) end render :json => { :success => li.save, :errors => li.errors.full_messages, :item_count => @order.item_count } end # PUT /cart/:line_item_id def update li = LineItem.find(params[:line_item_id]) li.quantity = params[:quantity].to_i li.save li.destroy if li.quantity == 0 @order.calculate_subtotal render :json => { :success => true } end # DELETE /cart/:line_item_id def remove li = LineItem.find(params[:line_item_id]).destroy render :json => { :success => true, :item_count => @order.line_items.count } end end end
Version data entries
4 entries across 4 versions & 1 rubygems