Logged in Customer Data on Product Details in Admin Area

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
hi,
I am trying to control showing Product Details sections based on logged in user's role.
For Ex: If logged in user is Forum Moderator, I do not want to show certain tabs in Product Details, like Purchased with Orders, Attribute tabs etc.
Also, moving on, I want to hide certain sections in Product Info page also, in similar fashion, based on logged in User's role.
On partial View, ProductModel is being used. So I tried adding new property to ProductModel, getting customer role from permissionService >> WorkContext >> Customer >> CustomerRole. Long route to get one property, but I could not find way to get what I need on product details view.

Requirement is pretty clear, getting Customer Role or IsForumModerator to _CreateOrUpdate.cshtml. Specifically only for Admin area.

Can anyone please suggest a way to do this ? TIA !
6 years ago
In your views, you need to be able to access the customers model, so add these using references and set the isForumModerator variable:

@using Nop.Core.Domain.Customers;
@using Nop.Services.Customers;
@using Nop.Core;
@{
    bool isForumModerator = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.IsInCustomerRole("Forum Moderator");
}



...and use conditional coding in your view to show features only to that role or not..

@if (isForumModerator == true) {
   @* do something *@
}
else
{
@* do something different *@
}
6 years ago
Only relevant if you're looking to avoid source code alterations...

To hide Product/Order/Customer tabs based on role without altering source files, you'd consume the AdminTabStripCreated event for "product-edit" and inject a new event block containing some script (consider using RenderPartialViewToString with a model) that hides kendo tabs by title.  

  

if (eventMessage.TabStripName == "product-edit") {
                int productId = Convert.ToInt32(System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values["ID"]);

//...logic discerning which tabs to show/hide by role

eventMessage.BlocksToRender.Add(new MvcHtmlString("<script>//your script that hides product tabs using above logic </script>"));
}



Hopefully that gets you on the right path!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.