I'll show my category list in a static block
<div>{{block type="catalog/product_list" category_id="488" template="catalog/product/list.phtml"}}</div>
No problem. But now I'm try to use the upsell.phtml- Template with
<div>{{block type="catalog/product_list" category_id="488" template="catalog/product/list/upsell.phtml"}}</div>
and I'll get these PHP Error. I'm not a PHP-developer, can you help me?
Fatal error: Call to a member function getItems() on a non-object in /var/www/.../catalog/product/list/upsell.phtml on line 1
and there's the standard Magento Code (upsell.phtml)
<?php if(count($this->getItemCollection()->getItems())): ?>
I have no idea what's wrong?!
Best Answer
You are attempting to only change the template, not the block type. If you check the block
Mage_Catalog_Model_Product_list
you will see that there is nogetItemCollection
method on it, therefore this call will return null (or possibly an empty string, can't remember off the top of my head). This results in your template attempting to callgetItems
on that null/empty string. As @Keyul suggests the solution would be to use the block type that the upsell.phtml file is associated with, which isMage_Catalog_Model_Product_List_Upsell
. This block has the methodgetItemCollection
and thus returns the collection expected in the template.