I have answered here for the exact same problem. It describes in detail how to achieve this. I also provided the complete reference for the module that will help us to achieve it.
EDIT
In my approach, we are going to create a module that mainly add a block on product view page, in which we will display our product list based on category id.
config.xml
our module's configuration file tells to magento that, hey magento I have a module with some blocks and some layouts.
Layout is for defining blocks that we will set to show in product view page and in block area we will add code for load product list based on category Id in the layout block that we are going to define.
Location:app/code/local/Programmerrkt/Listinview/etc/config.xml
<config>
<modules>
<Programmerrkt_Listinview>
<version>0.1.0</version>
</Programmerrkt_Listinview>
</modules>
<frontend>
<layout>
<updates>
<programmerrkt_listinview>
<file>programmerrkt_listinview.xml</file>
</programmerrkt_listinview>
</updates>
</layout>
</frontend>
<global>
<blocks>
<programmerrkt_listinview>
<class>Programmerrkt_Listinview_Block</class>
</programmerrkt_listinview>
</blocks>
</global>
</config>
layout
Our layout file is use to add a custom block in product view page. Later product list is going to show through this custom block.
Location:app/design/<your_package/<your_theme>/layout/programmerrkt_listinview.xml
<layout>
<catalog_product_view>
<reference name="content">
<block type="programmerrkt_listinview/catalog_product_list" name="listinview_list" as="listinview_list" template="programmerrkt/listinview/catalog/product/list.phtml" />
</reference>
</catalog_product_view>
</layout>
Template
So we have defined a template in our layout file. The location of template in app/design/fronend/<your_package>/<your_theme>/template/programmerrkt/listinview/catalog/product/list.phtml
. What is the content in our list.phtml
? Can you guess ? Yes we are going to use the exact same content in magento's default product list template. Its cool right ?
So copy paste content in app/design/fronend/<your_package>/<your_theme>/template/catalog/product/list.phtml
to our module's list.phtml
file.
Block
So in our template, we can see that we are calling products to our template like this
$_productCollection=$this->getLoadedProductCollection();
For us $_productCollection
should hold product collection of our desired category. So let us define a custom getLoadedProductCollection()
in backend so that it loads desired collection of products.
Location: app/code/local/Programmerrkt/Listinview/Block/Catalog/Product/List.php
<?php
class Programmerrkt_Listinview_Block_Catalog_Product_List extends Mage_Catalog_Block_Product_List
{
/**
* Default Category that is going to load
*
* @var string
*/
protected $_defaultCategoryId = '12';
/**
* Default toolbar block name
*
* @var string
*/
protected $_defaultToolbarBlock = 'catalog/product_list_toolbar';
/**
* Product Collection
*
* @var Mage_Eav_Model_Entity_Collection_Abstract
*/
protected $_productCollection;
/**
* Retrieve loaded category collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
*/
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$layer = $this->getLayer();
$category = Mage::getModel('catalog/category')->load($this->_defaultCategoryId);
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
$this->addModelTags($category);
}
$this->_productCollection = $layer->getProductCollection();
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
}
return $this->_productCollection;
}
/*
Calling method from view
*/
public function getLoadedProductCollection()
{
return $this->_getProductCollection();
}
}
What we did here is, we define a protected $_defaultCategoryId
(here I set it to 12) and using that Id we are loading product collection. You put your category id here.
For more details GITHUB
Now clear all cache. load any product view page. Did you see our product list at the bottom of our page ?
Play with this module. Thanks.