AdminTabStribCreated

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Implementing AdminTabStripCreated is straightforward enough but how would I gain reference to the entity that the tab is created for...

For Example: A Category, I can generate a new tab for the "category-edit" tab strip but how would I know which category the tab strip was created for so I could populate my content with the appropriate information?

Does anyone have a working plugin sample they could share that uses this functionality to add custom data to a category or product?

Thanks
11 years ago
I just came across the same problem as you did, but I think I found a solution.  If you need the id of the category being edited, you can pull the details from the RouteData in the HttpContext.

Something like this: (I haven't tested this yet)

int CategoryId = Convert.ToInt32(System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values["ID"]);


This is what I'm going to be doing to add a tab in the edit product view.  Take a look in the RouteData.Values dictionary and you should find what you're looking for if it isn't ID.

Hope this helps!
11 years ago
I had tried that already, I receive object null errors.

Near as I can tell, when using HandleEvent in a controller, Request is null.

Likewise when using an action to load in content the route data does not contain the proper categoryId and reports back null.
11 years ago
I did see that the .Request, .HttpContext, and .ControllerContext properties are all null when handling the event, however System.Web.HttpContext.Current was not null.  I was finally able to insert a custom tab and have it load a view by using the following code.  It took a little while to get it all working but I found I had to manually set the ControllerContext to get the RenderPartialViewToString to work.


public void HandleEvent(AdminTabStripCreated eventMessage)
        {
            //we know that tabstrip name on the product details page has "product-edit" name
            if (eventMessage.TabStripName == "product-edit")
            {
                int productId = Convert.ToInt32(System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values["ID"]);
                ProductTabsAdminModel model = new ProductTabsAdminModel();
                model.ProductId = productId;
                model.Tabs = _productTabsService.GetTabsForProduct(productId);

                // Set the ControllerContext if null
                this.ControllerContext = this.ControllerContext ?? new System.Web.Mvc.ControllerContext(System.Web.HttpContext.Current.Request.RequestContext, this);

                // Get the content for the tab
                string content = this.RenderPartialViewToString("Nop.Plugin.UI.ProductTabs.Views.agisProductTabs.ProductTabsAdmin", model);

                eventMessage.ItemFactory
                .Add()
                .Text("Product Tabs")
                .Content(content);
                
            }
        }
11 years ago
This worked well for me too.  There are a couple points that I did not get right away that I would like to clarify for future readers:

- The HandleEvent must go in your controller class, not a separate class (which some plugin examples use)
- You must always assign the this.ControllerContext property in your controller as specified in the above post (even if you do not need to access the RouteData, etc.) otherwise the call to RenderPartialViewToString will not work.
11 years ago
Hello

I am doing in this way:

public void HandleEvent(AdminTabStripCreated eventMessage)
        {
            if (eventMessage.TabStripName == "order-edit")
            {
              
                int orderId = onvert.ToInt32(System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values["ID"]);

                eventMessage.ItemFactory
                .Add()
                .Text("E24Payment Info")
                .LoadContentFrom("myAction", "myController" , new { orderId = orderId});
          
            }
        }


So the handler doesn't have to create the controller context, and the tab is loaded via ajax from the client itself.

Bye
11 years ago
Any idea how I would go about capturing the event when the save button is clicked? And how I would get access to my model?
9 years ago
Hi,
How do you load a view from a plugin here?

I have found that this will add a querystring like: "/Admin/OrderSynchronization/OrderSynchronizationDetails?orderId=36046". But my controller is only available at "Admin/OrderSynchronization/OrderSynchronizationDetails?orderId=36046"

J.
9 years ago
Hi,

I have next code in my IPlugin (NOP 3.20). However, for some reason I get a 404 error due to the ?OrderId=939 instead of /29349. How to resolve this? I can across: https://www.nopcommerce.com/boards/t/20478/broken-menus-in-admin-area-whilst-trying-to-make-a-plugin-admin-page.aspx

I want to load my own view.

J.


        public void HandleEvent(AdminTabStripCreated eventMessage)
        {
            if (eventMessage.TabStripName == "order-edit")
            {
                string tabName = _localizationService.GetResource("plugins.misc.qe.webservice.admin.fields.interface");

                int orderId = Convert.ToInt32(System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values["ID"]);

                eventMessage.ItemFactory
                    .Add()
                    .Text(tabName)
                    .LoadContentFrom(
                    "OrderSynchronizationDetails",
                    "Plugins/Misc/QEOrderSynchronization",
                    new { orderId = orderId });
            }
        }
9 years ago
This seems to work, but it is a bit weird that the routevalues are not to be used:


eventMessage.ItemFactory
                    .Add()
                    .Text(tabName)
                    .LoadContentFrom(
                    string.Format("OrderSynchronizationDetails/{0}", orderId.ToString()),
                    "Plugins/Misc/QEOrderSynchronization");
                    //new { orderId = orderId });
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.