You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on an e-commerce site using Lunar where users can register, make purchases, and manage their accounts. The platform needs to handle customer account deletion properly when requested by users or administrators.
What I'm Trying to Do
Delete customers from the admin panel (/admin/customers) either individually or through bulk actions, ensuring that all related data is properly cleaned up, including associated Users.
The Problem
When attempting to delete a Customer that has associated data (carts, orders, addresses), the deletion fails with foreign key constraint violations. Additionally, when deletion is forced through bulk actions, it only detaches the User relationship, leaving orphaned User records in the database that prevent email reuse for new registrations.
What I've Checked
Reviewed the CustomerObserver implementation
Analyzed database migrations and foreign key constraints
Checked for cascade delete configurations
Searched for existing issues related to customer deletion
Verified this affects both individual and bulk delete actions
Steps to Reproduce
Register a new user in the frontend (creates both User and Customer)
Add products to cart as that user
Navigate to admin panel → Customers
Attempt to delete the customer using bulk action
Observe the foreign key constraint error
If deletion succeeds (empty cart), check Users table - the User remains orphaned
Current Result
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row:
a foreign key constraint fails (`database`.`lunar_carts`, CONSTRAINT `lunar_carts_customer_id_foreign`
FOREIGN KEY (`customer_id`) REFERENCES `lunar_customers` (`id`))
Expected Result
Customer deletion should:
Handle or cascade delete related records (carts, addresses, etc.)
Either delete or properly handle associated Users
Allow email addresses to be reused after account deletion
Context
I'm working on an e-commerce site using Lunar where users can register, make purchases, and manage their accounts. The platform needs to handle customer account deletion properly when requested by users or administrators.
What I'm Trying to Do
Delete customers from the admin panel (
/admin/customers) either individually or through bulk actions, ensuring that all related data is properly cleaned up, including associated Users.The Problem
When attempting to delete a Customer that has associated data (carts, orders, addresses), the deletion fails with foreign key constraint violations. Additionally, when deletion is forced through bulk actions, it only detaches the User relationship, leaving orphaned User records in the database that prevent email reuse for new registrations.
What I've Checked
CustomerObserverimplementationSteps to Reproduce
Current Result
Expected Result
Customer deletion should:
Technical Details
Affected File:
packages/core/src/Observers/CustomerObserver.phpCurrent implementation:
Related Issues
CustomerResourcepagesProposed Solution
Enhanced CustomerObserver that properly handles all relationships:
Additionally, add delete action to CustomerResource pages:
Environment
Why This Matters
This is a critical issue for any production e-commerce site because:
Additional Notes
I'm already working on implementing this solution and will submit a PR shortly once the approach is confirmed.