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

Create new Guest Cart when Checkout resets #917

Merged
merged 4 commits into from
Mar 5, 2019
Merged

Conversation

supernova-at
Copy link
Contributor

@supernova-at supernova-at commented Feb 19, 2019

Description

This PR creates a new guest cart whenever the checkout/reset action is triggered.

The Continue Shopping button triggers this action and thus creates a new guest cart on click. The user can add items to the newly created cart without error.

Alternative Solutions

Move the Dispatch

The following code appears when trying to add an item to the cart:

        } catch (error) {
            const { response, noGuestCartId } = error;

            dispatch(actions.addItem.receive(error));

            // check if the guest cart has expired
            if (noGuestCartId || (response && response.status === 404)) {
                // if so, then delete the cached ID...
                // in contrast to the save, make sure storage deletion is
                // complete before dispatching the error--you don't want an
                // upstream action to try and reuse the known-bad ID.
                await clearGuestCartId();
                // then create a new one
                await dispatch(createGuestCart());
                // then retry this operation
                return thunk(...arguments);
            }
        }

We could move the dispatch(actions.addItem.receive(error)); line to after the "no guest cart" retry logic so that the error only gets dispatched when there is truly an unhandled error.

This "no guest cart" retry logic does appear in many places, however, so we'd likely want to make this change app-wide (in all the asyncActions.js files).

Handle the Error in the Reducer

This has the effect of signaling the backstop error catching reducer that we're handling the error (by retrying) and that it shouldn't pop up a notification.

Related Issue

Closes #916 .

Motivation and Context

This change allows users to add items to their cart after a successful purchase.

How Has This Been Tested?

See the repro steps in #916.

Screenshots (if appropriate):

Proposed Labels for Change Type/Package

BUG

venia-concept

Checklist:

  • I have read the CONTRIBUTING document.
  • I have linked an issue to this PR.
  • I have indicated the change type and relevant package(s).
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All CI checks are green (linting, build/deploy, etc).
  • At least one core contributor has approved this PR.

@vercel
Copy link

vercel bot commented Feb 19, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

@supernova-at
Copy link
Contributor Author

Honestly I prefer this solution:

Create a new Guest Cart during checkout/reset

This action gets triggered when the Continue Shopping button is clicked.

but I wanted to get a solution up quickly to discuss the options.

@sirugh
Copy link
Contributor

sirugh commented Feb 19, 2019

I'm a little confused -- what was the actual source of the error?

@supernova-at
Copy link
Contributor Author

supernova-at commented Feb 19, 2019

I'm a little confused -- what was the actual source of the error?

Oh, sorry - each cart has an id. After submitting an order, we wipe out that cart's id. When you attempt to add a new item, the error is that you can't because you don't have a cart.

In the current code we catch that error, create a new cart, and then retry adding the item. But we don't do any of that in redux, which is where the new backstop error notification reducer is looking to see if the error got handled. It thinks that the error went unhandled, so it pops up the error notification.

The solution I prefer is to create a new cart when the "continue shopping" button is clicked.
This way when you attempt to add an item, a cart already exists and everyone is happy.

@sirugh
Copy link
Contributor

sirugh commented Feb 19, 2019

The solution I prefer is to create a new cart when the "continue shopping" button is clicked.
This way when you attempt to add an item, a cart already exists and everyone is happy.

I think that makes a lot of sense!

@supernova-at supernova-at changed the title Moves error dispatch after retry logic Create new Guest Cart when Checkout resets Feb 19, 2019
@coveralls
Copy link

coveralls commented Feb 19, 2019

Coverage Status

Coverage increased (+0.006%) to 71.13% when pulling 3125e62 on supernova/916 into 7174988 on release/2.0.

@jimbo jimbo merged commit e5032fe into release/2.0 Mar 5, 2019
@jimbo jimbo deleted the supernova/916 branch March 5, 2019 18:17
supernova-at pushed a commit that referenced this pull request Mar 7, 2019
* Create script for generating reference docs from source code

* Fix develop script bug that makes the server reload continuously after a change

* Clean up reference table template

* Use new auto-generated content in topics

* Update docblocks in source

* Add clean command to scripts to prevent usage of stale content between develop runs

* Run prettier

* Adds unit tests to app reducer (#921)

* Adds unit tests to app reducer
* Updates tests to be less fragile

* Add unit tests to cart reducer (#928)

* Adds unit tests to catalog reducer (#931)

* [DOCUMENTATION] cherry pick 3.0 doc updates (#992)

* Fixed typo mistake (#939)

* Fixed typo mistake (#969)

* Scroll to top on Product mount (#832)

* Create new guest cart when checkout resets (#917)
supernova-at pushed a commit that referenced this pull request Mar 21, 2019
* Merge branch 'release/2.0' of /home/d.shmaliuk/pwa-studio with conflicts.

* "Remove Item" in Minicart usability issue #661.
Added loading element in MiniCart, after delete item.

* "Remove Item" in Minicart usability issue #661.
Added check for loadingElement object.

* "Remove Item" in Minicart usability issue #661.
Added check for loadingElement object.

* "Remove Item" in Minicart usability issue #661.
Added check for loadingElement object.

* Adds unit tests to app reducer (#921)

* Adds unit tests to app reducer
* Updates tests to be less fragile

* Add unit tests to cart reducer (#928)

* Adds unit tests to catalog reducer (#931)

* [DOCUMENTATION] cherry pick 3.0 doc updates (#992)

* Fixed typo mistake (#939)

* Fixed typo mistake (#969)

* Scroll to top on Product mount (#832)

* Create new guest cart when checkout resets (#917)

* Purchase History unit tests and refactors (#891)

* Simplifies and adds tests to purchaseHistory throughout the app

* Simplifies and adds tests to purchaseHistory throughout the app

* Adds snapshot test to PurchaseHistory Filter component

* Mask specific product instead of entire cart during removeItem action

* Remove unnecessary stuff.

* Cleanup code and extra additions.

* "Remove item" in minicart usability issue #661
Solved problem in file kebab.js

* [FEATURE] "Remove item" in minicart usability issue
Refactoring minicart.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants