Skip to content

Commit

Permalink
Remove unreachable order recovery code
Browse files Browse the repository at this point in the history
Every page load creates a cart order if none is present. So when a user
logs in, they always have an order stored in their session. And
therefore, we never got to recover an old order.

We could have fixed the code to restore old orders. But as far as I can
tell, order recovery hasn't been working for years and I couldn't find
any issue requesting this feature.

If we wanted to implement order recovery, it should probably be designed
more carefully and included in the `current_order` method.
  • Loading branch information
mkllnk committed Aug 19, 2020
1 parent bb3f958 commit 355c5f5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
13 changes: 2 additions & 11 deletions lib/spree/core/controller_helpers/order.rb
Expand Up @@ -68,18 +68,9 @@ def associate_user
session[:guest_token] = nil
end

# Recover incomplete orders from other sessions after logging in.
# Load current order and create a new one if necessary.
def set_current_order
return unless (user = spree_current_user)

last_incomplete_order = user.last_incomplete_spree_order

if session[:order_id].nil? && last_incomplete_order
session[:order_id] = last_incomplete_order.id
end

# Load current order and create a new one if necessary.
current_order(true)
current_order(true) if spree_current_user
end

def current_currency
Expand Down
11 changes: 0 additions & 11 deletions spec/controllers/base_controller_spec.rb
Expand Up @@ -28,17 +28,6 @@ def index
expect(user.orders.count).to eq 1
end

it "uses the last incomplete order" do
last_cart = create(:order, user: user, created_by: user, state: "cart", completed_at: nil)
allow(controller).to receive(:spree_current_user).and_return(user)

expect {
get :index
}.to_not change { Spree::Order.count }

expect(session[:order_id]).to eq last_cart.id
end

it "ignores the last incomplete order" do
# Spree used to merge the last order with the current one.
# And we used to override that logic to delete old incomplete orders.
Expand Down

0 comments on commit 355c5f5

Please sign in to comment.