@@ -234,11 +234,14 @@ public function execute()
234
234
$ customer = $ this ->getCustomerDataObject ($ this ->session ->getCustomerId ());
235
235
$ customerCandidate = $ this ->populateNewCustomerDataObject ($ this ->_request , $ customer );
236
236
237
- $ attributeToDelete = $ this ->_request ->getParam ('delete_attribute_value ' );
238
- if ((string )$ attributeToDelete !== "" ) {
239
- $ uploadedValue = $ this ->_request ->getParam ($ attributeToDelete . File::UPLOADED_FILE_SUFFIX );
240
- if ((string )$ uploadedValue === "" ) {
241
- $ this ->deleteCustomerFileAttribute ($ customerCandidate , $ attributeToDelete );
237
+ $ attributeToDelete = (string )$ this ->_request ->getParam ('delete_attribute_value ' );
238
+ if ($ attributeToDelete !== "" ) {
239
+ $ attributesToDelete = $ this ->prepareAttributesToDelete ($ attributeToDelete );
240
+ foreach ($ attributesToDelete as $ attribute ) {
241
+ $ uploadedValue = $ this ->_request ->getParam ($ attribute . File::UPLOADED_FILE_SUFFIX );
242
+ if ((string )$ uploadedValue === "" ) {
243
+ $ this ->deleteCustomerFileAttribute ($ customerCandidate , $ attribute );
244
+ }
242
245
}
243
246
}
244
247
@@ -304,6 +307,26 @@ public function execute()
304
307
return $ resultRedirect ;
305
308
}
306
309
310
+ /**
311
+ * Convert comma-separated list of attributes to delete into array
312
+ *
313
+ * @param string $attribute
314
+ * @return array
315
+ */
316
+ private function prepareAttributesToDelete (string $ attribute ) : array
317
+ {
318
+ $ result = [];
319
+ if ($ attribute !== "" ) {
320
+ if (str_contains ($ attribute , ', ' )) {
321
+ $ result = explode (', ' , $ attribute );
322
+ } else {
323
+ $ result [] = $ attribute ;
324
+ }
325
+ $ result = array_unique ($ result );
326
+ }
327
+ return $ result ;
328
+ }
329
+
307
330
/**
308
331
* Adds a complex success message if email confirmation is required
309
332
*
@@ -472,11 +495,7 @@ private function deleteCustomerFileAttribute(
472
495
string $ attributeToDelete
473
496
) : void {
474
497
if ($ attributeToDelete !== '' ) {
475
- if (strpos ($ attributeToDelete , ', ' ) !== false ) {
476
- $ attributes = explode (', ' , $ attributeToDelete );
477
- } else {
478
- $ attributes [] = $ attributeToDelete ;
479
- }
498
+ $ attributes = $ this ->prepareAttributesToDelete ($ attributeToDelete );
480
499
foreach ($ attributes as $ attr ) {
481
500
$ attributeValue = $ customerCandidateDataObject ->getCustomAttribute ($ attr );
482
501
if ($ attributeValue !== null ) {
0 commit comments