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 link to a file from the Product Details view? 
 
Brady
Guru
 
Avatar
Total Posts:  330
Joined:  2007-09-10
Orange County, CA
 

I created a new attribute called “product_support” that’s a text area, so I can fill in some HTML and link to a pdf manual.  I’m using the following code:

<a href="{{store url=''}}media/downloads/manual-meap01.pdf">manual-meap01.pdf</a>

but when I visit the live page, it redirects to http://domain.com/category/{{store url=’’}}media//downloads/manual-meap01.pdf

The only way I can get it to work is if I hard-link to the file… example: http://domain.com/media/downloads/manual-meap01.pdf

Image Attachments
Picture 1.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

the {{ }} tags will work in CMS pages, blocks and email templates only. They will not work in custom attributes.

The quick fix would be to add this to your catalog/product/view.phtml template around line 90 in default theme:

<?php $_downloadsUrl Mage::getBaseUrl('media').'/downloads/' ?>
            <?php 
foreach ($_additional as $_data): ?>
            
<tr>
                <
td class="label"><?php echo $_data['label'] ?></td>
                <
td class="data"><?php echo str_replace('{{downloads_url}}'$_downloadsUrl$_data['value']?></td>
            </
tr>
            
<?php endforeach; ?>
And add {{downloads_url}} before your file names in the attribute.
 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

You could also have generic {{base_url}} for general link purpose:

<?php $_baseUrl Mage::getBaseUrl('web'); ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Brady
Guru
 
Avatar
Total Posts:  330
Joined:  2007-09-10
Orange County, CA
 

Thanks Moshe, but didn’t you say that {{ }} does not work in the Attributes?  I added the code you suggested around like 90 in catalog/product/view.phtml and added the following to the attribute, but get the same error as mentioned in my post above.:

<a href="{{downloads_url}}manual-meap01.pdf">Download Manual (80 KB PDF)</a>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Did you replace the existing “additional information” code with this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brady
Guru
 
Avatar
Total Posts:  330
Joined:  2007-09-10
Orange County, CA
 

Ah - didn’t see that.  Works great now!  Thanks Moshe!

P.S. - I removed the “/” before “/downloads/”, so I don’t get a double “//” in the URL request.

 
Magento Community Magento Community
Magento Community
Magento Community
 
LisaPrzy
Jr. Member
 
Total Posts:  26
Joined:  2008-02-01
 

Hi Guys
I found your thread and it is very similar to what I have been trying to do, but instead of downloading a file I would like to open a link in a popup window.
Any help would be greatly appreciated.
Thanks
Lisa

 
Magento Community Magento Community
Magento Community
Magento Community
 
dstokdyk
Jr. Member
 
Total Posts:  2
Joined:  2007-12-31
 

LisaPrzy,

Did you ever get an answer or work it out for yourself?

Would love to see/hear anything you’ve learned, as I posted the same sort of question today—view here <http://www.magentocommerce.com/boards/viewthread/10274/>.

Regards,

Dale

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kara Heinrichs
Guru
 
Avatar
Total Posts:  482
Joined:  2008-01-17
aa, mi, us
 

To open a link in a new window, just target the link to a named window.  To open a link in a pop-up window, use the onclick event in the link and call a javascript function popWin that’s already defined in one of the included libraries.

Here’s an example with the link opening in a new window:

<?php $_additional $this->getAdditionalData(); ?>
<!--<?php //var_dump($_additional); ?>   use this if you want to dump and view the available attributes for debugging purposes-->
<?php if (array_key_exists('warranty'$_additional)):?>
     
<a href="http://media.mycompany.com/warranty/warranty_<?php echo ( $_additional['warranty']['value'] );?>.pdf" target="warr_win">Warranty</a>
<?php endif; ?>

Here’s an example with the link opening in a pop-up window: 

<?php $_additional $this->getAdditionalData(); ?>
<!--<?php //var_dump($_additional); ?>   use this if you want to dump and view the available attributes for debugging purposes-->
<?php if (array_key_exists('warranty'$_additional)):?>
     
<a href="#" onclick="popWin('http://media.mycompany.com/warranty/warranty_<?php echo ( $_additional['warranty']['value'] );?>.pdf','warr_win','width=800,height=600,resizable=yes,scrollbars=yes')">Warranty</a>
<?php endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top