lunar icon indicating copy to clipboard operation
lunar copied to clipboard

Add soft deletes to carts

Open alecritson opened this issue 1 year ago • 6 comments

This PR adds soft deletes to carts. The idea behind this is when you want to forget a cart, it is likely you want to remove the cart from a users current and future session.

The problem is in order to fully achieve this you would need to fully remove the cart from the database, which means there is a loss of important data as a store owner.

There are also situations you may want to forget the cart session, such as logging out, but you may want to retain that cart for when the user logs back in and can pick up from where they left off.

This PR looks to solve these issues by adding soft deletes to carts. The default behaviour is the cart will be soft deleted when you call CartSession::forget, but you can opt to keep the cart "active" by passing the delete: false parameter.

Existing Storefronts who want to soft delete carts

No further action is needed, call CartSession::forget() and the carts should be deleted.

Existing Storefronts who do not want to soft delete carts

// Old
CartSession::forget();

// New
CartSession::forget(delete: false);

alecritson avatar May 23 '24 13:05 alecritson

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 4, 2024 0:21am

vercel[bot] avatar May 23 '24 13:05 vercel[bot]

I have tested with this, it does solve my problem.

I would suggest to change the method to ::forget() and ::delete() instead of the parameter make a breaking change now is better for a clearer api

wychoong avatar May 23 '24 14:05 wychoong

I have tested with this, it does solve my problem.

I would suggest to change the method to ::forget() and ::delete() instead of the parameter make a breaking change now is better for a clearer api

@alecritson and I considered your suggestion, but we both prefer the originally proposed naming.

glennjacobs avatar May 23 '24 14:05 glennjacobs

The cart prune command should be updated as well?

wychoong avatar May 23 '24 16:05 wychoong

The cart prune command should be updated as well?

Good point, we might want to add ->withTrashed().

glennjacobs avatar May 23 '24 17:05 glennjacobs

I've adjusted the prune command to use withTrashed, hopefully that'll do it.

alecritson avatar May 24 '24 08:05 alecritson

@alecritson although we have it in the upgrade guide, we should also probably add to the main docs.

glennjacobs avatar Jul 04 '24 12:07 glennjacobs