The question:
I’m very confused with a small issue in my catalog/product/list.phtml file.
i’m trying to add the Manufacturer attribute that comes with Magento to my grid listing and have added the following code.
<?php echo $_product->getAttributeText('manufacturer') ?>
<?php if( $_product->getAttributeText('manufacturer') ): ?>
<p class="manufacturer">Manufactured by:<br/><?php echo $_product->getAttributeText('manufacturer')?></p>
<?php endif; ?>
Now this is the same code I’ve used on my product/view.phtml page and it works there. But this doesn’t work at all, the echo by its self or using it in the if statement. Both return nothing.
So I have to do something special to get these attributes on the list.phtml file?
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
Make sure the attribute manufacturer
(and others that you want to list) have the flag Use in product listing
set to Yes
. After setting the flag you should rebuild your product flat index if Flat catalog
is enabled.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0