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 unshipped orders #5418

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion api/app/controllers/spree/api/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def create

def empty
authorize! :update, @order, order_token
@order.empty!

@order.empty! unless @order.shipped?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@order.empty! unless @order.shipped?
@order.empty! unless @order.completed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kennyadsl I think we currently allow emptying a complete order as long as it's not been shipped. I'm thinking it may make sense in some instances, but they're probably just corner cases, so we may prefer to change behavior and privilege what makes generally more sense.


respond_with(@order, default_template: :show)
end

Expand Down
27 changes: 27 additions & 0 deletions backend/spec/features/admin/orders/order_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,33 @@
expect(page).not_to have_selector('.fa-arrows-h')
expect(page).not_to have_selector('.fa-trash')
end

context 'and on the cart page the cart is emptied' do
it 'should show the empty cart page' 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
)

click_on 'Empty Cart'

accept_alert 'Are you sure you want to delete this record?' do
click_icon :ok
end

expect(page.current_path).to eq(spree.cart_admin_order_path(order))
expect(page).not_to have_content(order.line_items.first.variant.sku)
end
end
end
end

Expand Down