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

[#152604] Prevent abandoned reservation carts #2292

Merged
merged 9 commits into from
Jun 2, 2020

Conversation

jhanggi
Copy link
Contributor

@jhanggi jhanggi commented May 12, 2020

Release Notes

Prevent abandoned carts created when clicking an instrument name. This should also help prevent order/detail IDs from growing too fast.

TODO

  • Refactor so there is less duplicated code between the old ReservationsController and the new controller
  • Try to get rid of @add_to_order in the old controller
  • Further testing/QA

Additional Context

Before, if you click an instrument, a new order and order detail are created. Users are often doing this to check the schedule for the instrument. If the user closes the tab comes back to the instrument, yet another order detail is created. We were deleting the cart if the user clicks "Cancel", but the order and order detail IDs were still eaten up.

Now, for normal single-reservation purchases, we go to a parallel controller where we do not create the order/detail prior to the user filling out the form. I did need to rework some of the code to avoid persisting and then rolling back the order/detail. Without these changes, the abandoned carts would not be created, but the IDs would still be used up.

For the order form (purchasing more than one or with other things) or part of a bundle, as well as edit/update, we are continuing to use the old controller.

Some offline discussion for context:

From Aaron:

What we highly suspect is that users are clicking on the instrument links to check out the calendar, and then closing the tab. I assume that if a user clicks on an instrument name bringing them to a "Create Reservation" page, and then clicks "cancel" then this will not generate an abandoned cart? Clicking cancel from the one-off "Create Reservation" page generates the banner: "the product has been removed." I assume the Order Number has still been used up, but that this wouldn't create an "abandoned cart"?

Jason:

You're right about the cancel button. I did a quick test: if you click "cancel" we do remove the order detail (so that number is used up), but we keep the order. That order gets re-used. So clicking an instrument creates, say, "100-100". Click cancel. Click the instrument again. You get "100-101". This won't count as an abandoned cart. However, if you click the browser's back button or close the tab, it leaves both of them hanging around. So "100-100", click on the instrument again, then you get "101-101". "100-100" is an abandoned cart.

@jhanggi jhanggi requested a review from cardoce May 12, 2020 19:52
@@ -0,0 +1,84 @@
class SingleReservationsController < ApplicationController
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not in love with the name--especially in the route/url--but I haven't come up with anything better.

load_resource :facility, find_by: :url_name
load_resource :instrument, through: :facility, find_by: :url_name
before_action :build_order
before_action { @submit_action = facility_instrument_single_reservations_path }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seemed to be the simplest way of still using the same view partial as the old reservations form. I'm open to other ideas.

render "reservations/new"
end

def create
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied this from ReservationsController and cleaned out some of the unneeded pieces (like merge orders). I still want to do some further refactors to remove some of the duplication.

@instrument.min_reserve_mins.to_i > 0 ? @instrument.min_reserve_mins : 30
end

def set_windows
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This and some of the other helper methods are ripe for refactoring.

@@ -206,6 +206,16 @@ def assign_actuals_off_reserve
self.actual_end_at ||= reserve_end_at
end

def valid_as_user?(user)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is essentially a duplicate of save_as_user, but with valid?. I might try again to DRY it up, but my initial attempts didn't work.

@jhanggi jhanggi marked this pull request as ready for review May 18, 2020 19:01
@jhanggi jhanggi requested a review from a team May 18, 2020 19:01
@jhanggi jhanggi requested a review from a team as a code owner May 18, 2020 19:01
@jhanggi jhanggi merged commit 819d532 into master Jun 2, 2020
@jhanggi jhanggi deleted the no_cart_reservations_152604 branch June 2, 2020 16:39
@jhanggi jhanggi added the NU label Jun 19, 2020
jhanggi added a commit that referenced this pull request Jun 29, 2020
# Release Notes

Fixes the "Cancel" button behavior on new reservation page.

# Additional Context

This does modify behavior a little bit, but the behavior before felt unexpected.

There are a couple ways to get to this page:

* Clicking on an instrument from the facility homepage. This is the new order-less reservation flow from #2292. 
  * Before: The cancel button was missing
  * After: The cancel button will return you the facility homepage.
* The reservation was in the cart because it was a bundle.
  * Before: The cancel button brought you back to the facility homepage, but left everything in your cart
  * After: The cancel button brings you back to your cart
* The reservation was in a cart because it was added with the order form
  * Before: The order detail was removed from your cart (this seemed wrong) and brought you to the facility homepage
  * After: You are returned to your cart and everything is left alone. If you want to remove the line from your cart, you can use the "Remove" button
* Adding to an existing order
  * Before: You are brought back to the existing order's page and the line item still requires resolution.
  * After: Same behavior
jhanggi added a commit that referenced this pull request Jul 15, 2020
# Release Notes

Fix hard error when a next reservation cannot be found.

# Additional Context

Easy way to reproduce: create a series of schedule rules that does not include the current day (e.g. Wednesday). Try to create a new reservation.

Caused by a bad copy/paste in #2292.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants