app/controllers/sprangular/carts_controller.rb in sprangular-0.0.1 vs app/controllers/sprangular/carts_controller.rb in sprangular-0.1.0

- old
+ new

@@ -1,14 +1,14 @@ class Sprangular::CartsController < Sprangular::BaseController def show - @order = current_order - if @order - render 'spree/api/orders/show' - else - not_found - end + return not_found unless @order = current_order + + render json: @order, + scope: current_spree_user, + serializer: Sprangular::OrderSerializer, + root: false end # Adds a new item to the order (creating a new order if none already exists) def add_variant order = current_order(create_order_if_necessary: true) @@ -84,8 +84,17 @@ @order.state ='cart' @order.save! render 'spree/api/orders/show' else not_found + end + end + + def guest_login + order = current_order(create_order_if_necessary: true) + if params[:order][:email] =~ Devise.email_regexp && order.update_attribute(:email, params[:order][:email]) + render json: { order: order, email: order.email }, status: 200 + else + invalid_resource!(order) end end end