I'm having a problem with the product page on a Magento site I'm working on.
I'm using the following code in a static block to display products in the header section:
{{block type="catalog/product_list" category_id="4" template="catalog/product/custom_list.phtml"}}
The thing is, the block is displaying fine on all pages except on the "product" page. Am I missing something here?
Hope you guys can help me.
custom_list.phtml:
<?php
$_productCollection = $this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="cat-product-list">
<ul class="products-grid">
<?php foreach ($_productCollection as $_product): ?>
<li class="item">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(90,60)->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(TRUE); ?>" width="90" height="60" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
It turns out that the products won't show up on the product page unless the category (category_id="4"
) is the same as the category of the product you are viewing. Found that
in List.php
.
if (Mage::registry('product')) {
$categories = Mage::registry('product')->getCategoryCollection()
->setPage(1, 1)
->load();
if ($categories->count()) {
$this->setCategoryId(current($categories->getIterator()));
}
}
I've added a local copy of the List.php
file and modified it to my needs.
It is working fine now.