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

How do I get the full URL of an image? 
 
msayag
Jr. Member
 
Total Posts:  25
Joined:  2008-12-22
 

Hi,
I’ve added a new image attribute to a product.
How do I get the full url of the image?

I am trying:

$attributes $_selection->getAttributes();
    if (
$frontend->getValue($_selection)) {
        $my_image 
$attributes['my_image'];
        
$frontend $my_image->getFrontend();
        if (
$frontend->getValue($_selection)) {
            $image_src 
$frontend->getValue($_selection);
            echo 
"<img src='$image_src'/>";
        
}
    }

but the url that I get is “/x/y/xyz.jpeg”.
How do I get the full path to magento/media/catalog/product/x/y/xyz.jpeg?

Calling getImageUrl() returned an empty string.

$image_src $attribute->getImageUrl();

Thanks,

Moshe

 
Magento Community Magento Community
Magento Community
Magento Community
 
ajoubert79
Jr. Member
 
Total Posts:  7
Joined:  2008-10-06
 

Not sure if this is what your looking for but to get the url of the base image is:

<?php echo $this->helper('catalog/image')->init($_product'image'?>
where $_product is the relevant product.

To get the small image for a product replace ‘image’ with ‘small_image’ or ‘thumbnail’ for the thumbnail.

If you want to get the value of an attribute you have called ‘image’ then

<?php echo $_product->getAttributeText('image'?>
should see you right.

Hope this helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
msayag
Jr. Member
 
Total Posts:  25
Joined:  2008-12-22
 

It works, thank you.

However, I get a long (and probably transient) url, something like
http://localhost/magento/media/catalog/product/cache/1/an_image/5e06319eda06f020e43594a9c230972d/x/y/xyz.jpeg

How this is better than the direct url
http://localhost/magento/media/catalog/product/x/y/xyz.jpeg

(Well, I guess it has something to do with caching… but can’t magento do this behind the scenes?)

Where can I read more about these methods ( $this->helper(...)->init(...) )

Moshe

 
Magento Community Magento Community
Magento Community
Magento Community
 
ajoubert79
Jr. Member
 
Total Posts:  7
Joined:  2008-10-06
 

I’m not sure about the direct url, I found the ( $this->helper(...)->init(...) ) code by diving through he magento code (particularly template/catalog/product/list.phtml & /view/media.phtml).  There isn’t a massive amount of documentation that I’ve come accros.  What I usually do is look on magento (front or backend) for something that does what I want to do and then try dig up the code.  If I find something of interest I usually search the magentocommerce site using google command:
site:docs.magentocommerce.com +query
or
site:www.magentocommerce.com +query
the top for the phpDocumentation and the lower for forums/wiki etc.

It helps alot when people who solve their problems post their solutions up.  With getting the direct url, I’m not sure where it is used on the front end if at all, magento might use caching on the front end and do the caching work in the backend.  Best of luck with it and if you find a solid solution don’t be shy in posting up how you got the direct url.

AJ

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