Question

I try to show Product-Attributes on the Grid-View (catalog(products/list.phtml).

At app/code/coreMage/Catalog/Block/Product/List.php I found this

public function addAttribute($code)
{
    $this->_getProductCollection()->addAttributeToSelect($code);
    return $this;
}

At my catalog.xml (theme/layout/catalog.xml) I add the following "addAttribute in my block

    <catalog_category_default translate="label">
    <label>Catalog Category (Non-Anchor)</label>
    <reference name="left">
        <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
    </reference>
    <reference name="content">
        <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
            <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">

                <action method="addAttribute"><attribute>Manufacturer</attribute></action>

At my PHTML-Template, I try to show the Manufacturer like this:

<?php echo $_product->getAttributeText('manufacturer') ?>

But it doesen't work. I don't know why. I found the tutorial via Google and I'm sure that I 've done it right. I work with Magento Enterprise 1.13. Where is my fault? Thanks for your help.

Was it helpful?

Solution

You don need all that xml markup to add an attribute to the product grid. Just edit the attribute in the backend, set the field Used in Product Listing to Yes, reindex everything and you should be able to use in catalog/product/list.phtml this:

<?php echo $_product->getAttributeText('manufacturer') ?>

OTHER TIPS

In magento 1.7.2 you have to use this

<?php echo $_product->getManufacturer() ?>

If you'd like to go a step further and display a logo for the manufacturers, you can implement the following code in both view.phtml and/or list.phtml:

   <?php $brand=$_product->getAttributeText('manufacturer');
$filename= $_SERVER['DOCUMENT_ROOT'].'/media/catalog/brands/'.str_replace(' ', '_',$brand).'.jpg';
if (file_exists($filename)) {
                    echo '<img style="float: left; margin: 2px;" src="/media/catalog/brands/'.str_replace(' ', '_',$brand).'.jpg" alt="'.$brand.'">'; 
                    }
                    ?>

Note: You need to place a jpg for each manufacturer name in your /magento/media/catalog/brand/ the name must match your manufacturer attribute.

Example:

Manufacturer = FRIDGE ----> Filename = FRIDGE.jpg

If you do not place a file matching the manufacturer attribute, the attribute name will be displayed.

In Magento 1.9 CE, we have try Marius answer and not working, we have do this:

<?php echo $this->__('Year:') . $this->htmlEscape($_product->getData('year'));?>

It can be another attribute and don't miss to turn on used in product listing.

To get value for country of manufacture you just need to write following code in your list file. This code is used for default dropdown for country manufacture for product.

Just edit the attribute in the backend, set the field "Used in Product Listing" to "Yes".

<?php echo $_product->getAttributeText('country_of_manufacture') ?>

Here country_of_manufacture is the attribute code.

I need manufacturer with a hyper link. My website having marketplace module and each seller has shop and shop name in this "block-title mp-vendor-name" . Now I want to show each seller name below product at category page.

Please help me out. Thank in advance.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top