Skip to content

Commit

Permalink
Fix error added when resetting order flow on an empty order
Browse files Browse the repository at this point in the history
#4369 introduced a regression
where when calling `Spree::Order#restart_checkout_flow` on an empty
order, an error would be added to the order. That happened when calling
`#next` and the validation failed because no line items were present.

We restore the previous behavior where we only try going to the
`"address"` state if the order has line items.
  • Loading branch information
waiting-for-dev committed Aug 11, 2023
1 parent e3028ba commit 7bea6bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def restart_checkout_flow
state: 'cart',
updated_at: Time.current
)
self.next
self.next if line_items.any?
end

def refresh_shipment_rates
Expand Down
8 changes: 8 additions & 0 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,14 @@ def merge!(other_order, user = nil)
order = create(:order, state: "delivery")
expect{ order.restart_checkout_flow }.to change{ order.state }.from("delivery").to("cart")
end

it "doesn't add errors to the order" do
order = create(:order, state: "delivery", line_items: [])

order.restart_checkout_flow

expect(order.errors).to be_empty
end
end
end

Expand Down

0 comments on commit 7bea6bd

Please sign in to comment.