@@ -153,17 +153,27 @@ protected Entity validateUniqueUsername(Entity entity, Customer adminInstance) {
153
153
public void remove (PersistencePackage persistencePackage , DynamicEntityDao dynamicEntityDao , RecordHelper helper ) throws ServiceException {
154
154
Entity entity = persistencePackage .getEntity ();
155
155
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' );
163
168
}
169
+
170
+ customer = customerService .saveCustomer (customer );
171
+ return ;
164
172
}
165
-
166
-
173
+
174
+ // Remove the customer roles for the customer since it's not cascaded
175
+ roleDao .removeCustomerRolesByCustomerId (customerId );
176
+
167
177
helper .getCompatibleModule (OperationType .BASIC ).remove (persistencePackage );
168
178
} catch (Exception e ) {
169
179
LOG .error ("Unable to execute persistence activity" , e );
0 commit comments