Skip to content

Commit 7e50b39

Browse files
BroadleafCommerce/QA#1354 - Soft-delete the CustomerAddresses when the Customer is soft-deleted
1 parent 3fcf2d1 commit 7e50b39

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

admin/broadleaf-admin-module/src/main/java/org/broadleafcommerce/admin/server/service/handler/CustomerCustomPersistenceHandler.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,27 @@ protected Entity validateUniqueUsername(Entity entity, Customer adminInstance) {
153153
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
154154
Entity entity = persistencePackage.getEntity();
155155
try {
156-
Long entityId = Long.parseLong(entity.findProperty("id").getValue());
157-
if (entityId != null) {
158-
Customer adminInstance = customerService.readCustomerById(entityId);
159-
if (Status.class.isAssignableFrom(adminInstance.getClass())) {
160-
((Status) adminInstance).setArchived('Y');
161-
customerService.saveCustomer(adminInstance);
162-
return;
156+
157+
Long customerId = Long.parseLong(entity.findProperty("id").getValue());
158+
159+
Customer customer = customerService.readCustomerById(customerId);
160+
if (Status.class.isAssignableFrom(customer.getClass())) {
161+
((Status) customer).setArchived('Y');
162+
163+
// If the customer has a conditional weave on ArchiveStatus, nothing triggers the delete so other
164+
// normally-cascaded deletes don't happen (like CustomerAddress)
165+
List<CustomerAddress> addressList = customer.getCustomerAddresses();
166+
for (CustomerAddress address : addressList) {
167+
address.setArchived('Y');
163168
}
169+
170+
customer = customerService.saveCustomer(customer);
171+
return;
164172
}
165-
166-
173+
174+
// Remove the customer roles for the customer since it's not cascaded
175+
roleDao.removeCustomerRolesByCustomerId(customerId);
176+
167177
helper.getCompatibleModule(OperationType.BASIC).remove(persistencePackage);
168178
} catch (Exception e) {
169179
LOG.error("Unable to execute persistence activity", e);

0 commit comments

Comments
 (0)