|
For the main products page (/products.html), I’d like to have a list of all my second-level categories and their products. I don’t need nested categories, just “preview” the categories + products on the current level.
Something like:
Category 1 -------------------------------- [product] [product] [product]
Category 2 -------------------------------- [product] [product] [product]
Category 3 -------------------------------- [product] [product] [product]
I found this thread http://www.magentocommerce.com/boards/viewthread/9632/, which helped me create a new block for listing categories, but for some reason when I get a list of products, I can’t get any product attributes.
I think that I have the wrong block type configured, but honestly I’m just guessing.
Here’s some code:
From: catalog.xml
... <block type="catalog/navigation" name="catalog.category" template="catalog/category/list.phtml"/> ...
From: catalog/category/list.phtml
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php foreach ($_categories as $_category): ?> <?php $_categoryName = $this->htmlEscape($_category->getName()); $_categoryUrl = $_category->getURL(); $_categoryProducts = $_category->getProductCollection(); $_categoryProductsCount = $_category->getProductCount(); ?> <?php if ($_categoryProductsCount > 0): ?> <div class="g-container product-list"> <h2><a href="<?php echo $_categoryUrl ?>"><?php echo $_categoryName ?></a></h2>
<?php foreach ($_categoryProducts as $_product): ?> <?php $_productName = $this->htmlEscape($_product->getName()); $_productUrl = $_product->getProductUrl(); $_productSmallImageLabel = $this->htmlEscape($_product->getSmallImageLabel()); $_productImageSrc = $this->helper('catalog/image')->init($_product, 'small_image')->resize(154, 111); ?> <div class="product"> <a href="<?php echo $_productUrl ?>" title="<?php echo $_productSmallImageLabel ?>"> <img src="<?php echo $_productImageSrc ?>" width="154" height="111" alt="" /> </a>
<h3><a href="<?php echo $_productUrl ?>" title="<?php echo $_productName ?>"><?php echo $_productName ?></a></h3> <pre><?php print_r($_product) ?></pre> </div> <?php endforeach ?> </div> <?php endif ?> <?php endforeach ?>
|