Category - filter by manufacturer

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

Is there a way to filter products in a category by manufacturer.

To better explain, i have sub categories set up, e.g. Bath Panel within the Bath category. There are still a lot of bath panels, what would be useful is a way of filtering bath panels by maufacturer.

Or vice versa, when you click on a particular manufacturer, there a loads of products, what would be nice, is then filtering the specific manufacturer by the categories already set up.

Is there a way to do this, or perhaps suggestions on how to alter the code?

Thanks in advance.

Gavin
13 years ago
It's not supported out of the box
12 years ago
Found this from another post and thought I'd respond.

You can filter by attributes.

Therefore you can create a manufacturer attribute and filter by that. Does mean adding that attribute to each product.

In a similar way you can add a category attribute and filter by that. (Not sure if Manufacturers has filtering but shouldn't be to hard to look how it's done elsewhere and copy/modify.

HTH

Dave
12 years ago
+1 ^ exactly what I was going to say.
11 years ago
We Done It in Nopcommerce 2.40

Step:1

Nop.Web=>Models=>Models=> Catalog=>CategoryModel.cs



public class CategoryModel : BaseNopEntityModel
    {
    public CategoryModel()
        {
           ......................code...........................
           ......................code..........................
            /* Added For manufacturer Filter */
            this.AvailableManufacturers = new List<SelectListItem>();
        }
        ..........................code.......................
        ..........................code........................
        /* Added For manufacturer Filter */
         public IList<SelectListItem> AvailableManufacturers { get; set; }
    }



Step:2

Nop.Web=>Controller=> CatalogController.cs

In #region  Categories


namespace Nop.Web.Controllers
{
    public class CatalogController : BaseNopController
    {
        #region Fields
          ----- code----
        #endregion

        #region Constructors
            ----- code----
         #endregion

         #region Utilities
            ----- code----
         #endregion

         #region Categories

         public ActionResult Category(int categoryId, CatalogPagingFilteringModel command)
           {
            
       ---------------code------------------
       ---------------code------------------
            var model = category.ToModel();


     /*Added For manufacturer Filter */
                                
    int manid;

    if (Request.QueryString["manufacturerId"] != null)
      {
          manid = Convert.ToInt16(Request.QueryString["manufacturerId"]);
     }
      else
        {
                manid = Convert.ToInt16(Request.QueryString["manufacturerId"]);
         }

   var manufacturers = _manufacturerService.GetAllManufacturers();

    if (manufacturers.Count > 0)
     {
        var PageUrl = _webHelper.GetThisPageUrl(true);
        var Url = _webHelper.ModifyQueryString(PageUrl, "manufacturerId=" + (0).ToString(), null);
       model.AvailableManufacturers.Add(new SelectListItem()
     {
        Text =  _localizationService.GetResource("Admin.Common.All"), Value = Url
      });

   foreach (var m in manufacturers)
  {
     var currentPageUrl = _webHelper.GetThisPageUrl(true);
   var sortUrl = _webHelper.ModifyQueryString(currentPageUrl, "manufacturerId=" + (m.Id).ToString(), null);
     model.AvailableManufacturers.Add(new SelectListItem()
   {
                  Text = m.Name,
                  Value = sortUrl,
                  Selected = m.Id== manid,

               });
          }
      }
          
    /*End code  manufacturer Filter */

          //sorting
          
          ---------------code----------------
         ----------------code----------------

          //view mode
          
           ---------------code---------------
           ---------------code---------------

        //page size

          ----------------code---------------
           ---------------code--------------

        //price ranges

          ----------------code---------------
          ----------------code---------------

        //specs

            ---------------code--------------
            ---------------code--------------

       //category breadcrumb

            ---------------code---------------
            ---------------code---------------

      //subcategories

           ----------------code---------------
           ----------------code---------------

      //featured products
            ---------------code--------------
            ---------------code--------------

      //products

           var products = _productService.SearchProducts(category.Id,manid,
                _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false,
                minPriceConverted, maxPriceConverted,
                0, string.Empty, false, _workContext.WorkingLanguage.Id, selectedSpecs,
                (ProductSortingEnum)command.OrderBy, command.PageNumber - 1, command.PageSize);
            model.Products = products.Select(x => PrepareProductOverviewModel(x)).ToList();

            model.PagingFilteringContext.LoadPagedList(products);
            model.PagingFilteringContext.ViewMode = viewMode;

      //template
            -----------------------code---------------
            -----------------------code---------------

         }

          #endregion

       #region Manufacturers

         ----- code-----
         ---- code------

       #endregion

       #region Products

         ----- code-----
         ---- code------

       #endregion

       #region Product tags

          ----- code-----
          ---- code------

        #endregion

        #region Product reviews

             ----- code----
             ----- code----

        #endregion

       #region Email a friend

             ----- code----
             ----- code----

       #endregion

        #region Comparing products

            ----- code----
            ----- code----

          #endregion

        #region Searching

             ----- code----
            ----- code----

          #endregion

}
}



Step:3  Views=>Catalog=>CategoryTemplate.ProductsInGridOrLines.cshtml





<div class="category-page" alin="center">

         -------------------code------------------
                                 ....
                                 ....
                                  ....
           -------------------code-------------------

  @*page size*@
    @if (Model.PagingFilteringContext.AllowCustomersToSelectPageSize && Model.Products.Count > 0)
    {
      
        -----------------------code-----------------------
        ------------------------code-----------------------

    }
    <div class="clear">
    </div>


    @* Added For manufacturer Filter  *@
    
     @if (Model.SubCategories.Count == 0 )
     {
           <div class="">

             @Html.Label("Nop.Admin.manufacturer")

       @Html.DropDownList("Manufacturer", Model.AvailableManufacturers, "--Select--", new { onchange = "setLocation(this.value);" })
          
</div>
     }
     @* End Code *@


---------------code--------------------------

  --------------code---------------------------


</div>

11 years ago
Snowp - Thank you very much, saved me a lot of time!
11 years ago
snowp----Thank you Very Much !!!!!
10 years ago
someone was able to adjust Snowp solution to version 3.1?

with this solution i can get a dropdownlist with all the manufacturers , not only the relevance for the current chosen category and it's also not realy filtering after choosing one of the manufacturers..
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.