From 2bdbd4ee66583455870c9d8edb419395032adfa6 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Mon, 27 Mar 2023 16:27:45 +0200 Subject: [PATCH] [API] Remove support for passing variant and quantity creating api shipments Now you should create a shipment and after that, use the dedicated endpoint to add stuff to it: PUT /api/shipments/{shipment_number}/add Ref https://github.com/solidusio/solidus/pull/4387 --- .../spree/api/shipments_controller.rb | 26 --------- api/openapi/solidus-api.oas.yml | 12 ---- api/spec/requests/spree/api/shipments_spec.rb | 55 ------------------- 3 files changed, 93 deletions(-) diff --git a/api/app/controllers/spree/api/shipments_controller.rb b/api/app/controllers/spree/api/shipments_controller.rb index b21a1a12008..7268f615f47 100644 --- a/api/app/controllers/spree/api/shipments_controller.rb +++ b/api/app/controllers/spree/api/shipments_controller.rb @@ -40,30 +40,8 @@ def select_shipping_method def create authorize! :create, Shipment - @shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id)) - if passing_deprecated_params_on_create? - Spree::Deprecation.warn <<~MSG - Passing `quantity` or `variant_id` to - - POST /api/shipments - - is deprecated and won't be allowed anymore starting from Solidus 4.0. - Instead, create an empty shipment and add items to it subsequently using - the dedicated endpoint: - - PUT /api/shipments/{shipment_number}/add - - MSG - - quantity = params[:quantity].to_i - variant = Spree::Variant.unscoped.find(params[:variant_id]) - @order.contents.add(variant, quantity, { shipment: @shipment }) - @shipment.save! - @shipment.reload - end - respond_with(@shipment, default_template: :show) end @@ -149,10 +127,6 @@ def load_transfer_params authorize! :create, Shipment end - def passing_deprecated_params_on_create? - params[:variant_id] || params[:quantity] - end - def find_order_on_create @order = Spree::Order.find_by!(number: params[:shipment][:order_id]) authorize! :show, @order diff --git a/api/openapi/solidus-api.oas.yml b/api/openapi/solidus-api.oas.yml index 365c1367a2f..123e734eb83 100644 --- a/api/openapi/solidus-api.oas.yml +++ b/api/openapi/solidus-api.oas.yml @@ -5290,10 +5290,6 @@ paths: Creates a shipment. Please note that this request can be only performed by users with the `create` permission on the shipment. - - **Deprecation Warning**: Adding items to the shipment via this endpoint - is deprecated. Instead, create an empty shipment and populate it with - the dedicated endpoint [to add items to the shipment](/docs/solidus/7078dbcf415ac-add-shipment-item). operationId: create-shipment tags: - Shipments @@ -5307,18 +5303,10 @@ paths: properties: stock_location_id: type: integer - variant_id: - type: integer - deprecated: true - quantity: - type: integer - deprecated: true examples: Example: value: stock_location_id: 0 - variant_id: 0 - quantity: 0 /shipments/transfer_to_location: post: responses: diff --git a/api/spec/requests/spree/api/shipments_spec.rb b/api/spec/requests/spree/api/shipments_spec.rb index 450ed598e5b..7567963e56b 100644 --- a/api/spec/requests/spree/api/shipments_spec.rb +++ b/api/spec/requests/spree/api/shipments_spec.rb @@ -78,61 +78,6 @@ module Spree::Api expect(json_response['exception']).to eq("param is missing or the value is empty: stock_location_id") end end - - context 'when passing a variant along' do - let(:params) do - { - variant_id: stock_location.stock_items.first.variant.to_param, - shipment: { order_id: order.number }, - stock_location_id: stock_location.to_param - } - end - - it 'creates a new shipment with a deprecation message' do - expect(Spree::Deprecation).to receive(:warn).with(/variant_id/) - - subject - expect(response).to be_ok - expect(json_response).to have_attributes(attributes) - end - end - - context 'when passing a variant and a quantity along' do - let(:params) do - { - variant_id: stock_location.stock_items.first.variant.to_param, - quantity: 2, - shipment: { order_id: order.number }, - stock_location_id: stock_location.to_param - } - end - - it 'creates a new shipment with a deprecation message' do - expect(Spree::Deprecation).to receive(:warn).with(/variant_id/) - - subject - expect(response).to be_ok - expect(json_response).to have_attributes(attributes) - end - end - - context 'when passing a quantity along (without a variant_id)' do - let(:params) do - { - quantity: 1, - shipment: { order_id: order.number }, - stock_location_id: stock_location.to_param - } - end - - it 'returns proper error with a deprecation warning' do - expect(Spree::Deprecation).to receive(:warn).with(/variant_id/) - - subject - expect(response.status).to eq(404) - expect(json_response['error']).to eq("The resource you were looking for could not be found.") - end - end end it 'can update a shipment' do