2

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.

1

5 Answers 5

5

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') ?>
1
  • It works with the option at the backend .. no XML, no PHP. Thank you very much! Commented Jul 11, 2013 at 8:00
0

In magento 1.7.2 you have to use this

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

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.

0

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.

0

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.