Try our conversational search powered by Generative AI!

How to delete carts via API without user information


In our E2E test that we run on all the environments we are adding items to a cart, signing in as a guest user, filling in contact details; but are not completing the purchase. We are ending up with many fake carts even on our PROD environment. 

From what I see a cart can be deleted with cart information, but for that we need the Order repository. In our tests we can only use the APIs. Is there a way to clean up after the testing via the API? (we do not have user id as we end the testing before the user is created)

Jan 27, 2023 12:12

Do you have real carts you want to keep? if not, a truncate on the table (assuming you're using serialzable carts) should be enough

other than that, if you don't keep the carts forever, they will be automatically deleted after 30 days with the remove expired carts scheduled job

otherwise, you can do a query to join with cls_Contact table (customerid should match with contactid if it is a registered account). you then can have a list of carts without registered accounts.

of course, those deletions should be done with cautions and back up should be performed 

Jan 27, 2023 14:59

Yes, of course we have real cards we want to keep : D (we run these tests against PROD as well). 

I am talking about Playwright tests, there is no access to the database, only the API. 

As I've mentioned, it is tested with guest users, and the test is completed before the purchase, so no contact ids. 

Jan 27, 2023 19:06

Some ideas

  • Load the carts using IOrderSearchService (by batch)
  • For each card, try to load the contact using CustomerContext.Current.GetContactById(cart.CustomerId);
  • if it is null, then you know there is no contact associated, you can decide if you want to keep it or delete it.

it will be a slow process however. you can leave it to the Remove Expired Carts to eventually clear the carts (those carts would have fairly small, if any, performance impact, I'd not worry about them, unless if you have tens of millions) 

Jan 28, 2023 10:13
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.