Sha256: 26566568544dbad29ac299257c1187da460ff24ba4745b1ae184e62dc7f5ebee
Contents?: true
Size: 1.13 KB
Versions: 6
Compression:
Stored size: 1.13 KB
Contents
module Spree module Api module V2 class LineItemsController < Spree::Api::V2::BaseController rescue_from ActiveRecord::RecordNotFound, with: :render_record_not_found_error rescue_from ActiveRecord::RecordInvalid, with: :render_record_invalid_error rescue_from RangeError, with: :render_range_error def create variant = Spree::Variant.find(line_item_params[:variant_id]) order = @current_api_user.orders.find(line_item_params[:order_id]) line_item = order.contents.add(variant, line_item_params[:quantity]) render_instance line_item end private def line_item_params params.require(:line_item).permit(:variant_id, :order_id, :quantity) end def render_range_error render json: error_response(:quantity_too_high), status: 400 end def render_record_invalid_error render json: error_response(:product_out_of_stock), status: 400 end def render_record_not_found_error render json: error_response(:record_not_found), status: 400 end end end end end
Version data entries
6 entries across 6 versions & 2 rubygems