Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call empty only on incomplete orders #5827

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions api/app/controllers/spree/api/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ def create

def empty
authorize! :update, @order, order_token
@order.empty!
respond_with(@order, default_template: :show)

if @order.complete?
invalid_resource!(@order)
else
@order.empty!
respond_with(@order, default_template: :show)
end
end

def index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Spree.Views.Cart.EmptyCartButton = Backbone.View.extend({

render: function() {
var isNew = function (item) { return item.isNew() };
this.$el.prop("disabled", !this.collection.length || this.collection.some(isNew));
this.$el.prop("disabled", !this.collection.length || this.collection.some(isNew) || this.model.get("completed_at"));
}
});
57 changes: 26 additions & 31 deletions backend/spec/features/admin/orders/order_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,39 +137,11 @@
expect(page).to have_field('quantity')
end

it "can remove all items with empty cart" do
it "cannot remove all items with a completed order" do
# Wait for the cart contents to be loaded.
expect(page).to have_content("spree t-shirt")

within("#item_total") do
expect(page).to have_content("$40.00")
end

within("#order_total") do
expect(page).to have_content("$40.00")
end

within("#order-total", text: 'Order Total') do
expect(page).to have_content("$40.00")
end

accept_confirm "Are you sure you want to delete this record?" do
click_on 'Empty Cart'
end

expect(page).not_to have_content("spree t-shirt")

# Should have a new item row
expect(page).to have_field('quantity')

within("#item_total") do
expect(page).to have_content("$0.00")
end

within("#order_total") do
expect(page).to have_content("$0.00")
end

expect(page).to have_css('#order-total', visible: false)
expect(page).to have_button("Empty Cart", disabled: true)
end

# Regression test for https://github.com/spree/spree/issues/3862
Expand Down Expand Up @@ -384,6 +356,29 @@
expect(page).not_to have_selector('.fa-arrows-h')
expect(page).not_to have_selector('.fa-trash')
end

context 'order has shipped' do
it 'disables empty cart' do
order = create(:order_ready_to_ship)

visit spree.cart_admin_order_path(order)
order.fulfill!

## simulate shipping order in another tab
shipment = order.shipments.first
order.shipping.ship(
inventory_units: shipment.inventory_units,
stock_location: shipment.stock_location,
address: order.ship_address,
shipping_method: shipment.shipping_method
)

# Make an assertion here about page content to give the JS time
# to load before the next expectation.
expect(page).to have_content("Cart")
expect(page).to have_button("Empty Cart", disabled: true)
end
end
end
end

Expand Down
Loading