0

In account pages when I click on address book on left side panel it redirect to add new address form with url customer/address/new/

while , In actual I should go to index where I can see address in address book.

Why its happening any idea ?

2
  • It's magento default functionality @Learner which is used for create new address for customer Commented Oct 3, 2017 at 6:02
  • @RohanHapani I saved address 4,5 times still it goes to new form , but suddenly on 6th attempt It went to address book. Is it because address was not properly saved ?
    – Learner
    Commented Oct 3, 2017 at 6:39

1 Answer 1

0

Redirecting on New Address Form, When user don't have any address is default functionlity of magento. If you want to overwrite this, you need to create plugin and overwrite the default functionlity like below:

Specify new plugin class in app/code/Stack/Customer/etc/di.xml file using the below code:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <type name="Magento\Customer\Controller\Address\Index">
        <plugin name="address-index" type="Stack\Customer\Plugin\Controller\Address\Index" sortOrder="1" />
    </type>    
</config>

Create plugin file app/code/Stack/Customer/Plugin/Controller/Address/Index.php using the below code:

namespace Stack\Customer\Plugin\Controller\Address;
class Index
{
    public function __construct(
        \Magento\Framework\View\Result\PageFactory $resultPageFactory,
        \Magento\Framework\App\Response\RedirectInterface $redirect
    )
    {
        $this->resultPageFactory = $resultPageFactory;
        $this->_redirect = $redirect;
    }

    public function aroundExecute(\Magento\Customer\Controller\Address\Index $index, callable $proceed)
    {
        $resultPage = $this->resultPageFactory->create();
        $block = $resultPage->getLayout()->getBlock('address_book');
        if ($block) {
            $block->setRefererUrl($this->_redirect->getRefererUrl());
        }
        return $resultPage;
    }
}

Hope this help!!

4
  • what exactly it will do ? It will redirect always to address book ?
    – Learner
    Commented Oct 3, 2017 at 6:38
  • yes it will redirect on address index page always Commented Oct 3, 2017 at 6:39
  • thank you. let me try this :) and where I can change page ?where is its phtml file of Address book ? any idea ?
    – Learner
    Commented Oct 3, 2017 at 6:40
  • 1
    vendor/magento/module-customer/view/frontend/templates/address/book.phtml -- you can copy this file in your theme in customer module Commented Oct 3, 2017 at 6:43

Your Answer

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

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