0

I want to add a button to abc.com/customer/account page when the user click it, it will redirect to a new page e.g. customer/account/upgrademember. How can I do this? I find it difficult to route it to my module. In Magento_Customer module, the \Magento\Customer\etc\frontend\route.xml defines when the frontName is customer, Magento will go to Magento_Customer module. But I create a new Controller upgrademember.php in my module. How can the Magento go to my upgrademember.php when the user clicks the abc.com/ccustomer/account/upgrademember.?

2

Finally, I got another solution. It is adding routes.xml under etc/frontend

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
   <router id="standard">
        <route id="customer" frontName="customer">
            <module name="Namespace_ModuleName" />
        </route>
    </router>
</config>

It will redirect the upgrade abc.com/ccustomer/account/upgrademember to the my custom module's controller UpgradeMember.php

  • will this override the customer module frontname or just extend this with our custom route ? what about the priority of the route if the same class exist in both module ? – Zeeshan Khuwaja May 28 '18 at 2:18
1

You can try this.
In your module add this in di.xml

<type name="Magento\Framework\App\Router\ActionList\Reader">
    <plugin name="namespace-module-route" type="Namespace\Module\Model\Plugin\ActionListReader" sortOrder="100" />
</type>

then create the file Namespace/Module/Model/Plugin/ActionListReader.php with this content:

<?php
namespace Namespace\Module\Model\Plugin;

class ActionListReader
{
    public function afterRead(\Magento\Framework\App\Router\ActionList\Reader\Interceptor $subject, $actions)
    {
        $actions['magento\customer\controller\account\upgrademember'] = 'Namespace\Module\Controller\Customer\Account\Upgrademember'; //your class name should go here.
        return $actions;
    }
}
  • I've tried, but it failed to plugin Magento\Framework\App\Router\ActionList\Reader, since I added a error_log() in afterRead(), but it logged nothing. Thanks. – Ricky.C Dec 11 '15 at 8:50
  • @ricky :- post your code – Pradeep Kumar Dec 14 '15 at 3:49
  • @Pradeep Kumar I use phpstorm to write the plugin, phpstorm shows 'cannot resolve symbol' error on <type name="Magento\Framework\App\Router\ActionList\Reader"> and 'undefined namespace' error on public function afterRead(\Magento\Framework\App\Router\ActionList\Reader\Interceptor $subject, $actions) Also, I can't find the file at lib. – Ricky.C Dec 14 '15 at 6:03
  • this does not work in M2.2, class does not exist and i have not found the usage of it in any of the core module. – Zeeshan Khuwaja May 28 '18 at 2:43

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.