Magento is one of the most popular eCommerce platform. Utilize the full potential of your Magento store by migrating to Magento 2.
Merchants may want to view some additional information like comments, reward points, etc of a particular customer in the back end. In order to show this, we need to create a tab in the customer admin.
In this blog, we shall see, how to create a new tab in the customer admin and to load custom PHTML into it. Let us say, the tab’s name is “Customer Credit”.
Before creating the customer tab, we need to create a new module. We already have a blog on “How to create a new module in Magento 2?” . Please refer to the same for more details.
To create a new tab in the admin customer edit, create an XML in the following path
Create a block file in the below path to load the contents when the tab is clicked
I have the block name as “Credit”. The block implements from TabInterface. The most important function in this class is : getTabUrl() and isAjaxLoaded() :
getTabUrl() contain the code return $this->getUrl(credit/*/credit, [‘_current’ => true]); equal go to action and execute the complete path of your controller in Magento 2.
The following are the routes.xml for creating a controller to make the URL valid.
Lets now create a controller with the class name Credit in the below path :
Create another XML to mention which phtml file has to load
Finally, create the phtml file and type your text or implement your logics with block and controller.
This is our new tab.
Now clear your cache. System – > Cache Management – > Flush Magento Cache
After clearing you cache, your admin will look like the image below…