HOWTO add brand or manufacturer logo to product pages

Last modified by clifference on Thu, August 26, 2010 22:35
Source|Old Revisions  

This is an old revision of the document!


Introduction

With vanilla Magento it is possible to show brand/manufacturer names on the page. These are text only and below the fold. Here is a simple method to show images above the fold where the main product information is, complete with a link that takes you to a page that shows you all products by the manufacturer.

Create Brand Logos

Since the logos are universal and unlikely to differ on a per-shop basis you may want to put these somewhere outside of the theme files. Make a directory /media/catalog/brands and put your logos in there. These can be jpg, png or gif. In this example gif images are used, all of them named as per the entries in the manufacturer attribute with underscores used for spaces. For instance the corresponding logo for ‘Acme Apparel’ becomes ‘Acme_Apparel.gif’.

Create Brand Pages

For each brand add a CMS page. Remember to set the layout, e.g. 3 columns. Include the brand name, intro text, a link to their website, words on their guarantee, sizing information and a link to all products by them. Also include a ‘back’ button so that people go back to the product and not onto the brand site ;-), for instance:

  1. <div class="category-title">
  2. <h2>Acme Apparel</h2>
  3. </div>
  4. <img style="float: right" src="/media/catalog/brands/Acme_Apparel.gif">
  5. <p>Clothes can make or break your brand identity. To have an edge - choose Acme Apparel.</p><p>2009 brings you even more choice - more styles, in the colours that matter.</p>
  6. <ul style="list-style-position:inside; list-style-type:square;padding:10px;"><li><a href="/catalogsearch/advanced/result/?manufacturer[]=NNN">Show all products by Acme Apparel</a></li>
  7. <li><a href="http://AcmeApparel.com/">Visit Acme Apparel online for detailed sizing information</a></li>
  8. <li><a onclick="history.go(-1)" href="#">Back</a></li></ul>

Note that you will need to get the reference to the ‘show all products’ correct. To do that, go into your ‘Advanced Search’, choose the brand and copy the manufacturer id returned in the results URL.

If you do not have time to setup CMS pages you can create URL rewrites that simply return the search results, i.e. add entries such as /Acme_Apparel → /catalogsearch/advanced/result/?manufacturer[]=NNN (where NNN is the search results URL id for the brand).

It will take a little while to setup these pages, just setup the one brand as a template at first. You may want to create the text in a spreadsheet application first for all the other brands as there is no way to copy CMS pages in vanilla Magento.

Open template/catalog/product/view.phtml and find somewhere where you want the logo to go, for instance after the line:

  1. <?php echo $this->getChildHtml('product_type_data') ?>

add:

  1. <?php $brand=$_product->getAttributeText('manufacturer');
  2. echo '<a href="/'.str_replace(' ', '_',$brand).'"><img style="float: right; margin: 2px;" src="/media/catalog/brands/'.str_replace(' ', '_',$brand).'.gif" alt="'.$brand.'"></a>' ?>

Test and fettle

Make sure your products actually have a brand/manufacturer in the attributes and see what the results are. You will hopefully see the logo... With ‘firebug’ you can inspect and fettle the image to look right.

Optional: When satisfied with the look, move the inline styles from the CMS page and the .phtml file into your styles.css file so you can update the look more easily.

Complete and finish

Add in the rest of the CMS pages for each brand. You can also create a brands page to show these extra CMS pages or include them in category blocks.

Show only if an image exists

For my websites I had many manufacturers and for seo & quality customer experience I couldn’t display links that are broken because I didn’t create a presentable CMS page for the manufacturer yet. I added an If statement around the code to first check if the image exists, and execute the code only if the image is there.

  1. <?php
  2. $brand=$_product->getAttributeText('manufacturer');
  3. $filename= '/var/www/vhosts/***path to folder***/media/catalog/brands/'.str_replace(' ', '_',$brand).'.gif';
  4. if (file_exists($filename)) {
  5. echo '<a href="/'.str_replace(' ', '_',$brand).'"><img style="float: right; margin: 2px;" src="/media/catalog/brands/'.str_replace(' ', '_',$brand).'.gif" alt="'.$brand.'"></a>';
  6.                    }
  7.                  ?>

Hope this helps!

IMPORTANT!!

If you are using version 1.4.0 or greater, there no longer exists a “manufacturer” attribute. Instead, find and replace every “manufacturer” in this document to “brand”. This includes the advanced search (you want your brand ID), and the PHP script that auto generates the logo. If you don’t you’ll end up with an error on Model/Product.php line 1239.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs