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

Why doesn’t this return grouped products? 
 
cshontz
Sr. Member
 
Avatar
Total Posts:  91
Joined:  2007-11-07
 

I put something together that basically returns a few of the most recently added products on the home page. It works fine, but when I created a new grouped product, it doesn’t show up. Can anyone explain?

class Mystore_Catalog_Block_Product_Recent extends Mage_Catalog_Block_Product_Abstract
{
    
public function __construct()
    
{
        parent
::__construct();

        
$storeId    Mage::app()->getStore()->getId();
        
$product    Mage::getModel('catalog/product');
        
        
$products   $product->setStoreId($storeId)->getCollection()
            ->
addAttributeToSelect(array('name''price''small_image'), 'inner')
            ->
addAttributeToSelect(array('special_price''special_from_date''special_to_date'), 'left')
            ->
setOrder('created_at')
            ->
setPageSize(6)
            ->
setCurPage(1);
        
        
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

        
$this->setProductCollection($products);
    
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  91
Joined:  2007-11-07
 

Fixed! It was basically getting hung up on the “price” attribute. Pull “price” out of the array, and also add “addMinimalPrice()” if you want the “Starting at:” price to be displayed.

class Mysite_Catalog_Block_Product_Recent extends Mage_Catalog_Block_Product_Abstract
{
    
public function __construct()
    
{
        parent
::__construct();

        
$storeId    Mage::app()->getStore()->getId();
        
$product    Mage::getModel('catalog/product');
        
        
$products   $product->setStoreId($storeId)->getCollection()
            ->
addAttributeToSelect(array('name''small_image'), 'inner')
            ->
addAttributeToSelect(array('special_price''special_from_date''special_to_date'), 'left')
            ->
addAttributeToSelect('price')
            ->
addMinimalPrice()
            ->
setOrder('created_at')
            ->
setPageSize(6)
            ->
setCurPage(1);
        
        
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

        
$this->setProductCollection($products);
    
}
}

Thanks for your help, Chris - I don’t know what I would’ve done without you.

No problem, Chris! Anytime! smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top