2.4/2.5 Admin Edit links on category and product pages

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 Jahre weitere
We usually add and edit link to category and product pages so that admins can quickly correct any issues they find while browsing the site.

Thought the code would be useful to some

modify the following files;-

for Category edit

\Presentation\Nop.Web\Models\Catalog\CategoryModel.cs

add the following property

public bool DisplayAdminLink { get; set; }


\Presentation\Nop.Web\Controllers\CatalogController.cs

in method

public ActionResult Category(int categoryId, CatalogPagingFilteringModel command)


after

var model = category.ToModel();


add the following line

model.DisplayAdminLink = _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel);


\Presentation\Nop.Web\Views\Catalog\CategoryTemplate.ProductsInGridOrLines.cshtml

add whereever you want the edit link to appear

@if (Model.DisplayAdminLink)
    {
        <a href="/Admin/Category/Edit/@Model.Id" target="_blank">Edit</a><br />
    }



for product edit

\Presentation\Nop.Web\Models\Catalog\ProductModel.cs

add the following property

public bool DisplayAdminLink { get; set; }


\Presentation\Nop.Web\Controllers\CatalogController.cs

in method

protected ProductModel PrepareProductDetailsPageModel(Product product)


after

var model = product.ToModel();


add

model.DisplayAdminLink = _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel);


\Presentation\Nop.Web\Views\Catalog\ProductTemplate.SingleVariant.cshtml
\Presentation\Nop.Web\Views\Catalog\ProductTemplate.VariantsInGrid.cshtml

add whereever you want the edit link to appear

@if (Model.DisplayAdminLink)
    {
        <a href="/Admin/Product/Edit/@Model.Id" target="_blank">Edit</a><br />
    }


I didn't bother with the mobile side as imo editing the shop on a mobile is not something I want to encourage.

HTH

Dave
11 Jahre weitere
Dave, thanks for suggestion
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.