Skip to content

Commit

Permalink
[API] Remove support for passing variant and quantity creating api sh…
Browse files Browse the repository at this point in the history
…ipments

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 solidusio#4387
  • Loading branch information
kennyadsl committed Apr 12, 2023
1 parent d0c6e6f commit 59c3fa8
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 93 deletions.
26 changes: 0 additions & 26 deletions api/app/controllers/spree/api/shipments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions api/openapi/solidus-api.oas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
55 changes: 0 additions & 55 deletions api/spec/requests/spree/api/shipments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 59c3fa8

Please sign in to comment.