addressRepository = $addressRepository; $this->resultJsonFactory = $resultJsonFactory; $this->logger = $logger; } /** * Delete customer address action * * @return Json * @throws \Magento\Framework\Exception\LocalizedException */ public function execute(): Json { $customerId = $this->getRequest()->getParam('parent_id', false); $addressId = $this->getRequest()->getParam('id', false); $error = false; $message = ''; if ($addressId && $this->addressRepository->getById($addressId)->getCustomerId() === $customerId) { try { $this->addressRepository->deleteById($addressId); $message = __('You deleted the address.'); } catch (\Exception $e) { $error = true; $message = __('We can\'t delete the address right now.'); $this->logger->critical($e); } } $resultJson = $this->resultJsonFactory->create(); $resultJson->setData( [ 'message' => $message, 'error' => $error, ] ); return $resultJson; } }