1

I have added a text attribute for adding a pdf files name. Then created an installation tab display a button for "Installation PDF" which the button should have an href pointing to the media folder with the file name listed in the database from the attribute.We can then just upload the pdf's into the /media folder and reference them that way. I have created the Tab and attribute. Then given the code like this to display the button in frontend.

if($_data['label'] == 'installation'): ?>

  <td class="data">
<a href="<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']); ?>" onclick="<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']); ?>"  target="_blank"><input type="submit" name="InstallationPDF"  value="Installation PDF" /></a></td>  

</tr>


<?php endif;    ?>  

But in Front end it shows like this.

enter image description here

where should i change? Any help are appreciable.

1

I don't understand because you use:

<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']); ?>

You can use the different structures:

Imagine that you have an attribute that have absolute path (e.g: magento_store.com/media/pdf/pdf_installation.pdf) then you can try with this:

<?php if($_data['label'] == 'installation'): ?>

<td class="data">
    <a href="<?php echo $_product->getData('name_attribute') ?>" 
        onclick="<?php echo $_product->getData('name_attribute') ?>"  
        target="_blank"><input 
        type="submit" 
        name="InstallationPDF"  
        value="Installation PDF" />
    </a>
</td>  

<?php endif;    ?> 

If your attribute is called 'installation_pdf' you can use also:

    <?php if($_data['label'] == 'installation'): ?>

    <td class="data">
        <a href="<?php echo $_product->getInstallationPdf() ?>" 
            onclick="<?php echo $_product->getInstallationPdf() ?>"  
            target="_blank"><input 
            type="submit" 
            name="InstallationPDF"  
            value="Installation PDF" />
        </a>
    </td>  
<?php endif;    ?>

Finally if you have only the name of the file (e.g: pdf_installation.pdf) in your attribute text value, and you save your images in 'media/pdf/' you can try with this:

<?php if($_data['label'] == 'installation'): ?>
    <?php $mediaUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); . 'pdf' ?>
    <td class="data">
        <a href="<?php echo $mediaUrl . $_product->getInstallationPdf() ?>" 
            onclick="<?php echo $mediaUrl . $_product->getInstallationPdf() ?>"  
            target="_blank"><input 
            type="submit" 
            name="InstallationPDF"  
            value="Installation PDF" />
        </a>
    </td>  
<?php endif;    ?>  
  • Thanks osrecio. I have applied the last snippet. i reached in the folder where the pdf lies. but I am not getting the pdf name of particular product. My attribute name in 'installation'. – Sheen Mar 1 '16 at 12:37
  • change $_product->getInstallationPdf() for $_product->getInstallation() or $_product->getData('installation'). If it works remeber vote up. – osrecio Mar 1 '16 at 12:47

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.