DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Guide to E-Commerce Mobile App Development: Steps, Features, and Costs
  • How to Create and Debug a Plugin in NopCommerce 4.40

Trending

  • AI Speaks for the World... But Whose Humanity Does It Learn From?
  • AI Agents: A New Era for Integration Professionals
  • Optimizing Serverless Computing with AWS Lambda Layers and CloudFormation
  • When Airflow Tasks Get Stuck in Queued: A Real-World Debugging Story

How To Add Tab On Admin Side Using The Plugin In nopCommerce 4.3

In this article, you will see how you can add tabs on a nopCommerce admin side using a plugin. Let's directly dive into the implementation part...

By 
Kiran Joshi user avatar
Kiran Joshi
·
Updated Oct. 14, 20 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
9.1K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, you will see how you can add tabs on a nopCommerce admin side using a plugin. Let's directly dive into the implementation part because I believe when developers search for this type of article, they are looking for solutions that will help them to learn or troubleshoot issues. The following are the steps to add a tab on the admin side using a plugin in nopCommerce 4.3. 

FindWidgetZone

 First, identify on which admin side page you want to add a tab. In this article, I am adding a tab on the admin order edit page. So, first I need to find the order edit page in the source code to check the WidgetZone of page. In this widget zone, we will return our new tab view page. I am finding a widget zone on ~\Presentation\Nop.Web\Areas\Admin\Views\Order\Edit.cshtml. The Widgetzone's name is AdminWidgetZones.OrderDetailsBlock

FindWidgetZone


Add ViewComponent and WidgetZone Name

 To add a custom tab on the admin side I am using the existing nopCommerce NivoSlider plugin. If you want to check with new plugin then you can Create Plugin.  Once you create new plugin or working with existing plugin First, go to the plugin file Plugins\Nop.Plugin.Widgets.NivoSlider\NivoSliderPlugin.cs. If it's a new plugin then make sure your plugin inherits IWidgetPlugin. Go to GetWidgetZones() method, and in that add the widget zone which you found on the order edit page; i.e. AdminWidgetZones.OrderDetailsBlock. Now GetWidgetZones() will look as follows:

C#
 




x
12


 
1
/// <summary>    
2
/// Gets widget zones where this widget should be rendered    
3
/// </summary>    
4
/// <returns>Widget zones</returns>    
5
public IList < string > GetWidgetZones() {  
6
  return new List < string > {  
7
    PublicWidgetZones.HomepageTop,  
8
    AdminWidgetZones.OrderDetailsBlock // this we added for custom order  
9
  };  
10
}   



Now we will add viewcomponentname in GetWidgetViewComponentName in the same file. We add viewcomponent name WidgetsAdminOrderDetails. This viewcomponent calls when we view the admin order edit page. And this view component will return the list of tabs that we want to add. 

C#
 




x


 
1
/// <summary>    
2
/// Gets a name of a view component for displaying widget    
3
/// </summary>    
4
/// <param name="widgetZone">Name of the widget zone</param>    
5
/// <returns>View component name</returns>    
6
public string GetWidgetViewComponentName(string widgetZone) {  
7
  if (widgetZone == AdminWidgetZones.OrderDetailsBlock) 
8
        return "WidgetsAdminOrderDetails";  
9
  return "WidgetsNivoSlider";  
10
}   
11

          



Create ViewComponent and TabList and TabContent cshtml file

 Now we will create view component file WidgetsAdminOrderDetailsViewComponent.cs following is code. The file location will be \Nop.Plugin.Widgets.NivoSlider\Components\WidgetsAdminOrderDetailsViewComponent.cs

C#
 




xxxxxxxxxx
1
11


 
1

          
2
    namespace Nop.Plugin.Widgets.NivoSlider.Components {  
3
        [ViewComponent(Name = "WidgetsAdminOrderDetails")]  
4
        public class WidgetsAdminOrderDetailsViewComponent: NopViewComponent {  
5
            public WidgetsAdminOrderDetailsViewComponent() {}  
6
            public IViewComponentResult Invoke(string widgetZone, object additionalData) {  
7
                return View("~/Plugins/Widgets.NivoSlider/Views/WidgetsAdminOrderDetails/AdminOrderTabList.cshtml");  
8
            }  
9
        }  
10
    }   



Now we will create AdminOrderTabList.cshtml. In this file, we will provide a list of tabs with their tab content file. We will create this file at the following location: Plugins\Nop.Plugin.Widgets.NivoSlider\Views\WidgetsAdminOrderDetails\AdminOrderTabList.cshtml. I am creating a new folder WidgetAdminOrderDetails under the view folder of the plugin. Following is AdminOrderTabList.cshtml file.

HTML
 




x


 
1
@using Nop.Services.Common    
2
@using Nop.Core    
3
@* You can add above 2 namespace in _ViewImport.cshtml. This 2 namespace required for workcontext and generic attribute service.*@     
4
@inject IWorkContext workContext    
5
@inject IGenericAttributeService genericAttributeService    
6
 @{    
7
        const string hideCustomBlockAttributeName = "CustomOrderPage.HideCustomBlock";    
8
        var hideCustomBlock = genericAttributeService.GetAttribute<bool>(workContext.CurrentCustomer, hideCustomBlockAttributeName);    
9
 }    
10
<nop-panel asp-name="custom-order-tab" asp-icon="fa fa-th-list"    
11
  asp-title="CustomTabTitle"    
12
  asp-hide-block-attribute-name="@hideCustomBlockAttributeName"    
13
  asp-hide="@hideCustomBlock" asp-advanced="true">    
14
        @await Html.PartialAsync("/Plugins/Widgets.NivoSlider/Views/WidgetsAdminOrderDetails/_CustomTab.Order.cshtml")    
15
</nop-panel>



If you want to add multiple tabs in the order edit page, then replicate this code in the same file and provide different cshtml file locations for tab content. [Tips: I copied this content from order/ edit.cshtml file of nopcommerce.]

For tab content we specified /Plugins/Widgets.NivoSlider/Views/WidgetsAdminOrderDetails/_CustomTab.Order.cshtml. So, following is the content of _CustomTab.Order.cshtml file content. 

HTML
 




x


 
1

          
2
<div class="panel-body">    
3
  <div class="panel panel-default sub-panel">    
4
    <div class="panel-body">    
5
      Custom Body content    
6
    </div>    
7
  </div>    
8
</div>



Now please make sure both .cshtml files are marked as copies as in the below screenshot. If you are using VSCode then you manually need to add this in a plugin.csproject file i.e(Plugins\Nop.Plugin.Widgets.NivoSlider\Nop.Plugin.Widgets.NivoSlider.csproj) 

customTab

Now build a plugin and check the order edit page ( AdminOrderList -> Click on VIEW button) of nopCommerce. Following is the final result, as you can see the CustomTabTitle tab.

edit order details

Following is a screenshot of the files which I added or changed to implement this functionality. 

nop.plugin

Your feedback and suggestions help me to improve this article. In this article, I didn't explain the code very much because the main purpose of this article is to show complete steps to add custom tabs in admin nopCommerce using the plugin. If you face any problem while you follow this article then please mention it in the comments so I can improve. If you want to see any other articles about nopCommerce then also let me know in the comments.

Thanks in advance for taking the time to read and make suggestions. 

NopCommerce

Opinions expressed by DZone contributors are their own.

Related

  • Guide to E-Commerce Mobile App Development: Steps, Features, and Costs
  • How to Create and Debug a Plugin in NopCommerce 4.40

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!