Skip to content

Support adding items to cart without logging in - #156

Open
TanmayS0406 wants to merge 21 commits into
dotnet:mainfrom
TanmayS0406:issue27
Open

TanmayS0406 wants to merge 21 commits into
dotnet:mainfrom
TanmayS0406:issue27

Conversation

@TanmayS0406

@TanmayS0406 TanmayS0406 commented Jan 11, 2024 •

Copy link
Copy Markdown

closes #27 , changes are related to WebApp.

I want to propose an idea to store cart objects into session untill user log-in. When user log-in, this session cart will be converted into redis cart for user.

Comment thread Directory.Packages.props Resolved
Comment thread src/WebApp/Services/BasketState.cs Resolved
@TanmayS0406
TanmayS0406 marked this pull request as ready for review January 14, 2024 13:16
@TanmayS0406

Copy link
Copy Markdown
Author

@captainsafia are you going to review this or anyone else will continue with review process? 😕

@captainsafia captainsafia changed the title Issue27 Support adding items to cart without logging in Jan 16, 2024
@captainsafia

Copy link
Copy Markdown
Contributor

@ks1990cn Considering the scope of this change, we may want to incorporate other reviewers in here, but I can take a look for now.

Have you verified that this works end-to-end? I'm not able to checkout after adding an item to the cart while being logged out.

@TanmayS0406

TanmayS0406 commented Jan 17, 2024 •

Copy link
Copy Markdown
Author

@ks1990cn Considering the scope of this change, we may want to incorporate other reviewers in here, but I can take a look for now.

Have you verified that this works end-to-end? I'm not able to checkout after adding an item to the cart while being logged out.

Correct me if I misunderstood, as per issue #27 , we should be able to add item to cart when user is not logged-in. User need to log-in before check out. On this functionality I have worked on.

Testing27

@captainsafia

Copy link
Copy Markdown
Contributor

Correct me if I misunderstood, as per issue #27 , we should be able to add item to cart when user is not logged-in. User need to log-in before check out. On this functionality I have worked on.

Thanks for sharing the recording. For whatever reason, I don't see the same behavior when I repro locally. The "Checkout" button doesn't redirect to the login page...

@TanmayS0406

Copy link
Copy Markdown
Author

Correct me if I misunderstood, as per issue #27 , we should be able to add item to cart when user is not logged-in. User need to log-in before check out. On this functionality I have worked on.

Thanks for sharing the recording. For whatever reason, I don't see the same behavior when I repro locally. The "Checkout" button doesn't redirect to the login page...

I am not sure, can you ask anyone else to try this?

@TanmayS0406

Copy link
Copy Markdown
Author

Correct me if I misunderstood, as per issue #27 , we should be able to add item to cart when user is not logged-in. User need to log-in before check out. On this functionality I have worked on.

Thanks for sharing the recording. For whatever reason, I don't see the same behavior when I repro locally. The "Checkout" button doesn't redirect to the login page...

I am not sure, can you ask anyone else to try this?

Take recent code changes, I have made commits after our last comments!! @captainsafia

@TanmayS0406

Copy link
Copy Markdown
Author

@captainsafia I am waiting for PR review again🥺🥺, is there any luck with running it locally?

@captainsafia captainsafia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I realized why it was failing to redirect to the login page -- seems to be an issue with my browser and not the code change.

Tagging @mgravell to sanity check the use of distributed caching here.

@TanmayS0406

TanmayS0406 commented Jan 24, 2024 •

Copy link
Copy Markdown
Author

@captainsafia can you please review again, made requested changes?

@TanmayS0406

Copy link
Copy Markdown
Author

@jamesmontemagno @adityamandaleeka Looks like you also work on this repo, can you review this if @captainsafia is no more looking in this PR.

Just wanted to know till when I can expect review again? I'm so excited to continue contribution on this!

@TanmayS0406

Copy link
Copy Markdown
Author

Hii @captainsafia , will you gonna see this PR again? It's been long time now

@captainsafia

captainsafia commented Apr 23, 2024 •

Copy link
Copy Markdown
Contributor

@ks1990cn Thanks for your eagerness here, Tanmay! At the moment, we're trying to prioritize bug fixes and quality improvements on eShop before taking new features so we'd like to hold off on merging this change at the moment.

@cwash05

cwash05 commented May 20, 2024

Copy link
Copy Markdown

@captainsafia any update on this pr? this feature is very much needed for my scenario.

@adityamandaleeka

Copy link
Copy Markdown
Member

@cwash05 As @captainsafia mentioned above, we're prioritizing quality/fixes in this project for now so we are holding off on adding functionality.

It's not clear what you mean by this being needed for your scenario. This PR has no impact on the product capabilities of ASP.NET Core, Aspire, or any other technology we ship; this repo/project is merely a sample.

TanmayS0406 and others added 4 commits August 21, 2024 11:55
Conflict in ItemPage.razor: kept main's new item page layout (back link,
image zoom, item-buy section, price formatting) and re-applied this
branch's change on top of it, so the add-to-cart form no longer depends
on being logged in and always shows the "Add to shopping bag" button.

BasketState implements IBasketState again. The interface had been
dropped on this branch, and main's ChatState now takes an IBasketState,
so the WebApp did not compile without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves the logged-in/anonymous decision into BasketState so callers no
longer branch on it. Until the user logs in, the basket is kept in the
session; on login it is merged into the basket saved for the user
(quantities are summed) instead of replacing it.

- BasketState: GetBasketItemsAsync, AddAsync and SetQuantityAsync work for
  both kinds of user; the session is read on demand, so BasketState no
  longer fails when there is no HttpContext (e.g. the chatbot circuit).
- Anonymous users can now change quantities and remove items in the bag.
- ItemPage shows the "in your bag" count for anonymous users on load.
- CartPage no longer requires login; checkout still does.
- Checkout sends a user who is not logged in to the login page instead of
  placing the order.
- The login cookie is rejected once its access token has expired, so the
  user is treated as logged out instead of hitting Unauthenticated from the
  Basket API.
- The chatbot's add-to-cart tells anonymous users to log in.
- Adds e2e tests for adding while logged out and for keeping the items
  after logging in.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Rejecting a login cookie whose access token has expired fixes a separate,
existing problem (any basket write fails with Unauthenticated once the
token is older than 2 hours) and is not needed to support an anonymous
cart. It can be proposed on its own.

Also drops a stray blank line in AddApplicationServices.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@TanmayS0406

Copy link
Copy Markdown
Author

Hi @captainsafia @adityamandaleeka ,

Years have passed still even no one looked into this PR. I have updated PR with latest code after claude PR review.

Can you confirm what is your priority these days?

Please reivew this PR before I retire from software industry 🤣

The quantities of the session basket and the saved basket were added up
as int, which throws OverflowException at login when they are large
enough. Add them as long and clamp the result to int.MaxValue.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

Add items to cart without logging in

4 participants