0

Most previous questions on this are old, related to M1 and never garnered a conclusive response.

Why is there a need for a Persistent Shopping Cart (PSC) and how does this interact with Quotes?

On our M2.3.3 site, we see quotes being created when anyone visits the site - although not all the time. For example, we have an uptime monitor that polls every minute. Sometimes we see a new "null" quote created each time the monitor polls (from the same IP) and other times nothing. Same for bots visiting the site. These quotes remain active and stay, unused, in the quote table forever. There are now thousands of null quotes registered with the same IPs but no customer.

What's the logic for when it decides to create a new quote?

When a customer logs in (we're B2B and require login to even view the shop), they either get a quote created or an existing quote updated. Anything added to the cart goes in the quote and lives there forever; quote lifetime only applies to inactive quotes (i.e. those converted to orders). Login from another device and what's in the cart is there. Persistent Shopping Cart is disabled.

So there's no need for PSC to maintain a cart, despite how PSC is described and the use-cases for registered customers presented in the documentation for it.

So what is the point of the PSC? Is it meant as a cookie-based fix for whatever is happening with guest quotes, where they seem to be randomly created or not?

Can anyone shed some light on why there are apparently two different mechanisms for the same thing - retaining a cart.

2
  • My understanding is that a quote is created any time something is added to the cart. Logged in will have customer details. Guest won't. Where persistence comes in is linking a guest back to their guest cart via cookies. Add to cart and close and reopen your browser. If users have to log in and they are associated against a quote persistence lifetime is irrelevant and they will have items in their cart providing the quote is not cleared or invalidated in someway. Although M2 uses local storage too. I'm not sure how this affects all this. And extensions probably modify this behavior too. – Dominic Xigen Feb 23 at 13:47
  • Hmm, that would be expected behaviour but not what we're seeing. Just visiting the site home page might or might not generate a new quote record. We have a couple of extensions to force login to view shop and switch store based on GeoIP/account store. Perhaps one of these is triggering this. Trouble is it's random so a vanilla install isn't necessarily going to tell me anything. – Adam Lavery 2 days ago
0

Had to convert to an answer as too much content for a comment.

Could it be that your site is being hit by bots? You can do that via the API https://devdocs.magento.com/guides/v2.4/rest/tutorials/orders/order-add-items.html

http://demo-m2.bird.eu/swagger#/

http://demo-m2.bird.eu/

POST
/V1/guest-carts
Enable an customer or guest user to create an empty cart and quote for an anonymous customer.
POST http://demo-m2.bird.eu/rest/all/V1/guest-carts HTTP/1.1

HTTP/1.1 200 OK
Date: Tue, 23 Feb 2021 21:27:18 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
X-Frame-Options: SAMEORIGIN, SAMEORIGIN
Set-Cookie: PHPSESSID=romlp9kjpd7mjkl87ml9mc4mk4; expires=Tue, 23-Feb-2021 22:27:18 GMT; Max-Age=3600; path=/; domain=demo-m2.bird.eu; HttpOnly
X-Content-Type-Options: nosniff
Connection: close
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8

"NnBWiwAjZKdUC1YWtQ5b62sN0aG3G2Br"
GET
/V1/guest-carts/{cartId}/items
List items that are assigned to a specified cart.

GET http://demo-m2.bird.eu/rest/all/V1/guest-carts/NnBWiwAjZKdUC1YWtQ5b62sN0aG3G2Br/items HTTP/1.1

HTTP/1.1 200 OK
Date: Tue, 23 Feb 2021 21:36:39 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
X-Frame-Options: SAMEORIGIN, SAMEORIGIN
Set-Cookie: PHPSESSID=romlp9kjpd7mjkl87ml9mc4mk4; expires=Tue, 23-Feb-2021 22:36:39 GMT; Max-Age=3600; path=/; domain=demo-m2.bird.eu; HttpOnly
X-Content-Type-Options: nosniff
Connection: close
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8

[]

Swap out for an invalid hash and you will see different behaviour. So potentially I've just created an empty basket/cart/quote.

2
  • At the moment just suggestions. No firm answer. Any extension has the potential to modify core behaviour. – Dominic Xigen 2 days ago
  • Great information, thanks. However, I don't think this can account for the uptime poll which simply checks the home page is available. That sometimes generates a null quote but more often not. If we could be sure how core Magento behaves, then I could investigate extensions that could be causing this behaviour. Either way, still doesn't explain how quotes (in the DB) and PSC interact. – Adam Lavery 2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.