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

W-15040197: lazy basket creation #1677

Merged
merged 6 commits into from
Feb 28, 2024

Conversation

alexvuong
Copy link
Collaborator

Description

Current: today the PWA Kit calls SCAPI endpoints to create a basket on session start. This has two consequences:

  • An extra API that may/may not be helpful, this takes up more network bandwidth. A user may not interact with the baskets until they add an item to basket
  • In hybrid sites create the possibility of a condition between cart instantiation and retrieval between SFRA and PWA Kit

This PR added a helper function in commerce-sdk-react useShopperBasketsMutationHelper that returns a map of helpers. Currently, it has addItemToNewOrExistingBasket that is responsible for managing the process of adding an item to a basket.

If a basket already exists, add the item to the basket immediately.
If a basket does not exist, create a new basket using the createBasket mutation
and then add the item to the newly created basket using the addItemToBasket mutation.
addAnItemToCart is the only mutation that needs to be aware of basket creation. The other mutations (e.g removeItem or updateItem or the rest) are actions that always come after addAnItemToCart has been called.

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • add a helper in commerce react
  • product detail and wishlist page in retail app

How to Test-Drive This PR

  • Check out code
  • npm ci
  • Start the retail app
  • Delete your localstrage and cookie
  • Confirm that when the app boosts up, basket creation is not called until and an item is added to cart on PDP or on wishlist page

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@vcua-mobify
Copy link
Contributor

vcua-mobify commented Feb 28, 2024

Verified the changes are working as expected after fixing an issue with the proxy configuration (see #1678)

When I load the page, I see a request to fetch baskets and the total returned is 0, which shows that no basket was created. I also see that basket creation occurs on add to cart

Approving

@alexvuong alexvuong merged commit 99e109b into v3/template-retail-react-app Feb 28, 2024
28 checks passed
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.

3 participants