Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Delete.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
16  public function execute()
17  {
18  $addressId = $this->getRequest()->getParam('id', false);
19 
20  if ($addressId && $this->_formKeyValidator->validate($this->getRequest())) {
21  try {
22  $address = $this->_addressRepository->getById($addressId);
23  if ($address->getCustomerId() === $this->_getSession()->getCustomerId()) {
24  $this->_addressRepository->deleteById($addressId);
25  $this->messageManager->addSuccess(__('You deleted the address.'));
26  } else {
27  $this->messageManager->addError(__('We can\'t delete the address right now.'));
28  }
29  } catch (\Exception $other) {
30  $this->messageManager->addException($other, __('We can\'t delete the address right now.'));
31  }
32  }
33  return $this->resultRedirectFactory->create()->setPath('*/*/index');
34  }
35 }
__()
Definition: __.php:13
$address
Definition: customer.php:38