Jump to content

filter manufacturer products by category


Recommended Posts

One of the problems of the manufacturers list page, is that it showcases all the products of that manufacturer with no way to filter them or select to only display the ones that match a criteria.

 

I have a fashion shop, and need a way to separate from "Men" "Women" "Kids" clothing, inside manufacturer pages.

Any ideas how can I do this?

 

Thanks!

Link to comment
Share on other sites

hello

i checked your page

i see there some filter at the moment

XBWIVob.png

Hi Vekia,

Thanks for the reply,

No, that is the reference website, I wold like to create a filter like that in manufacturer pages, were I can choose to show women or men shoes.

Link to comment
Share on other sites

No idea how to do this?

Not sure how is it possible to filter products in the manufacturer page so the user doenst have all products mixed (men and woman).

That link I shared is from a reference website that was able to do it. and was wondering how can I accomplish the same thing.

 

Thanks!

Link to comment
Share on other sites

Hi,

 

As you saw, I originally posted here about this.

 

I wasn't able to find a module that did what I needed so wrote one myself (actually modified blockmanufacture).  What I was hoping to do was as follows:

 

I wanted a "sticky" manufacture filter - that is to say when a manufacture was selected, all other navigation would filter by that manufacture until it was explicitly cleared.

 

I changed the home hook code in BM to set a cookie for the current manufacture.  Something like

public function hookHeader($params)
{
$id_manufacturer = Tools::getValue('id_manufacturer');
if($id_manufacturer !== false) {
$this->context->cookie->id_manufacturer = (int)$id_manufacturer;
} else {
$page_name = Dispatcher::getInstance()->getController();
if( $page_name != 'category' && $page_name != 'product') {
unset($this->context->cookie->id_manufacturer);
}
}


if( !empty( $this->context->cookie->id_manufacturer ) ) {
$id_manufacturer = $this->context->cookie->id_manufacturer;
$this->displayed_manf = new Manufacturer( $id_manufacturer, $this->context->cookie->id_lang );
$this->context->smarty->assign( 'displayed_manuf', $this->displayed_manf );
}


$this->context->controller->addCSS(($this->_path).'blockmanufacturer.css', 'all');
}
This sets a cookie when user navigates to the manufacture pages and then unsets it when ever they navigate to any page other than the product pages.

 

Then created a new template that was hooked into the center column hook that simply displays a box with what manufacture was selected

<div id="manufacturers_block_clear" class="col-xs-12">
You are currently viewing products by brand {$displayed_manuf->name}.  If you wish to clear this filter, click <a href="/" rel="nofollow">here</a>.
</div>
<div class="clearfix"></div>

Then i made some changes to blockcategories to only show the categories that contained products from the selected brands.  

// around line 195 in blockcategoies.php
$id_manufacturer = $this->context->cookie->id_manufacturer;
		
$name = $category ? $category->id : null;
if(!empty($id_manufacturer)) {
	$name .= "|" . $id_manufacturer;
}

// then around line 225
INNER JOIN `'._DB_PREFIX_.'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = '.(int)$this->context->shop->id.')';
			
$m = null;
if( !empty( $id_manufacturer ) ) {
$sql .= ' INNER JOIN `ps_category_product` cp ON (c.`id_category` = cp.`id_category`)
					INNER JOIN `ps_product` p ON (cp.`id_product` = p.`id_product` 
					AND ( cp.`id_category` = 1 OR p.`id_manufacturer` = ' . $id_manufacturer . '))';
$m = new Manufacturer( $id_manufacturer, $this->context->cookie->id_lang );
}

Then what I was hoping to be able to do was use the actionProductListModifier hook to strip out products that didn't match the selected manufacture... 

 

But thats where it started to go wrong because I could not get pagination working correctly.  The products were stripped out, but the page count still showed the total number of products as would have been shown without the filter enabled.

 

So in the end, I had to resort to modding the core code.  

 

I modded Category.getProducts to take an id for manufacturer

public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null, $id_manuf = null)

// around line 667
if(!empty($id_manuf)) {
				$sql .= ' AND p.id_manufacturer = '.(int)$id_manuf;
			}

// around line 707
	if(!empty($id_manuf)) {
					$sql .= ' AND p.id_manufacturer = '.(int)$id_manuf;
				}
			
				$sql .= ' GROUP BY product_shop.id_product';


Then changed every call to getProducts to pass in the cookie value.

 

And for me, it works.  But its a great big hack which is why wouldn't want to publish it as an actual module etc.

 

Looking at the site you posted, its clear they have done the same.  I suspect they have modded ManufactureController to take an extra query string option that determines the category.  The modded the core getProducts function for class Manufacture to take this into account.

 

Manufacture's I think are a bit of an after thought in PS.  The out of the box implementation is pretty useless since I can't see any user wanting to see a FULL list of products by manufacture, unless you only have a few.  The layered navigation filters go someway to sorting this out, but the navigation is still category "centric".  For my hack above, I have had to live without the layered navigation manufacture filter which is a shame, but the industry my shop is in is very much about people shopping by brand, so this is what I had to do.

 

If you ever find anything better, do post here.

Edited by dj060004 (see edit history)
Link to comment
Share on other sites

  • 4 years later...
  • 1 year later...
  • 4 weeks later...
  • 5 months later...
  • 3 weeks later...
  • 4 weeks later...

Hi there, we used the module "Advanced Search 4" which offers this feature : https://addons.prestashop.com/fr/recherches-filtres/2778-advanced-search-4-recherche-par-filtre-tri-par-filter.html#overview. (I am not related to the module development company). It's a bit expensive but the job is done. I'm still really surprised Prestashop does not offer that in it's core.

Link to comment
Share on other sites

  • 3 weeks later...

Hi, I have implemented a module for category filters (at the moment only categories) on the brand pages, see here or here, for PS 1.7.

The module works in a similar fashion and same styles than the default faceted search module, meaning you initially see the first level categories and you can drill down to the last category. Filtering by a category includes products from its subcategories. When you enter a subcategory, it is added to the breadcrumb so you can go back up to parent categories. 

 666657492_Screenshot2021-12-27at14_49_45.thumb.png.e54eca181cfbc15822c21f269b4600d6.png

I plan to add more filters (price range, features, etc) in the future. 

If anybody is interested PM me. 

  • Like 2
Link to comment
Share on other sites

On 6/11/2015 at 11:34 PM, dj060004 said:

Hi,

 

As you saw, I originally posted here about this.

 

I wasn't able to find a module that did what I needed so wrote one myself (actually modified blockmanufacture).  What I was hoping to do was as follows:

 

I wanted a "sticky" manufacture filter - that is to say when a manufacture was selected, all other navigation would filter by that manufacture until it was explicitly cleared.

 

I changed the home hook code in BM to set a cookie for the current manufacture.  Something like

public function hookHeader($params)
{
$id_manufacturer = Tools::getValue('id_manufacturer');
if($id_manufacturer !== false) {
$this->context->cookie->id_manufacturer = (int)$id_manufacturer;
} else {
$page_name = Dispatcher::getInstance()->getController();
if( $page_name != 'category' && $page_name != 'product') {
unset($this->context->cookie->id_manufacturer);
}
}


if( !empty( $this->context->cookie->id_manufacturer ) ) {
$id_manufacturer = $this->context->cookie->id_manufacturer;
$this->displayed_manf = new Manufacturer( $id_manufacturer, $this->context->cookie->id_lang );
$this->context->smarty->assign( 'displayed_manuf', $this->displayed_manf );
}


$this->context->controller->addCSS(($this->_path).'blockmanufacturer.css', 'all');
}
This sets a cookie when user navigates to the manufacture pages and then unsets it when ever they navigate to any page other than the product pages.

 

Then created a new template that was hooked into the center column hook that simply displays a box with what manufacture was selected

<div id="manufacturers_block_clear" class="col-xs-12">
You are currently viewing products by brand {$displayed_manuf->name}.  If you wish to clear this filter, click <a href="/" rel="nofollow">here</a>.
</div>
<div class="clearfix"></div>

Then i made some changes to blockcategories to only show the categories that contained products from the selected brands.  

// around line 195 in blockcategoies.php
$id_manufacturer = $this->context->cookie->id_manufacturer;
		
$name = $category ? $category->id : null;
if(!empty($id_manufacturer)) {
	$name .= "|" . $id_manufacturer;
}

// then around line 225
INNER JOIN `'._DB_PREFIX_.'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = '.(int)$this->context->shop->id.')';
			
$m = null;
if( !empty( $id_manufacturer ) ) {
$sql .= ' INNER JOIN `ps_category_product` cp ON (c.`id_category` = cp.`id_category`)
					INNER JOIN `ps_product` p ON (cp.`id_product` = p.`id_product` 
					AND ( cp.`id_category` = 1 OR p.`id_manufacturer` = ' . $id_manufacturer . '))';
$m = new Manufacturer( $id_manufacturer, $this->context->cookie->id_lang );
}

Then what I was hoping to be able to do was use the actionProductListModifier hook to strip out products that didn't match the selected manufacture... 

 

But thats where it started to go wrong because I could not get pagination working correctly.  The products were stripped out, but the page count still showed the total number of products as would have been shown without the filter enabled.

 

So in the end, I had to resort to modding the core code.  

 

I modded Category.getProducts to take an id for manufacturer

public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null, $id_manuf = null)

// around line 667
if(!empty($id_manuf)) {
				$sql .= ' AND p.id_manufacturer = '.(int)$id_manuf;
			}

// around line 707
	if(!empty($id_manuf)) {
					$sql .= ' AND p.id_manufacturer = '.(int)$id_manuf;
				}
			
				$sql .= ' GROUP BY product_shop.id_product';

Then changed every call to getProducts to pass in the cookie value.

 

And for me, it works.  But its a great big hack which is why wouldn't want to publish it as an actual module etc.

 

Looking at the site you posted, its clear they have done the same.  I suspect they have modded ManufactureController to take an extra query string option that determines the category.  The modded the core getProducts function for class Manufacture to take this into account.

 

Manufacture's I think are a bit of an after thought in PS.  The out of the box implementation is pretty useless since I can't see any user wanting to see a FULL list of products by manufacture, unless you only have a few.  The layered navigation filters go someway to sorting this out, but the navigation is still category "centric".  For my hack above, I have had to live without the layered navigation manufacture filter which is a shame, but the industry my shop is in is very much about people shopping by brand, so this is what I had to do tutu box.

 

If you ever find anything better, do post here.

It works fabulously for separating product pages.

Edited by kleipin (see edit history)
Link to comment
Share on other sites

  • 2 months later...
On 12/27/2021 at 3:51 PM, w3bsolutions said:

Hi, I have implemented a module for category filters (at the moment only categories) on the brand pages, see here or here, for PS 1.7.

The module works in a similar fashion and same styles than the default faceted search module, meaning you initially see the first level categories and you can drill down to the last category. Filtering by a category includes products from its subcategories. When you enter a subcategory, it is added to the breadcrumb so you can go back up to parent categories. 

 666657492_Screenshot2021-12-27at14_49_45.thumb.png.e54eca181cfbc15822c21f269b4600d6.png

I plan to add more filters (price range, features, etc) in the future. 

If anybody is interested PM me. 

This is almost exactly what I need, but instead of "ajax filtering" it should redirect to a real URL, like your breadcrumb example suggests. 

So in your example, the "filtered" URL should be domain.tld/brands/studio-design/clothes/men/hoodies

Could you make this possible @w3bsolutions ?

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...