Magento

eCommerce Software for Online Growth

Magento Forum

From setting up your store to managing your products, pages and promotions to generating detailed reports, the Magento User Guide empowers the user to utilize the platform for all of its vast capacity.
Available in eBook and Print formats – Download Now!!!
   
How do I do a category + products list view? 
 
Mike G.
Jr. Member
 
Total Posts:  9
Joined:  2009-07-06
 

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(154111);
                
?>
                
                
<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 ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mike G.
Jr. Member
 
Total Posts:  9
Joined:  2009-07-06
 

For anyone who also experiences this problem, I was able to resolve it by re-loading the product by SKU in the inner for…each. I can’t see this as an very efficient solution, but it did seem to work.

If anyone sees a better way to accomplish this same task, I’d like to know.

<?php
    
// Refresh $_product so all attributes become available
    
$_product                $_product->loadByAttribute('sku'$_product->getSku());
    
$_productName            $this->htmlEscape($_product->getName());
    
$_productUrl             $_product->getProductUrl();
    
$_productSmallImageLabel $this->htmlEscape($_product->getSmallImageLabel());
    
$_productImageSrc        $this->helper('catalog/image')->init($_product'small_image')->resize(154111);
?>

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
© Copyright 2010 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
177733 users|984 users currently online|277180 forum posts