Magento Thumbnail

I am trying to use a thumbnail of the Magento category, but it does not work. I followed many online tutorials (e.g. http://www.douglasradburn.co.uk/getting-category-thumbnail-images-with-magento/ ) and they all mention the function:

$_category->getThumbnail() 

which should be in the category model. I am running Magento 1.6 and I can not find this feature anywhere. I also downloaded 1.5 and 1.7, looked there, and can not be found anywhere. When I run the code, it gives me no errors, but nothing is output.

Here is my complete code:

  <ul id="nav"> <?php foreach ($this->getStoreCategories() as $_category): ?> <?php echo $_category->getThumbnail(); ?> <?php echo $this->drawItem($_category) ?> <?php endforeach ?> </ul> 

(I'm trying to use a thumbnail as a menu item where it is present)


It worked. The secret is to re-query the FULL category data with this code:

 Mage::getModel('catalog/category')->load($_category->getId())->getThumbnail() 

I followed this guide somewhat:

http://www.ho.nl/blog/using_category_images_in_your_magento_navigation/

to display category thumbnails in your menu.

thank you

+6
source share
4 answers

For what it's worth, your solution works, but is pretty inefficient.

Using:

 Mage::getModel('catalog/category')->load($_category->getId())->getThumbnail() 

will add a few hundredths, or maybe even tenths of a second, for each category at the time the page loads.

The reason for this is that you are faced with the problem of getting a collection of models and getting an element inside it, and then you will add new database calls that retrieve the full data for each category. You just need to ensure that you collect the full category data first.

The reason you were before didn't work, because the category collection didn't tell you which attributes she needed to choose. In fact, it simply returned flat data from the catalog_category_entity table, and was not combined with any attribute tables.

What you need to do is probably more on these lines:

 <ul id="nav"> <?php foreach ($this->getStoreCategories()->addAttributeToSelect("*") as $_category): ?> <?php echo $_category->getThumbnail(); ?> <?php echo $this->drawItem($_category) ?> <?php endforeach ?> </ul> 

In fact, ideally you want to override the function ->getStoreCategories() to add a substitution filter.

I recommend opening app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php and finding out which very interesting collection functions were written. Mastering the EAV collections is like a ritual for Magento developers. Once you do this, you will stop!

Hope this helps.

+11
source

No need to change application / code / local / Mag / Catalog / Model / Category .php

This is easy to do with this line of code ... try this ... Its working

 $child= Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId(); $imageSrc = Mage::getModel('catalog/category')->load($child)->getThumbnail(); $ThumbnailUrl = Mage::getBaseUrl('media').'catalog/category/'.$imageSrc; echo "<img src='{$ThumbnailUrl}' />"; 
+4
source

this worked for me:

 <img src="http://etienneaigner.com/shop/media/catalog/category/ <?php echo Mage::getModel('catalog/category')->load($_category->getId())->getThumbnail(); ?>" height="338px" width="338px" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" /> 
+2
source

Just stumbled upon this answer. However, in later versions of magento 1.7+ there is no need to add overhead to the code, you can add more standard (and custom) eav attributes to the Category collection via config.xml. If you check Mage / Catalog / etc / config.xml, you will see in node that there are nodes:

  <category> <collection> <attributes> <name/> <url_key/> <is_active/> </attributes> </collection> </category> 

So, you can create your own module and add additional eav attributes:

  <category> <collection> <attributes> <thumbnail/> <image/> </attributes> </collection> </category> 

And they will be added to your collection of categories.

+1
source

Source: https://habr.com/ru/post/916046/


All Articles