Class: Spree::Api::ShipmentsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Spree::Api::ShipmentsController
- Defined in:
- app/controllers/spree/api/shipments_controller.rb
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
- #add ⇒ Object
- #create ⇒ Object
- #mine ⇒ Object
- #ready ⇒ Object
- #remove ⇒ Object
- #ship ⇒ Object
- #transfer_to_location ⇒ Object
- #transfer_to_shipment ⇒ Object
- #update ⇒ Object
Instance Method Details
#add ⇒ Object
66 67 68 69 70 71 |
# File 'app/controllers/spree/api/shipments_controller.rb', line 66 def add quantity = params[:quantity].to_i @shipment.order.contents.add(variant, quantity, {shipment: @shipment}) respond_with(@shipment, default_template: :show) end |
#create ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/spree/api/shipments_controller.rb', line 23 def create # TODO Can remove conditional here once deprecated #find_order is removed. unless @order.present? @order = Spree::Order.find_by!(number: params[:shipment][:order_id]) :read, @order end :create, Shipment quantity = params[:quantity].to_i @shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id)) @order.contents.add(variant, quantity, {shipment: @shipment}) @shipment.save! respond_with(@shipment.reload, default_template: :show) end |
#mine ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/spree/api/shipments_controller.rb', line 10 def mine if current_api_user @shipments = Spree::Shipment .reverse_chronological .joins(:order) .where(spree_orders: {user_id: current_api_user.id}) .includes(mine_includes) .ransack(params[:q]).result.page(params[:page]).per(params[:per_page]) else render "spree/api/errors/unauthorized", status: :unauthorized end end |
#ready ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/spree/api/shipments_controller.rb', line 45 def ready unless @shipment.ready? if @shipment.can_ready? @shipment.ready! else logger.error("cannot_ready_shipment shipment_state=#{@shipment.state}") render 'spree/api/shipments/cannot_ready_shipment', status: 422 and return end end respond_with(@shipment, default_template: :show) end |
#remove ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/spree/api/shipments_controller.rb', line 73 def remove quantity = params[:quantity].to_i if @shipment.pending? @shipment.order.contents.remove(variant, quantity, {shipment: @shipment}) @shipment.reload if @shipment.persisted? respond_with(@shipment, default_template: :show) else @shipment.errors.add(:base, :cannot_remove_items_shipment_state, state: @shipment.state) invalid_resource!(@shipment) end end |
#ship ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'app/controllers/spree/api/shipments_controller.rb', line 57 def ship :ship, @shipment unless @shipment.shipped? @shipment.suppress_mailer = (params[:send_mailer] == 'false') @shipment.ship! end respond_with(@shipment, default_template: :show) end |
#transfer_to_location ⇒ Object
86 87 88 89 90 |
# File 'app/controllers/spree/api/shipments_controller.rb', line 86 def transfer_to_location @stock_location = Spree::StockLocation.find(params[:stock_location_id]) @original_shipment.transfer_to_location(@variant, @quantity, @stock_location) render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201 end |
#transfer_to_shipment ⇒ Object
92 93 94 95 96 |
# File 'app/controllers/spree/api/shipments_controller.rb', line 92 def transfer_to_shipment @target_shipment = Spree::Shipment.find_by!(number: params[:target_shipment_number]) @original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment) render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201 end |
#update ⇒ Object
39 40 41 42 43 |
# File 'app/controllers/spree/api/shipments_controller.rb', line 39 def update @shipment.update_attributes_and_order(shipment_params) respond_with(@shipment.reload, default_template: :show) end |