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

use more specific way to check if a backup cart is existing #868

Closed
wants to merge 1 commit into from

Conversation

netzkollektiv
Copy link

We're having problems with the loading behavior of the Kiener\MolliePayments\Service\Cart\CartBackupService. Our plugin is dynamically adding an additional LineItem to the current cart using a custom Collector. However, the LineItem is also being added to the backup cart which leads to the problem that isBackupExisting returns true without an existing backup cart.

It would be good if the Mollie extension could use a more specific method to check if a backup cart exists. I would suggest the use of `Shopware\Core\Checkout\Cart\CartPersister::load(string $token, SalesChannelContext $context), see this pull request.

@BlackScorp
Copy link
Collaborator

hi @netzkollektiv
thx for the pull request, maybe we can check why the line items also beeing added to the backup cart? maybe there is a problem?

right now the backup cart is created when you click on apple pay direct button. there i send a value to add to cart port request. if the value is not set, the backup cart should not be created in first place.

if the backup cart is also filled with your collector, then the there will be no exception there so the method isBackupExisting will still return true, right?

@netzkollektiv
Copy link
Author

Hi @BlackScorp, thank you for your quick feedback ! Indeed we are going to adapt our extension and check if the cart token is the current token within the collector. However I‘m not really sure how the collectors are meant to be. For me they seem to be implemented in a „singleton way“. Regardless of our change, I think the explicit check in the isBackupExisting check would avoid problem like that in general.

thanks, Dominik

@BlackScorp
Copy link
Collaborator

@netzkollektiv

what i noticed btw. there is a chance that if multiple users are going to buy over paypal express at same second, they can override each carts.

i updated in a branch the backup service. maybe this also helps with your problem?

https://github.com/BlackScorp/Shopware6/blob/users/vm/MOL-245-ppe/src/Service/Cart/CartBackupService.php

with your solution there might be too many calls to the database. cartService->getCart has in memory cache and once the cart is loaded somewhere else, there is no request to the database. if i use the persister directly then iam not sure how often the database is accessed. it might make the shop slower

@netzkollektiv
Copy link
Author

netzkollektiv commented Oct 21, 2024

@BlackScorp
Your change does not solve the problem, the LineItem would be added anyway.

The cart persister executes just one simple query which will give you a definite answer to your question if the cart is existing. If you are concerned about performance you could simplify and execute the query yourself: SELECT 1 FROM cart WHERE token = :token

see the original db statement here:
https://github.com/shopware/shopware/blob/c20e50cdeec0c06ad40f2680562aa955a4e5ce87/src/Core/Checkout/Cart/CartPersister.php#L37

@BlackScorp
Copy link
Collaborator

@netzkollektiv i think i understand, getCart creates a new cart if one is not existing. i will add a select statement with in memory cache

@BlackScorp
Copy link
Collaborator

@netzkollektiv i could not use the connection i have to use the persister, since there is also a redis cart persister and others can configure which one is used.

i had to change some things as well, so i created a new PR

#875

i will close this PR then. hope then your problem is fixed

@BlackScorp BlackScorp closed this Oct 23, 2024
@netzkollektiv
Copy link
Author

Thank you very much for your efforts! :-)

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.

2 participants