Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Pulling All Category Products’ Thumbnails into Product Detail Page
 
trrill
Jr. Member
 
Total Posts:  3
Joined:  2008-08-28
 

When viewing a Product Detail, I’d like to be able to display thumbnails of all the products from the viewed product’s “deepest” category. That is, if Product p is in Category l0 > l1 > l2, I’d like to get the collection of all products in category l2 and display their thumbnails on p‘s detail page.

I’ve successfully been able to get the basic collection of those products in the deepest assigned category:

<?php 
    $_categories 
$_product->getCategoryIds(); 
    
$_greatestCat count($_categories) - 1;
    
$_category Mage::getModel('catalog/category')->load($_categories[$_greatestCat]);
    
$this->setCategoryId($_category->getId());
?>

Then I simply call the Product List block that gets used in Category View. I basically get the correct thumbnails. The problem is that it will only display the number of products set by the current session per-page limit. If I add set the limit to ‘all’ using the key/value pair in the URL—as in http://mysite.com/l0/l1/l2/the-product?limit=all, then the thumbnails for all the products show up, the way I want.

How can I get the block to display all the products in the collection without resetting the session’s limit used in the normal Category View—either explicitly or with a URL-passed parameter?

 
Magento Community Magento Community
Magento Community
Magento Community
 
trrill
Jr. Member
 
Total Posts:  3
Joined:  2008-08-28
 

For reference, here is how I was able to solve it, though it may not be the right way. The Pager sets the PageSize on the Collection by getLimit(), but in this case , it only seems do so when the limit is an integer. That’s why trying to setPageSize explicitly in the template doesn’t work. We can leave that default functionality in place and simply return the unlimited Collection before it reaches the comparison. Of course that ‘all’ return should only be applicable on a limited basis—in my case, when we’re on a Product detail/view page:

/app/code/core/Mage/Page/Block/Html/Pager.php

public function setCollection($collection)
    
{
        $this
->_collection $collection
            
->setCurPage($this->getCurrentPage());

                    
// here be the conditions for when to setLimit to 'all'
                    
if (Mage::registry('product')) {
                        
return $this;
                    
}
                    
        
// If not int - then not limit
        
if ((int) $this->getLimit()) {
            $this
->_collection->setPageSize($this->getLimit());
        
}

        
return $this;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top