3

I need to display a product list from a category id given in a product-view page. After a large research i could see people saying this is not possible due type=catalog/product_list don't work in a product-view page. Is there any way to accomplish this??.

1

You can always write your own block or inject some custom code into catalog/product/view.phtml to fetch a product collection of a given category and show them.

So adding the product_list block into the product view page isn't the only option you've got.

Be careful though because one wrong step and you will end with some really heavy load of SQL queries.

Cheers!

2
  • The thing is that the product list is called in a custom .phtml, this .phtml is called within the cms content of a static block, and this static-block is called in the .phtml file of the top navigation menu. It works in homepage and category pages, but fails in product-view page due type="catalog/product_list" So i need to know which block type i should use to display a product list in both pages and product-view pages. do you know? – Guille Jun 5 '14 at 20:18
  • I can't inject code in catalog/product/view.phtml – Guille Jun 5 '14 at 20:19
0

First you will need to get current category id

$cat_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); 

Then get all products of that category id

$collection = Mage::getModel('catalog/product')
                             ->getCollection()
                             ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
                             ->addAttributeToSelect('*')
                             ->addAttributeToFilter('category_id', array('in' => $cat_id))

This collection than you can use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.