Skip to content

Commit

Permalink
Add destroyed variants to be removed from a shipment
Browse files Browse the repository at this point in the history
* Previously, if a variant was destroyed it was impossible to remove it
  from a shipment. This change allows all variants to be removed.

Fixes #5268
  • Loading branch information
dkubb authored and Jeff Dutil committed Aug 26, 2014
1 parent 14f9046 commit 8efd648
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions api/app/controllers/spree/api/shipments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def create
@order = Spree::Order.find_by!(number: params[:shipment][:order_id])
authorize! :read, @order
authorize! :create, Shipment
variant = Spree::Variant.find(params[:variant_id])
quantity = params[:quantity].to_i
@shipment = @order.shipments.create(stock_location_id: params[:stock_location_id])
@order.contents.add(variant, quantity, {shipment: @shipment})
Expand Down Expand Up @@ -45,7 +44,6 @@ def ship
end

def add
variant = Spree::Variant.find(params[:variant_id])
quantity = params[:quantity].to_i

@shipment.order.contents.add(variant, quantity, {shipment: @shipment})
Expand All @@ -54,7 +52,6 @@ def add
end

def remove
variant = Spree::Variant.find(params[:variant_id])
quantity = params[:quantity].to_i

@shipment.order.contents.remove(variant, quantity, {shipment: @shipment})
Expand Down Expand Up @@ -97,6 +94,10 @@ def shipment_params
{}
end
end

def variant
@variant ||= Spree::Variant.unscoped.find(params.fetch(:variant_id))
end
end
end
end
11 changes: 10 additions & 1 deletion api/spec/controllers/spree/api/shipments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@
api_put :remove, { variant_id: variant.to_param, quantity: 1 }
response.status.should == 200
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 1
end
end

it 'removes a destroyed variant from a shipment' do
order.contents.add(variant, 2)
variant.destroy

api_put :remove, { variant_id: variant.to_param, quantity: 1 }
response.status.should == 200
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 1
end
end

context "can transition a shipment from ready to ship" do
Expand Down

0 comments on commit 8efd648

Please sign in to comment.