Try the Demo

Magento Forum

   
related products attributes on product details page
 
danieln
Sr. Member
 
Avatar
Total Posts:  131
Joined:  2007-11-08
Mainz, Germany
 

Hello,

I would like to display related products with more details (some custom attributes) on the product details page.  Right now I’m stuck with the getAttributes() method which results in a blank page.

This is the code I’m using in template/catalog/product/list/related.html:

<?php if($this->getItems()->getSize()): ?>
    <?php 
foreach($this->getItems() as $_item): ?>
        <?php 
            
/* @var $relatedProduct Mage_Catalog_Model_Product */
            
$relatedProduct Mage::getModel('catalog/product')->load($_item->getId());
            
Zend_Debug::dump($relatedProduct->getAttributes());
        
?>
    <?php 
endforeach; ?>
<?php 
endif ?>

On product datails page, attributes are loaded by using the getAdditionalData() method. But this only uses the current product from registry.

Now I’m wondering if I would have to extend the Mage_Catalog_Block_Product_View_Attributes to make this method available for other products than the current or if there is a simpler way I didn’t think of.

Any suggestions?

Best regards,
Daniel

 Signature 

netz98.de - new media gmbh.

 
Magento Community Magento Community
Magento Community
Magento Community
 
somesid
Sr. Member
 
Total Posts:  83
Joined:  2008-06-20
 

The easiest way would be I think to override /app/code/core/Mage/Catalog/Block/Product/List/Related.php

Then add the attributes you want to select

->addAttributeToSelect('attribute1')
    ->
addAttributeToSelect('attribute2')

in

protected function _prepareData()
 
{
    
...
        
$this->_itemCollection $product->getRelatedProductCollection()
            ->
addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->
addAttributeToSelect('attribute1')
            ->
addAttributeToSelect('attribute2'
            ->
addAttributeToSort('position''asc')
            ->
addStoreFilter()
            ->
addExcludeProductFilter(Mage::getSingleton('checkout/cart')->getProductIds());
     ...
}

Then in /app/design/frontend/default/default/template/catalog/product/list/related.phtml you can just use :

$_item->getAttribute1(); to get your attribute.

 
Magento Community Magento Community
Magento Community
Magento Community
 
somesid
Sr. Member
 
Total Posts:  83
Joined:  2008-06-20
 

And anyway there is nothing wrong with those 2 lines :

$relatedProduct Mage::getModel('catalog/product')->load($_item->getId());
$relatedProduct->getAttributes();

but using var_dump() it gets a really big dump, that’s maybe why you get a blank page. You could use :

var_dump($relatedProduct->getData('attribute1'));
and it seems to work fine.

 
Magento Community Magento Community
Magento Community
Magento Community
 
danieln
Sr. Member
 
Avatar
Total Posts:  131
Joined:  2007-11-08
Mainz, Germany
 

Hello somesid,

thank for your reply!

I’ve tried it with getData method and yes I get the attribute id. But I’m looking for the value, not just the entity. I guess I have to go with the class extension…

Later,
Daniel

 Signature 

netz98.de - new media gmbh.

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