2

When I am going to delete an address from "My Account" address book I am getting error message We can't delete the address right now.

But some other account I can delete the address.

I have checked controller file or delete the address and it's giving an error from the catch.

if ($addressId && $this->_formKeyValidator->validate($this->getRequest())) {
        try {
            $address = $this->_addressRepository->getById($addressId);
            if ($address->getCustomerId() === $this->_getSession()->getCustomerId()) {
                $this->_addressRepository->deleteById($addressId);
                $this->messageManager->addSuccess(__('You deleted the address.'));
            } else {
                $this->messageManager->addError(__('We can\'t delete the address right now.'));
            }
        } catch (\Exception $other) {
            $this->messageManager->addException($other, __('We can\'t delete the address right now.'));
        }
    }

Also in the system log, it's give an error like main.CRITICAL: Exception message: "Street Address" cannot contain more than 1 lines.

Please help me to solve this issue.

3 Answers 3

1

I have resolved this issue. It was due to in admin side 1 address line set for the customer and addresses which i was deleting were more than two lines.

So i have set default in backend after this deleted existing address and again set to 1 line. Now it's working.

1

It looks like a core magento issue

It checks the type of customerID from session and address object here $address->getCustomerId() === $this->_getSession()->getCustomerId()

So the one from $address->getCustomerId() is int and $this->_getSession()->getCustomerId() seems string.

If you replace === with == , it will work as expected

1

Update interface for Delete.php file directory: vendor/magento/module-customer/Controller/Address/Delete.php

comment line no 9 to 11

/* use Magento\Framework\App\Action\HttpPostActionInterface;

class Delete extends \Magento\Customer\Controller\Address implements HttpPostActionInterface */ 

change code

use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;

class Delete extends \Magento\Customer\Controller\Address implements HttpGetActionInterface
1
  • how can do this in overriding?any help?
    – Mujahidh
    Jun 10, 2019 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.