Jump to content

How to add block layered filter to manufacturers


Recommended Posts

What kind of help are you looking for? I already mentioned the module does not support what you're asking.

 

Your options are:

 

1) Use a different module which support this option.

2) Ask Prestashop to add this feature (I wouldn't hold my breath for a quick turnaround).

3) Find a developer to make this customization for you.

 

I would suggest option #1 as it would likely be the cheapest.

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...
  • 1 year later...
  • 1 year later...
  • 1 month later...

Hi, here is the code I edited:

In file modules/blocklayered/blocklayered.php: (do a backup of file before, please)

 

Around line 691, change:

if (Tools::getValue('id_category', Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY'))) == Configuration::get('PS_HOME_CATEGORY'))
return;

to:

if (Tools::getValue('id_category', Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY'))) == Configuration::get('PS_HOME_CATEGORY')
&& $this->context->controller->php_self != "manufacturer")
return;

Around line 1782, change:

if ($id_parent == $home_category)
return false;

to

if ($id_parent == $home_category && !Tools::getIsset("id_manufacturer_layered"))
return false;

Around line 1995, above this code:

$this->nbr_products = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'cat_filter_restriction');

add this code:

if(Tools::getIsset("id_manufacturer_layered")){
$this->nbr_products = Db::getInstance()->getValue(
'
SELECT COUNT(*) FROM '._DB_PREFIX_.'cat_filter_restriction cfr
LEFT JOIN '._DB_PREFIX_.'product p ON p.id_product = cfr.id_product
WHERE p.id_manufacturer = '.Tools::getValue("id_manufacturer_layered")
);
}

Around line 2025, add:

$id_manufacturer_layered = "";
if(Tools::getIsset("id_manufacturer_layered")) $id_manufacturer_layered = " AND m.id_manufacturer = ".Tools::getValue("id_manufacturer_layered");

just before the line $this->products = Db::getInstance()->executeS...

 

Edit sql query, changing where clause:

WHERE '.$alias_where.'.`active` = 1 AND '.$alias_where.'.`visibility` IN ("both", "catalog")

to

WHERE '.$alias_where.'.`active` = 1 AND '.$alias_where.'.`visibility` IN ("both", "catalog") '.$id_manufacturer_layered.'
Around line 3178, add:
$current_friendly_url = $filter_block['current_friendly_url'];


//manufacturers page
if(!isset($filter_block['current_friendly_url']) && Tools::getValue("p") > 1){
$current_friendly_url = "/page-".Tools::getValue("p");
}
before the line $vars = array(........
and, in $vars array, also change:
'current_friendly_url' => ((int)$n == (int)$nb_products) ? '#/show-all': '#'.$filter_block['current_friendly_url'],

to

'current_friendly_url' => ((int)$n == (int)$nb_products) ? '#/show-all': '#'.$current_friendly_url,
Inside getProducts functions, add:
//manufacturers
if(sizeof($products) == 0){
$selected_filters["manufacturer"] = Tools::getValue("id_manufacturer_layered");
$products = $this->getProductByFilters($selected_filters);
}

after $products = $this->getProductByFilters($selected_filters);

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

  • 1 month later...

Hi,

I added the code and I don't get it to work. I'm using 1.6.1.11.

I got a warning:

Warning: Invalid argument supplied for foreach() in /xxxxx/modules/blocklayered/blocklayered.php on line 759

Is it something I have missed?

Link to comment
Share on other sites

 

Hi, here is the code I edited:

 

In file modules/blocklayered/blocklayered.php: (do a backup of file before, please)

 

Around line 691, change:

if (Tools::getValue('id_category', Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY'))) == Configuration::get('PS_HOME_CATEGORY'))
return;

to:

if (Tools::getValue('id_category', Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY'))) == Configuration::get('PS_HOME_CATEGORY')
&& $this->context->controller->php_self != "manufacturer")
return;

Around line 1782, change:

if ($id_parent == $home_category)
return false;

to

if ($id_parent == $home_category && !Tools::getIsset("id_manufacturer_layered"))
return false;

Around line 1995, above this code:

$this->nbr_products = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'cat_filter_restriction');

add this code:

if(Tools::getIsset("id_manufacturer_layered")){
$this->nbr_products = Db::getInstance()->getValue(
'
SELECT COUNT(*) FROM '._DB_PREFIX_.'cat_filter_restriction cfr
LEFT JOIN '._DB_PREFIX_.'product p ON p.id_product = cfr.id_product
WHERE p.id_manufacturer = '.Tools::getValue("id_manufacturer_layered")
);
}

Around line 2025, add:

$id_manufacturer_layered = "";
if(Tools::getIsset("id_manufacturer_layered")) $id_manufacturer_layered = " AND m.id_manufacturer = ".Tools::getValue("id_manufacturer_layered");

just before the line $this->products = Db::getInstance()->executeS...

 

Edit sql query, changing where clause:

WHERE '.$alias_where.'.`active` = 1 AND '.$alias_where.'.`visibility` IN ("both", "catalog")

to

WHERE '.$alias_where.'.`active` = 1 AND '.$alias_where.'.`visibility` IN ("both", "catalog") '.$id_manufacturer_layered.'
Around line 3178, add:
$current_friendly_url = $filter_block['current_friendly_url'];


//manufacturers page
if(!isset($filter_block['current_friendly_url']) && Tools::getValue("p") > 1){
$current_friendly_url = "/page-".Tools::getValue("p");
}
before the line $vars = array(........
and, in $vars array, also change:
'current_friendly_url' => ((int)$n == (int)$nb_products) ? '#/show-all': '#'.$filter_block['current_friendly_url'],

to

'current_friendly_url' => ((int)$n == (int)$nb_products) ? '#/show-all': '#'.$current_friendly_url,
Inside getProducts functions, add:
//manufacturers
if(sizeof($products) == 0){
$selected_filters["manufacturer"] = Tools::getValue("id_manufacturer_layered");
$products = $this->getProductByFilters($selected_filters);
}

after $products = $this->getProductByFilters($selected_filters);

 

 

 

Could you please upload the file.. plus my blocklayered.php is slightly different from yours.

 

Im on 1.6.1.11

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 9 months later...
On 1/9/2017 at 11:43 AM, garciasanchezdani said:

Hi, here is the code I edited:

In file modules/blocklayered/blocklayered.php: (do a backup of file before, please)

 

Around line 691, change:


if (Tools::getValue('id_category', Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY'))) == Configuration::get('PS_HOME_CATEGORY'))
return;

to:


if (Tools::getValue('id_category', Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY'))) == Configuration::get('PS_HOME_CATEGORY')
&& $this->context->controller->php_self != "manufacturer")
return;

Around line 1782, change:


if ($id_parent == $home_category)
return false;

to


if ($id_parent == $home_category && !Tools::getIsset("id_manufacturer_layered"))
return false;

Around line 1995, above this code:


$this->nbr_products = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'cat_filter_restriction');

add this code:


if(Tools::getIsset("id_manufacturer_layered")){
$this->nbr_products = Db::getInstance()->getValue(
'
SELECT COUNT(*) FROM '._DB_PREFIX_.'cat_filter_restriction cfr
LEFT JOIN '._DB_PREFIX_.'product p ON p.id_product = cfr.id_product
WHERE p.id_manufacturer = '.Tools::getValue("id_manufacturer_layered")
);
}

Around line 2025, add:


$id_manufacturer_layered = "";
if(Tools::getIsset("id_manufacturer_layered")) $id_manufacturer_layered = " AND m.id_manufacturer = ".Tools::getValue("id_manufacturer_layered");

just before the line $this->products = Db::getInstance()->executeS...

 

Edit sql query, changing where clause:


WHERE '.$alias_where.'.`active` = 1 AND '.$alias_where.'.`visibility` IN ("both", "catalog")

to


WHERE '.$alias_where.'.`active` = 1 AND '.$alias_where.'.`visibility` IN ("both", "catalog") '.$id_manufacturer_layered.'
Around line 3178, add:

$current_friendly_url = $filter_block['current_friendly_url'];


//manufacturers page
if(!isset($filter_block['current_friendly_url']) && Tools::getValue("p") > 1){
$current_friendly_url = "/page-".Tools::getValue("p");
}
before the line $vars = array(........
and, in $vars array, also change:

'current_friendly_url' => ((int)$n == (int)$nb_products) ? '#/show-all': '#'.$filter_block['current_friendly_url'],

to


'current_friendly_url' => ((int)$n == (int)$nb_products) ? '#/show-all': '#'.$current_friendly_url,
Inside getProducts functions, add:

//manufacturers
if(sizeof($products) == 0){
$selected_filters["manufacturer"] = Tools::getValue("id_manufacturer_layered");
$products = $this->getProductByFilters($selected_filters);
}

after $products = $this->getProductByFilters($selected_filters);

 

Thanks for the suggestions @garciasanchezdani . As the other users here described, the same happened to me. After applying your modifications on the file, Prestashop showed an error which is:

Warning: Invalid argument supplied for foreach() in /xxxxx/modules/blocklayered/blocklayered.php on line ...

Also, the blocklayered filter did not appear on the manufacturers page. I did a quick edit on your code and added this:

if (is_array($filters) || is_object($filters))
                {

before this:

foreach ($filters as $type => $val)
		{

of course, added the closing } at the end, so that the whole piece of code is now:

if (is_array($filters) || is_object($filters))
                {
		
		foreach ($filters as $type => $val)
		{
			switch ($type)
			{
				case 'id_attribute_group':
					foreach ($val as $attr)
					{
						$attr_id = preg_replace('/_\d+$/', '', $attr);
						if (in_array($attr_id, $attributes) || in_array(array('id_attribute_group' => $attr_id), $attribute_group_list))
						{
							$smarty->assign('nobots', true);
							$smarty->assign('nofollow', true);
							return;
						}
						$attributes[] = $attr_id;
					}
					break;
				case 'id_feature':
					foreach ($val as $feat)
					{
						$feat_id = preg_replace('/_\d+$/', '', $feat);
						if (in_array($feat_id, $features) || in_array(array('id_feature' => $feat_id), $feature_list))
						{
							$smarty->assign('nobots', true);
							$smarty->assign('nofollow', true);
							return;
						}
						$features[] = $feat_id;
					}
					break;
				default:
					if (in_array($type, $blacklist))
					{
						if (count($val))
						{
							$smarty->assign('nobots', true);
							$smarty->assign('nofollow', true);
							return;
						}
					}
					elseif (count($val) > 1)
					{
						$smarty->assign('nobots', true);
						$smarty->assign('nofollow', true);
						return;
					}
					break;
			}
		}
		}

 

Now Prestashop (mine is 1.6.1.4) does not trigger the error anymore, but again - the blocklayered navigation filter is not visible on manufacturers page. Any ideas @garciasanchezdani?

I see that other users have the same issue too. Do you know is there anything that we are missing? We really appreciate any help here. Thanks! 

Link to comment
Share on other sites

  • 4 months 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...