Jump to content

Manufacturer filter in categorylist / productlist


Recommended Posts

Hello,

I just made a manufacturer filter for Prestashop V1.4.7.0.

In the categorylist you get a new dropdown menu which contains all manufacturers in that category.

If there are no products, the dropdown is not visible.

 

I hope you like this 'tweak' and if you are satisfied, you can donate some..

https://www.paypal.c...gif%3aNonHosted

 

Thanks!

 

Paul

post-330606-0-52193600-1338660014_thumb.jpg

Prestashop.zip

Edited by djpaul (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

Hi djpaul and thanks for your hack. Unfortunately it doesn't work for me (prestashop 1.4.7), since overwriting the tools.php file gives me a "fatal error" message.

Could you please state where and what did you exactly added/modified, so that I can try to join the functions in an override file and check conflicts?

 

Many thanks : )

Share this post


Link to post
Share on other sites

Hey!

I just saw that I included a wrong file.

The file in theme must be product-sort.tpl, not product-list.tpl.

Put this file in theme/youtheme/

I uploaded the new file now...

 

But te changes:

Category.php arround line 549

Tools.php arround line 2155

CategoryController line 166

product-sort.tpl line 41

 

Let me know if it works, or maybe i can have a look on your site what happens.

 

For Dawid_g: I don't know if it works since i do not have that version, just give it a shot. But make a copy of your old files!!

Edited by djpaul (see edit history)

Share this post


Link to post
Share on other sites

Hey, thanks for your answer. I confirm that the Tools.php file is cusing me that "Fatal Error" message on presta 1.4.7.0, and more specifically, the line

return ((preg_match('/^[a-zA-Z0-9_-]+$/', $value)) ? $value : ((in_array($value, $list, true)) ? $value : 'asc'));

I'll further investigate, maybe is a plugin, maybe an override I already did (I'm not using any custom made plugin btw, only the ones included in installation)

Share this post


Link to post
Share on other sites

Okay, let me know then. I made the change so he would accept integer values. Normally it returns only asc or desc.

I am busy with another site and i will implement this function in there also.

If it's done, i let you know how it went...

Share this post


Link to post
Share on other sites

Hey Studioneko. I found the problem.

You can leave the pregmatch intact. But you need to override 1 file more, Validate.php

I forgot this one to add to the zip but now it's there...

Edit in Validate.php on line 628 and add

| is_numeric($orderWay)

at the end...

 

Good luck!

Share this post


Link to post
Share on other sites
  • 2 weeks later...
  • 2 months later...

Hello.

At first, thanks for your contribution!

This was exactly what I needed for my client.

But it did not work "out of the box" for me..

At first, why did you not create override classes and controllers? You could put there only the actual functions being changed and do not touch the actual "core" files!

I am attaching the archive, which contains only override files.
It works for me under 1.4.7.0 version.

Second, CategoryController did not work at all for me. There were 3 issues with it.

Here is your code:
 


public function productListAssign()

{

$hookExecuted = false;

Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));

if(!$hookExecuted) // The hook was not executed, standard working

{

self::$smarty->assign('categoryNameComplement', '');

$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);

$this->manufacturers = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, false, false, false, 1, true, true);

$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"

$this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay);



}

else // Hook executed, use the override

$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"

self::$smarty->assign(array('nb_products' => (int)$this->nbProducts, 'manufacturers' => $this->manufacturers));

}

And here is the working one:
 


public function productListAssign()

{

$hookExecuted = false;

$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/, true);

$this->manufacturers = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/, false, false, false, 1, true, true);

$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"

$this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/);

Module::hookExec('productListAssign', array('nbProducts' => /*&*/$this->nbProducts, 'catProducts' => /*&*/$this->cat_products, 'manufacturers'=>$this->manufacturers, 'hookExecuted' => &$hookExecuted));

/* if(!$hookExecuted) // The hook was not executed, standard working

{

self::$smarty->assign('categoryNameComplement', '');

$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);

$this->manufacturers = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, false, false, false, 1, true, true);

$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"

$this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay);



}

else // Hook executed, use the override

$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"*/

self::$smarty->assign(array('nb_products' => (int)$this->nbProducts, 'manufacturers' => $this->manufacturers));

}

I don't know why, but


if(!$hookExecuted)

was never triggered for me, so I had to put the code out of it. Second, somehow


$this->orderWay

was always having 'asc' value despite the "&orderway=34" in the location string. So I had to change it to


Tools::getValue('orderway')/*$this->orderWay*/

And lastly, to make the actual filtering, I had to change


Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products

to


Module::hookExec('productListAssign', array('nbProducts' => /*&*/$this->nbProducts, 'catProducts' => /*&*/$this->cat_products

Note, in the preferences I have smarty cache disabled for debugging purposes. Maybe this affects the above described behaviour.

If anyone has some more correct ways of getting it work, your contribution would be appreciated!

EDIT: Here is the latest working version with more good looking code:


public function productListAssign()

{

$hookExecuted = false;

Module::hookExec('productListAssign', array('nbProducts' => /**/&$this->nbProducts, 'catProducts' => /**/&$this->cat_products, 'manufacturers'=>$this->manufacturers, 'hookExecuted' => /*&*/$hookExecuted));

if(!$hookExecuted) // The hook was not executed, standard working

{

self::$smarty->assign('categoryNameComplement', '');

$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/, true);

$this->manufacturers = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/, false, false, false, 1, true, true);

$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"

$this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/);



}

else // Hook executed, use the override

$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"

self::$smarty->assign(array('nb_products' => (int)$this->nbProducts, 'manufacturers' => $this->manufacturers, 'orderway' => Tools::getValue('orderway') ));

}

I only changed:
'hookExecuted' => &$hookExecuted to 'hookExecuted' => /*&*/$hookExecuted
$this->orderWay to Tools::getValue('orderway')/*$this->orderWay*/
And added 'orderway' => Tools::getValue('orderway') to the last line to have the selected manufacturer to be shown in the select box.

And still, who has ideas/knowledge about why &$hookExecuted had to be changed as well as about why $this->orderWay is not taken from $_GET, feel free to contribute!

 

Prestashop_Manuf_Filter.zip

 

Edited by Benjamin Utterback (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites
  • 3 weeks later...

Hello,

 

 

it's almost working for me ... but doesn't show names of manufacturers. The difference is that I'm using 1.4.4.1 PL version of prestashop. I'm quite new in prestashop and it's difficult for me to modified something in it...

 

Regards Mateusz

 

Hello.

 

At first, thanks for your contribution!

 

This was exactly what I needed for my client.

 

But it did not work "out of the box" for me..

 

At first, why did you not create override classes and controllers? You could put there only the actual functions being changed and do not touch the actual "core" files!

 

I am attaching the archive, which contains only override files.

It works for me under 1.4.7.0 version.

 

Second, CategoryController did not work at all for me. There were 3 issues with it.

 

Here is your code:

 

public function productListAssign()
{
 $hookExecuted = false;
 Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));
 if(!$hookExecuted) // The hook was not executed, standard working
 {
  self::$smarty->assign('categoryNameComplement', '');
  $this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);
		$this->manufacturers = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, false, false, false, 1, true, true);
  $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
  $this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay);

 }
 else // Hook executed, use the override
  $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
 self::$smarty->assign(array('nb_products' => (int)$this->nbProducts, 'manufacturers' => $this->manufacturers));
}

 

And here is the working one:

 

public function productListAssign()
{
 $hookExecuted = false;
  $this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/, true);
		$this->manufacturers = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/, false, false, false, 1, true, true);
  $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
  $this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/);
 Module::hookExec('productListAssign', array('nbProducts' => /*&*/$this->nbProducts, 'catProducts' => /*&*/$this->cat_products, 'manufacturers'=>$this->manufacturers,  'hookExecuted' => &$hookExecuted));
/*  if(!$hookExecuted) // The hook was not executed, standard working
 {
  self::$smarty->assign('categoryNameComplement', '');
  $this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);
		$this->manufacturers = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, false, false, false, 1, true, true);
  $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
  $this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay);

 }
 else // Hook executed, use the override
  $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"*/
 self::$smarty->assign(array('nb_products' => (int)$this->nbProducts, 'manufacturers' => $this->manufacturers));
}

 

I don't know why, but

if(!$hookExecuted)

was never triggered for me, so I had to put the code out of it. Second, somehow

$this->orderWay

was always having 'asc' value despite the "&orderway=34" in the location string. So I had to change it to

Tools::getValue('orderway')/*$this->orderWay*/

And lastly, to make the actual filtering, I had to change

Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products

to

Module::hookExec('productListAssign', array('nbProducts' => /*&*/$this->nbProducts, 'catProducts' => /*&*/$this->cat_products

 

Note, in the preferences I have smarty cache disabled for debugging purposes. Maybe this affects the above described behaviour.

 

If anyone has some more correct ways of getting it work, your contribution would be appreciated!

 

EDIT: Here is the latest working version with more good looking code:

public function productListAssign()
{
 $hookExecuted = false;
 Module::hookExec('productListAssign', array('nbProducts' => /**/&$this->nbProducts, 'catProducts' => /**/&$this->cat_products, 'manufacturers'=>$this->manufacturers,  'hookExecuted' => /*&*/$hookExecuted));
 if(!$hookExecuted) // The hook was not executed, standard working
 {
  self::$smarty->assign('categoryNameComplement', '');
  $this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/, true);
		$this->manufacturers = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/, false, false, false, 1, true, true);
  $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
  $this->cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, Tools::getValue('orderway')/*$this->orderWay*/);

 }
 else // Hook executed, use the override
  $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
 self::$smarty->assign(array('nb_products' => (int)$this->nbProducts, 'manufacturers' => $this->manufacturers, 'orderway' => Tools::getValue('orderway') ));
}

 

I only changed:

'hookExecuted' => &$hookExecuted to 'hookExecuted' => /*&*/$hookExecuted

$this->orderWay to Tools::getValue('orderway')/*$this->orderWay*/

And added 'orderway' => Tools::getValue('orderway') to the last line to have the selected manufacturer to be shown in the select box.

 

And still, who has ideas/knowledge about why &$hookExecuted had to be changed as well as about why $this->orderWay is not taken from $_GET, feel free to contribute!

Share this post


Link to post
Share on other sites
  • 2 months later...
  • 1 year later...
  • 1 month later...
  • 4 months later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More