0

I need to display relevant category image alongside product detail page. I need to display product's sub category image. Im using custom phtml file to display logo image on top of/before the product name. (image location)

My categories are like this, Category one Category two Category three

each category has a few manufacturers as sub categories. I need to display that manufacturer logo image on product's detail page.

I tried using module_catelog/templates/category/image.phtml but it shows some errors on this line of code.

$_imgUrl = $_category->getImageUrl()

How can I get the category image URL in my phtml file?

1

You'll need to update template files to show the manufacturer(s) logo.

Open template/catalog/product/view.phtml

=> If you want to display manufacturer image:

<?php 
     $_product = $this->getProduct();
     $manufacturerName = $_product->getAttributeText('manufacturer');
     $manufacturerId = $_product->getManufacturer();
     echo '<a href="/catalogsearch/advanced/result/?manufacturer[]='.$manufacturerId.'">' ?>
     <img src="../media/catalog/brands/<?php echo str_replace(' ', '_',$manufacturerName); ?>.png" alt="<?php echo $manufacturerName; ?>" /></a>

Manufacturer images in this example are relative to /media/catalog/brands/

=> If you want to Display Category Image :

<?php $categoryImage = Mage::getModel('catalog/layer')->getCurrentCategory()->getThumbnail(); //Get the file name of the Image stored for the category ?>

<img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.$categoryImage  ?>" /> 
  • worked like a charm. thanks. Another question I have. Is there any other way to set images of manufacturer rather than using media/catalog/brands folder? may be something like using CMS block for each manufacturer or something dynamic so someone who has no knowledge on magento code, can add/change images from backend? – Joey Sep 15 '17 at 4:32
  • plus Mage is deprecated in magento 2. so this part "=> Display Category Image " cannot be implemented in magento 2 – Joey Sep 15 '17 at 8:43
0
If(Mage::registry('current_catgory')){
    $Cat=Mage::getModel('catalog/category')->load(Mage::registry('current_catgory'));
    $name=$Cat->getName();
    $thum=  Mage::getBaseUrl('media').'catalog/category/'.$Cat->getData('thumbnail');
}

This code is work if you coming to product page from category page.

  • Thanks. "Mage" is deprecated in magento 2. So I cant use this. what if user comes from search result? or suggested product? my requirements is to show manufacturer image no matter which path user came from – Joey Sep 15 '17 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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