3

I have issue in Address Book when "Add New Address" Steps to reproduce:

Go to "My Account" page
Navigate to "Address Book"
Click "Add New Address" button

Expected result

On "Add New Address" button click should prompt a new form to create an additional address

also I have discovered that the "Delete Address" button that shows after you have successfully added an additional address to your address book has an href="#" and therefore doesn't do anything.

4

To solve "Add New Address" button issue replace below code at line no 91:

<button type="button" role="add-address" title="<?= $block->escapeHtmlAttr(__('Add New Address')) ?>" class="action primary add"><span><?= $block->escapeHtml(__('Add New Address')) ?></span></button>

with below code

<a class="action primary add" href="<?php /* @escapeNotVerified */ echo $block->getUrl('customer/address/new'); ?>"><span><?php /* @escapeNotVerified */ echo __('Add New Address') ?></span></a>

To solve "Delete Address" link issue replace below code at line no 78:

href="#"

with below code

href="<?php /* @escapeNotVerified */ echo $block->getUrl('customer/address/delete', ['id' => $_address->getId()]) ?>" 

Now, we need to make some changes in below controller file:

/vendor/magento/module-customer/Controller/Address/Delete.php So we need to override controller by creating new module, please refer this link->How to override

On line no 18 from above controller file we need to comment/remove below code:

&& $this->_formKeyValidator->validate($this->getRequest())

Both issues solved.

0

If anyone interested I had the same issue with my add new address button doesn't work anymore. The reason was because I changed the main layout class. (called by x-magento-init)

I fixed it by, copying

module-customer/view/frontend/templates/address/book.phtml

to

design/frontend/VENDOR/YOUR_THEME/Magento_Customer/templates/address/book.phtml

at the very bottom of the file change

<script type="text/x-magento-init">
{
    ".page-main": {
        "address": {
            "deleteAddress": "li.item a[role='delete-address']",
            "deleteUrlPrefix": "<?= $block->escapeJs($block->escapeUrl($block->getDeleteUrl())) ?>id/",
            "addAddress": "button[role='add-address']",
            "addAddressLocation": "<?= $block->escapeJs($block->escapeUrl($block->getAddAddressUrl())) ?>"
        }
    }
}

by

<script type="text/x-magento-init">
{
    ".class-of-your-parent-container": {
        "address": {
            "deleteAddress": "li.item a[role='delete-address']",
            "deleteUrlPrefix": "<?= $block->escapeJs($block->escapeUrl($block->getDeleteUrl())) ?>id/",
            "addAddress": "button[role='add-address']",
            "addAddressLocation": "<?= $block->escapeJs($block->escapeUrl($block->getAddAddressUrl())) ?>"
        }
    }
}

You add new address button should work now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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