Jump to content
Pete Nice

Display products from 2 categories on one page

Recommended Posts

Hi,

 

I'm trying to show the products from 2 categories on one category page. I've created a blank category and assigned a custom category template with an override CategoryController.php.

 

Can anyone show me an example of a function to get the products from two categories?

Share this post


Link to post
Share on other sites

Can you not just assign all of the products to both categories? 

Share this post


Link to post
Share on other sites

I have a clothing store that has separate categories for Men & Women. I want to combine both of the 'New Arrivals' categories on one page so the products need to stay in their respective categories.

Edited by Pete Nice (see edit history)

Share this post


Link to post
Share on other sites

Prestashop has a built in category for new products. Have you tried using that? 

Share this post


Link to post
Share on other sites

Yes I could use that category but I like the flexibility of which products can be added to each independent new arrivals category. Surely someone can point me in the right direction to create a function to pull products from both categories?

Share this post


Link to post
Share on other sites

$this->category2 = new Category(10, $this->context->language->id);

$this->cat_products2 = $this->category2->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);
$this->cat_products = array_merge($this->cat_products, $this->cat_products2);

 

voila ;)

Share this post


Link to post
Share on other sites

So I modified the homefeatured module to get the products from 2 categories and merged the resulting arrays.

 

EDIT - Ha! Thanks I'd just figured that out.

Edited by Pete Nice (see edit history)

Share this post


Link to post
Share on other sites

Thanks, I actually used your method to customise my CategoryController rather than add a module

Share this post


Link to post
Share on other sites

you can also use shuffle($this->cat_products), products will be shuffled then ;)

Share this post


Link to post
Share on other sites

Hi Guys

 

I was trying to the the same, however unlike you two I'm a little lost when it comes to the php smarty stuff.

 

If you have time I wonder if either of you could explain the way you achived it and the code used, as I wouldnt mind learning how you made it work.

 

Thanks In Advance

 

@Pete,  Questlove, qaulity drummer, roots qaulity band :-)

Share this post


Link to post
Share on other sites

Hi Guys

 

I was trying to the the same, however unlike you two I'm a little lost when it comes to the php smarty stuff.

 

If you have time I wonder if either of you could explain the way you achived it and the code used, as I wouldnt mind learning how you made it work.

 

Thanks In Advance

 

@Pete,  Questlove, qaulity drummer, roots qaulity band :-)

 

 

where exactly you want to change it? for what part of website?

Share this post


Link to post
Share on other sites

Hi Vekia

 

Thanks for taking the time to repley.

 

Like Pete, i would like to have 2 catagories display on one page as I also need the flexability to select want product show in those categories

 

For example I have an on sale catagory , on that page I want to show to fashion labels that are on sale but not all mixed up, I would like to have them like below

 

 

Sale

---label 1

    ---- all the items here

---label 2

    ---- all the items here

 

I see the code you have written and looked at the CategoryController but I don't understand how you implemented it.

 

Chris

Edited by Chris2013 (see edit history)

Share this post


Link to post
Share on other sites
Hi vekia,

 

I need to put same functionality on hamepage replacing featured products.

 

Deepanshu Goel

Share this post


Link to post
Share on other sites

Hey guys, 

 

I have the following problem: I have Cat1 and Cat2. When somebody enters in Cat1, I want to list:

Cat1

     - products from Cat1

Cat2

     - products from Cat2

 

Similar when they enter Cat2, to have a label Cat2 and the products from Cat2, and label Cat1 and products from Cat1.

 

I tried the code that Vekia said, but I didn't understand where to assign Cat2 to Cat1 and Cat1 to Cat2

 

Can you please help me?

 

Thanks, Madalin

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

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