aboutsummaryrefslogtreecommitdiff
path: root/customer/hooks.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2023-09-03 23:39:05 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2023-09-03 23:39:05 +0530
commitcba9f19ba50c60576a5961e89c24caefca52d740 (patch)
tree5dd36d4903c640e11a022c5fbf0e55adc3cdd5a5 /customer/hooks.go
parent46083ff15e16b0b49132af9466bcab7c2ae71322 (diff)
deleting addresses upon customer deletionv0.0.5
Diffstat (limited to 'customer/hooks.go')
-rw-r--r--customer/hooks.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/customer/hooks.go b/customer/hooks.go
index ac246f3..bef3308 100644
--- a/customer/hooks.go
+++ b/customer/hooks.go
@@ -39,5 +39,19 @@ func (c *Customer) BeforeDelete(tx *gorm.DB) error {
return errors.ErrNoWhereCondition
}
+ var err error
+
+ // delete billing address
+ err = db.Where("customer_id = ?", c.ID).Delete(&CustomerBillingAddress{}).Error
+ if err != nil {
+ return err
+ }
+
+ // delete shipping addresses
+ err = db.Where("customer_id = ?", c.ID).Delete(&CustomerShippingAddress{}).Error
+ if err != nil {
+ return err
+ }
+
return nil
}