Quantcast
Channel: Magento 2 – DCKAP
Viewing all articles
Browse latest Browse all 135

How To Create a Tab in Customer Admin Edit in Magento 2 ?

$
0
0

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 the same for more details.

Step 1:

To create a new tab in the admin customer edit, create a xml in the following path

/app/code/Vendorname/modulename/view/adminhtml/layout/customer_index_edit.xml

 

Step 2:

Create a block file in the below path to load the contents when the tab is clicked

/app/code/Vendorname/Modulename/Block/Adminhtml/Edit/Tab/Credit.php

 

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.

 

Step 3:

Following is the routes.xml for creating a controller to make the url valid.

/app/code/Vendorname/Modulename/etc/adminhtml/routes.xml 

 Step 4:

Lets now create a controller with the class name Credit in the below path :

/app/code/Vendorname/Modulename/Controller/Adminhtml/Index/Credit.php

 

Step 5:

Create another xml to mention which phtml file has to load

/app/code/Vendorname/Modulename/view/adminhtml/layout/credit_index_credit.xml

Step 6:

Finally create the phtml file and type your text or implement your logics with block and controller.

/app/code/Vendorname/Modulename/view/adminhtml/templates/credit.phtml

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…

customer admin edit magento 2

PLANNING FOR A MAGENTO 2 MIGRATION ?
Magento 2 migration can be trickier than you expect. We are a Magento 2 Trained Solution Partner. We will help you move seamlessly to the new platform.

This post How To Create a Tab in Customer Admin Edit in Magento 2 ? appeared first on


Viewing all articles
Browse latest Browse all 135

Trending Articles