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 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
    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
    Oct 3, 2017 at 6:38
  • yes it will redirect on address index page always 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
    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 Oct 3, 2017 at 6:43

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.