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

[16.0][IMP] shopinvader signin jwt anonymous cart #1523

Conversation

qgroulard
Copy link
Contributor

@qgroulard qgroulard commented Mar 25, 2024

Handle anonymous cart at signin:

  • If there is an anonymous cart, transfer it to the real partner (merge with the previous partner cart if there is one)
  • Remove the anonymous partner
  • Delete the anonymous cookie

Discussion threads regarding /signin and anonymous carts can be found here: #1428 and #1510

@qgroulard qgroulard force-pushed the 16.0-shopinvader_signin_anonymous_cart-qgr branch 3 times, most recently from b54f554 to 68e4be1 Compare April 3, 2024 09:11
@qgroulard qgroulard marked this pull request as ready for review April 3, 2024 09:29
"shopinvader_api_signin_jwt.signin_router.helper"
]._create_partner_from_payload(payload)
response.status_code = status.HTTP_201_CREATED
anonymous_partner = env["res.partner"]._get_anonymous_partner__cookie(
Copy link
Contributor

Choose a reason for hiding this comment

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

@qgroulard who is supposed to call _create_anonymous_partner__cookie?
Shouldn't it happen the 1st time you call a cart endpoint w/o authenticated customer?

Copy link
Member

Choose a reason for hiding this comment

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

@simahawk this is done by the auth_jwt_authenticated_or_anonymous_partner_autocreate FastAPI depend. There is an example in #1364 where the cart routes are mounted with that authentication method.

if not cart:
cart = self._create_empty_cart(partner_id)
cart._update_cart_lines_from_cart(self)
self.unlink()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why deleting the cart?
And what about the UUID?
If you delete it you should keep they UUID for ext reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, it doesn't make sense to delete the cart there.

I need to delete the anonymous cart to be able to delete the anonymous partner. I do it in the /signin route now.

@qgroulard qgroulard force-pushed the 16.0-shopinvader_signin_anonymous_cart-qgr branch from 68e4be1 to cf58a78 Compare April 17, 2024 09:43

def _transfer_cart(self, partner_id):
"""
Transfer the current cart to a given partner
Copy link
Member

Choose a reason for hiding this comment

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

Maybe expand this docstring. Something like this?

Suggested change
Transfer the current cart to a given partner
Copy the lines of this cart to the current cart of a given partner. Merge lines of identical products.
If the partner does not have a current cart yet, create one.
This cart is not deleted. It is the responsibility of the caller to remove it if desired.

Copy link
Contributor

Choose a reason for hiding this comment

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

This cart is not deleted. It is the responsibility of the caller to remove it if desired.

this part is very helpful 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a delete option could be useful?

Copy link
Member

Choose a reason for hiding this comment

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

Or another method _transfer_and_unlink_cart

Copy link
Member

Choose a reason for hiding this comment

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

But in the end it's simply a matter of adding an unlink line at the call site, so a different method or a delete flag may not ease the life of the caller that much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the input.

I like to keep it simple, I think this is not necessary to add a delete option or a _transfer_and_unlink_cart() method. As @sbidoul said, this is just a matter of adding an unlink after the call.

I have added the suggested docstring.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine w/ the proposed solution, however... I don't really see the point for keeping this cart.
Especially in the ctx of the anon partner you MUST delete the cart.
As this meth is called "transfer cart" where do you see a use for keeping the old cart?

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 don't know, you tell me 😂 I thought you had a use case for that, as you started this discussion with this comment:

Why deleting the cart?
And what about the UUID?
If you delete it you should keep they UUID for ext reference.

For me personally, the only use I have of this method is in the context of anonymous partners. But I like the idea to keep this method atomic and let people do what they want with the cart.

@qgroulard qgroulard force-pushed the 16.0-shopinvader_signin_anonymous_cart-qgr branch from cf58a78 to ba4e512 Compare April 24, 2024 06:04
@sebastienbeau sebastienbeau added this to the 16.0 milestone Jun 3, 2024
Copy link
Collaborator

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

@qgroulard Can you add some doc on how to enable this functionality when defining your fastapi app (the required addon, how you mount the router and define the authentication policy, ...)

@lmignon
Copy link
Collaborator

lmignon commented Jun 4, 2024

Documentation will be added into another PR

@lmignon
Copy link
Collaborator

lmignon commented Jun 4, 2024

/ocabot merge minor

@shopinvader-git-bot
Copy link

This PR looks fantastic, let's merge it!
Prepared branch 16.0-ocabot-merge-pr-1523-by-lmignon-bump-minor, awaiting test results.

@shopinvader-git-bot shopinvader-git-bot merged commit d8fab63 into shopinvader:16.0 Jun 4, 2024
3 checks passed
@shopinvader-git-bot
Copy link

Congratulations, your PR was merged at 97e8563. Thanks a lot for contributing to shopinvader. ❤️

@lmignon lmignon deleted the 16.0-shopinvader_signin_anonymous_cart-qgr branch June 4, 2024 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants