Option to delete customers account from the Myaccount

A delete button has been placed on the account custom template on the extension JJ_Account.

On the delete a controller action is called on the Ajax method.

$(document).on(‘click’,’.delete-contact’, function () {

var email = $(this).data(“email”);

swal.fire({

title: “Are you sure?”,

text: “Do you want to delete?”,

icon: “warning”,

showCancelButton: true,

confirmButtonColor: ‘#9FC33A’,

cancelButtonColor: ‘#9FC33A’,

confirmButtonText:’Yes’,

cancelButtonText:’No’,

closeOnConfirm: false,

closeOnCancel: false,

dangerMode: true,

}).then(function(isConfirm) {

if (isConfirm.isConfirmed) {

$.ajax({

url: url.build(‘Account/Index/Delete?email=’+ email),

dataType: ‘json’,

type: ‘GET’,

showLoader: true,

success: function (res) {

if (res.status == 200) {

swal.fire({

title: “<?= __(‘Sucess’) ?>”,

text: res.message,

icon: “success”,

button: “<?= __(‘Ok’) ?>”,

confirmButtonColor: ‘#9FC33A’,

}).then(function () {

location.reload();

});

}

}

});

} else {

}

});

});

On the controller, function has been created to disable the customer and rmove the parent from it.

$this->registry->register(‘isSecureArea’, true);

$customer = $this->customerRepository->get($email);

$customer->setCustomAttribute(‘parent_id’, 0)->setCustomAttribute(‘status’, 0);

$this->customerRepository->save($customer);

$customer= [

‘id’ => $customer->getId(),

‘is_deleted’ => 1

];

$curl = curl_init();

curl_setopt_array($curl, array(

CURLOPT_URL => “”,

CURLOPT_RETURNTRANSFER => true,

CURLOPT_ENCODING => “”,

CURLOPT_MAXREDIRS => 10,

CURLOPT_TIMEOUT => 30000,

CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

CURLOPT_CUSTOMREQUEST => “POST”,

CURLOPT_POSTFIELDS => json_encode($customer),

CURLOPT_HTTPHEADER => array(

“accept: */*”,

“accept-language: en-US,en;q=0.8”,

“content-type: application/json”,

“User-Agent: Mozilla/5.0”

),

));

$response = curl_exec($curl);

$err = curl_error($curl);

curl_close($curl);

Leave a comment

Your email address will not be published. Required fields are marked *