0

I have old code that displays a pdf from the media folder. It shows if there is a file named for it. But now for the customer to enter a NEW pdf I created an attribute called pdf_download where they can paste in the file path in the admin and it appears on the page. Currently both pdfs show when a new one is entered. I wrote a small snippet at the bottom creating $specsheet. Ultimately I would like for the script to hide the old code if the admin field is populated. When I impliment the small part at the bottom it kills my attribute from rendering. What am I missing?

<?php 
        $_helper = Mage::helper('productattachments');
        $attachments = $_helper->getAttachmentsForProduct($this->getParentBlock()->getProduct()->getId());
    ?>


    <?php if (!empty($attachments)): ?>
    <div class="ac-attachments">
        <?php  $header_attachment = Mage::getStoreConfig('attachments_module_configuration/settings_group/show_attachment_label'); ?>
        <?php if ($header_attachment != ''): ?>    
            <h2><?php echo $header_attachment; ?></h2>
        <?php endif; ?>
        <ul>
            <?php foreach($attachments as $attachment): ?>
                <li>                
                    <?php if ($_helper->isIconEnabled($attachment->getFilename()) && $_helper->getFileTypeIcon($attachment->getFilename()) !== NULL): ?>
                        <img src="<?php echo $_helper->getFileTypeIcon($attachment->getFilename()); ?>" />                
                    <?php endif; ?>
                    <a href="<?php echo Mage::getUrl('productattachments/index/downloadfile', array('name' => $attachment->getFilename(), 'att_id' => $attachment->getProductattachments_id())); ?>">
                        <?php echo $attachment->getTitle(); ?>

                        <?php if ($_helper->isShowSizeEnabled()): ?>
                            <?php $file_size = $_helper->getFileSize($attachment->getFilename()); ?>
                            <?php if ($file_size != ''): ?>
                                (<?php echo $file_size; ?>)
                            <?php endif;   ?>                        
                        <?php endif; ?>
                    </a>
                </li>
            <?php endforeach; ?>
        </ul>    
    </div>
    <?php endif; ?>


    <?php $specsheet = trim($_product->getPdfDownload());
      if (empty($specsheet)) {
        echo $attachment 
    }
    ?>
3

2 Answers 2

0

Try

<?php 
    $_product = $this->getParentBlock()->getProduct();
    $_helper = Mage::helper('productattachments');
    $attachments = $_helper->getAttachmentsForProduct($_product->getId());
?>

<?php $specsheet = trim($_product->getPdfDownload()); ?>

<?php if (!empty($specsheet)): ?>
   display attribute 
<?php elseif (!empty($attachments)): ?>
   display old code
<?php endif; ?>
1
  • Thank you sir. Worked great. What is your Twitter handle? Commented Nov 5, 2014 at 21:15
0

please this

   <?php 
    if(Mage::registry('current_product')):
    $Product=Mage::registry('current_product')
    else:
   $Product= Mage::getModel('catalog/product')->load($this->getParentBlock()->getProduct());
   endif;
    $specsheet = trim($Product->getPdfDownload());
      if (empty($specsheet)) {
        echo $attachment 
    }
    ?>

registry will work if it is product page

Mage::registry('current_product'):

else load product by product id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.