Jump to content

How to group products by manufacturer in product-list ( category or sub-category pages)


arash_a2k

Recommended Posts

Hello. Can someone help me plz. I want to group products by manufacturer in each category or sub-category page instead of showing all products followed by each other(default behavior).

for example in laptop page we have four groups: Sony, Apple, Samsung, Dell : and under each of them are their laptops.

 

Also I want to list products by category in manufacturer page. For example in Apple page we can have several groups containing apple products:  Ipods, Mac books, Iphones.....

 

It would be fantastic If someone could give me the right code.

Even introducing modules that can do these for me is appreciated.

I use prestashop 1.5.4.1

 

Thanks 

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

Hi. I managed to solve my first problem ( grouping by manufacturer ) :D. Thanks to this post : http://www.prestashop.com/forums/topic/223689-solved-list-manufacturers-under-category-page-ps15/

 

What I had to done was changing the code in the CategoryController.php  to this  :

at the end of the funtion "public function assignProductList()" you need to modify it to the following:

$this->manufacturers = array();
			  
if ($this->cat_products)
	 foreach ($this->cat_products as &$product) {
		   $this->manufacturers[$product['id_manufacturer']] = new Manufacturer(intval($product['id_manufacturer']), $this->context->language->id);
	 }
	 $this->context->smarty->assign(array(
		   'nb_products', $this->nbProducts,
		   'manufacturers' => $this->manufacturers,
	 ));

then add these lines of code to your product-list.tpl and modify the css  to achieve what you want.

 

{if $page_name == 'category'}
	<!-- Products list -->
	{foreach from=$manufacturers item=manufacturer}
	<p><strong>{$manufacturer->name|escape:'htmlall':'UTF-8'}</strong></p>
	<ul id="product_list" class="clear">
	{foreach from=$products item=product name=products}
	{if isset($product.manufacturer_name)}
	{if $manufacturer->name == $product.manufacturer_name}
.....


	{/if}
	{/foreach}
	</ul>
	{/foreach}
	<!-- /Products list -->
{else}
<!-- Products list -->
default product-list.tpl code
.....
<!-- Products list -->
{/if}

but my second issue is still unsolved :) If I can solve that I will inform here

Link to comment
Share on other sites

  • 2 months later...
  • 7 months later...

 

Hi. I managed to solve my first problem ( grouping by manufacturer ) :D. Thanks to this post : http://www.prestashop.com/forums/topic/223689-solved-list-manufacturers-under-category-page-ps15/

 

What I had to done was changing the code in the CategoryController.php  to this  :

at the end of the funtion "public function assignProductList()" you need to modify it to the following:

$this->manufacturers = array();
			  
if ($this->cat_products)
	 foreach ($this->cat_products as &$product) {
		   $this->manufacturers[$product['id_manufacturer']] = new Manufacturer(intval($product['id_manufacturer']), $this->context->language->id);
	 }
	 $this->context->smarty->assign(array(
		   'nb_products', $this->nbProducts,
		   'manufacturers' => $this->manufacturers,
	 ));

then add these lines of code to your product-list.tpl and modify the css  to achieve what you want.

 

{if $page_name == 'category'}
	<!-- Products list -->
	{foreach from=$manufacturers item=manufacturer}
	<p><strong>{$manufacturer->name|escape:'htmlall':'UTF-8'}</strong></p>
	<ul id="product_list" class="clear">
	{foreach from=$products item=product name=products}
	{if isset($product.manufacturer_name)}
	{if $manufacturer->name == $product.manufacturer_name}
.....


	{/if}
	{/foreach}
	</ul>
	{/foreach}
	<!-- /Products list -->
{else}
<!-- Products list -->
default product-list.tpl code
.....
<!-- Products list -->
{/if}

but my second issue is still unsolved :) If I can solve that I will inform here

 

 

 

Hi. I managed to solve my first problem ( grouping by manufacturer ) :D. Thanks to this post : http://www.prestashop.com/forums/topic/223689-solved-list-manufacturers-under-category-page-ps15/

 

What I had to done was changing the code in the CategoryController.php  to this  :

at the end of the funtion "public function assignProductList()" you need to modify it to the following:

$this->manufacturers = array();
			  
if ($this->cat_products)
	 foreach ($this->cat_products as &$product) {
		   $this->manufacturers[$product['id_manufacturer']] = new Manufacturer(intval($product['id_manufacturer']), $this->context->language->id);
	 }
	 $this->context->smarty->assign(array(
		   'nb_products', $this->nbProducts,
		   'manufacturers' => $this->manufacturers,
	 ));

then add these lines of code to your product-list.tpl and modify the css  to achieve what you want.

 

{if $page_name == 'category'}
	<!-- Products list -->
	{foreach from=$manufacturers item=manufacturer}
	<p><strong>{$manufacturer->name|escape:'htmlall':'UTF-8'}</strong></p>
	<ul id="product_list" class="clear">
	{foreach from=$products item=product name=products}
	{if isset($product.manufacturer_name)}
	{if $manufacturer->name == $product.manufacturer_name}
.....


	{/if}
	{/foreach}
	</ul>
	{/foreach}
	<!-- /Products list -->
{else}
<!-- Products list -->
default product-list.tpl code
.....
<!-- Products list -->
{/if}

but my second issue is still unsolved :) If I can solve that I will inform here

 

 

Hi arash_a2k,
Were you able to find solution to second issue?
 
Also I want to list products by category in manufacturer page. For example in Apple page we can have several groups containing apple products:  Ipods, Mac books, Iphones.....
 
I am trying to implement same feature in my website too. I will be really thankful if you have solved the problem and share your expertise on this issue.
Link to comment
Share on other sites

  • 10 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...