How to restrict vendors from posting on multiple categories for the same products on nopcommerce 4.0

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Hi Everyone,

Does anyone know how can an admin restrict vendors from having a choice to list products on multiple categories per product. I want my vendors to be able to post only to one category or subcategory.

The default one allows vendors to post one product to multiple categories.


If anyone can help please reply.


Thank you in advance.
5 years ago
Hi,

nopCommerce not supporting this feature out of the box.

You must need to customize in that method for allow to select only one category/subcategory when current login user having vendor role.

Let me know if you need any more help for same.

Thanks,
Jatin
5 years ago
Hi,

Thank a lot for you replay. Do you know how or by any chance to you have the code/script to add. Do you have any suggestions how I might fix this???

Thank you in advance.
5 years ago
Hi,
can you explain why you want to restrict vendors to select multiple categories. I have also vendors in my shop, I don‘t see a reason why I should do this.

Greatings
5 years ago
Hi,

Thank you for you replay. I don't want to restrict vendors to select multiple categories, but I want to restrict them from listing one product to multiple categories (ex. If a vendor sells Mobile Phones I don't want the to have the possibility to list the product to Mobile Category and also any other category). So basically with the default nopcommerce you can list a product to as many categories as you want.

Please let me know if I was clear and if you have a solution for this.


Thank you in advance
5 years ago
Ok, i understand you want to avoid spamming the catalog with the same product in to many categories. I general i would think it‘s no problem when some body select a multipel subcategories from one mother categorie, because sometimes for a specific product it‘s not clear whitch is the proper subcategory. But when somebody in multiple mother categories this should not allow this is spam.

I think the easiest way is change it by hand and write them an email they please should not spam the catalog. The more scaling solution is to build an other product page with several editing processes like in amazon marketplace. I would also like to have something like the second solution but this is very specific to categories. Than you should able to select first a mother category and than special restricted fields for that category.

Let me know what you thing about that?
5 years ago
You will need to modify the ProductController.cs in Nop.Web/Areas/Admin/Controllers/ where it populates the product category

Let say you have SALE and GIFT categories and you don't want your vendors to map their product to these categories then you can perform the following.

Assuming that your vendor that does not have access to "Admin area. Manage Categories" from Access Control List

Add a permissionService as shown in the code below.


protected virtual void PrepareCategoryMappingModel(ProductModel model, Product product, bool excludeProperties)
{
    if (model == null)
        throw new ArgumentNullException(nameof(model));

    if (!excludeProperties && product != null)
        model.SelectedCategoryIds = _categoryService.GetProductCategoriesByProductId(product.Id, true).Select(c => c.CategoryId).ToList();

    var allCategories = SelectListHelper.GetCategoryList(_categoryService, _cacheManager, true);

    //check if user has manage categories access. if admin then show sale category, if vendor then don't show sale.
    
  //Vendor will have access to all product categories except SALE and GIFT
  if (!this._permissionService.Authorize(StandardPermissionProvider.ManageCategories))
    {
        foreach (var c in allCategories.Where(x => x.Value != "2127" && x.Value != "2128")) //Where Category SALE = 2127, GIFT = 2128
        {
            c.Selected = model.SelectedCategoryIds.Contains(int.Parse(c.Value));
            model.AvailableCategories.Add(c);
        }
    }
    else
  //Admin will have access to all product categories
    {
        foreach (var c in allCategories)
        {
            c.Selected = model.SelectedCategoryIds.Contains(int.Parse(c.Value));
            model.AvailableCategories.Add(c);
        }
    }
}


I guess in your case, you will need to create a logic wherein if the vendor is selling mobile phones (Mobile Category) then don't load the the other categories.

Hope this will get you going.
5 years ago
We are also looking for this solution. Is there any solution.
5 years ago
This isn’t available out of the box and you have to customise it. I was able to solve this by implementing that code I mentioned. Have you tried?
5 years ago
can we use this code for 4.1 version?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.