The error appears because you are creating an instance of the Mage_Catalog_Block_Product_List
class using new
. You should use the createBlock
method because some other stuff happens in there. Also I don't think you need to create an instance of Mage_Catalog_Block_Product_List_Toolbar
block. This should happen automatically (on the same line where you get the error).
While you are at it, don't create an instance of the category model like that either. Use Mage::getModel()
.
And I don't think that calling setCollection
on the list block will work. Try setting the category id.
So your code shold become:
require_once ('app/Mage.php');
umask(0);
Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
$layout = Mage::app('default')->setCurrentStore( Mage::app()->getStore()->getId() )
->getLayout();
$layout->getUpdate()
->addHandle('default')
->load();
$layout->generateXml()->generateBlocks();
$head=$layout->getBlock('head');
echo $head->toHtml();
<!-- NOW THE LIST BLOCK -->
$categoryid = 3;
$category = Mage::getModel('catalog/category');
$category->load($categoryid);
$list_block= Mage::app()->getLayout()->createBlock('catalog/product_list');
$list_block->setCategoryId($categoryid)->setTemplate('catalog/product/list.phtml');
?>
<pre><?php echo $list_block->toHtml();?></pre>