Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

getThumbnail not working
 
[db] DigitalBlueprint
Member
 
Avatar
Total Posts:  37
Joined:  2007-10-11
Eastbourne, UK
 

Hi guys,

I have a need to use the thumbnail images for one of my views, but it seems as though there is an issue somewhere in magento that is preventing the frontend code from retrieving the thumbnail urls.

## From /app/code/core/Mage/Catalog/Model/Product.php
public function getThumbnailUrl()
    
{
        $url 
false;
        if (!
$this->getThumbnail()) {
            $url 
Mage::getDesign()->getSkinUrl('images/no_image.jpg');
        
}
        
elseif ($attribute $this->getResource()->getAttribute('thumbnail')) {
            $url 
$attribute->getFrontend()->getUrl($this);
        
}
        
return $url;
    
}

The above code will always return the no_image.jpg url, I’ve tested it by taking out the check for getThumbnail() so that it only checks the straight attribute retrieval but still get nothing returned. I’ve looked in the database and the thumbnail attribute id is set up correctly in eav_attribute table and for each product there is a related entry in the catalog_product_entity_varchar for the thumbnail that correctly points to the right attribute_id.

I’m stuck as to where to look next. Can anyone confirm that this works/doesn’t work in their Magento installation?

 
Magento Community Magento Community
Magento Community
Magento Community
 
[db] DigitalBlueprint
Member
 
Avatar
Total Posts:  37
Joined:  2007-10-11
Eastbourne, UK
 

Forgot to mention, in the admin area the thumbnail images appear fine which just adds more confusion as to why the frontend code doesn’t work.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mark_Kimsal
Sr. Member
 
Total Posts:  186
Joined:  2007-09-12
Michigan, USA
 

For some reason, only a limited sub-set of attributes are ever loaded on any given front-end page.  To load up the thumbnail property ($product->getTumbnail() returns $product->_data[’thumbnail’] property), you must specifically load all attributes on the page you want.

This is really terrible for keeping up with updates because you either have to track a 1 line change in a bunch of files, or make duplicate classes and keep track of 1 line changes in a bunch of XML files to tell the system to you your customized class files.

To load the thumbnail on the category view page add this around line 52 of Mage/Catalog/Block/Product/List.php

$collection->getProductCollection()->addAttributeToSelect('*');

So it looks something like this:

/**
     * Retrieve loaded category collection
     *
     * @return Mage_Eav_Model_Entity_Collection_Abstract
     */
    protected function _getProductCollection()
    
{
        
if (is_null($this->_productCollection)) {
            $collection 
Mage::getSingleton('catalog/layer');
            if (
$this->getShowRootCategory()) {
                $categoryId 
Mage::getStoreConfig('catalog/category/root_id');
                
$category Mage::getModel('catalog/category')->load($categoryId);
                
$collection->setCurrentCategory($category);
            
}

            $collection
->getProductCollection()->addAttributeToSelect('*');
            
$this->_productCollection $collection->getProductCollection();
        
}
        
return $this->_productCollection;
    
}

If you want to load thumbnails/all attributes for simple products on a configurable/grouped product info page, search for my thread titled “Loading Attributes” for similar instructions on different files.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Hi, here’s the lastest thread about this smile
http://www.magentocommerce.com/boards/viewthread/1610/#t7523

 
Magento Community Magento Community
Magento Community
Magento Community
 
circa1977
Member
 
Total Posts:  65
Joined:  2008-03-01
 

This thread actually started with getting the Thumbnail URL similar to the other images. In the latest release, in catalog/product helper, is the following

public function getThumbnailUrl($product)
    
{
        
return '';
    
}

which follows:

public function getImageUrl($product)
    
{
        $url 
false;
        if (!
$product->getImage()) {
            $url 
Mage::getDesign()->getSkinUrl('images/no_image.jpg');
        
}
        
elseif ($attribute $product->getResource()->getAttribute('image')) {
            $url 
$attribute->getFrontend()->getUrl($product);
        
}
        
return $url;
    
}

    
/**
     * Retrieve small image url
     *
     * @return unknown
     */
    
public function getSmallImageUrl($product)
    
{
        $url 
false;
        if (!
$product->getSmallImage()) {
            $url 
Mage::getDesign()->getSkinUrl('images/no_image.jpg');
        
}
        
elseif ($attribute $product->getResource()->getAttribute('small_image')) {
            $url 
$attribute->getFrontend()->getUrl($product);
        
}
        
return $url;
    
}

Try as I might, I can’t get the thumbnail URL method to return a URL as the other two do. I’m trying to use the thumbnail image in my cart view.

Any thoughts?

Mark

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top