duanqiao1947 2014-10-30 11:38
浏览 30
已采纳

产品PDF附件 - 具有多个文件的属性

I have created a product attribute called product_downloads, I can put a file name there and it appears in the product view page in the tab "Additional Information" with a link to the file name. I have successfully implemented this idea for one download, but for some products I will have multiple downloads...

Like I said, I have the code working with one download per product, all that took was a small amount of code inside of app/design/frontend/base/default/template/catalog/product/view/attributes.phtml

Where the original code was:

<?php foreach ($_additional as $_data): ?>
    <tr>
        <th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
<?php endforeach; ?>

this is the code I have replaced that with:

<?php foreach ($_additional as $_data): ?>
<?php if ((string)$_data['value'] != '' and $_data['value'] != 'N/A'): ?>   <!-- IF NOTHING DO NOTHING-->
<tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <?php if ($_data['code'] == 'product_download'): ?>
        <td>
                    <a href="<?php echo Mage::getBaseUrl('web',true). "media/downloads/{$_product->getProductDownload()}";?>">Product PDF</a>
        </td>
        <?php else: ?>          
                <?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
        <?php endif; ?>
    </tr>
<?php endif; ?>
<?php endforeach; ?>

This works perfectly, however... What I need now is to look at the value of product_download, if it has a comma(or some other divider, if this would interfere with a csv format) make two separate links to two seperate files..

One major thing to note... I rely heavily on MAGMI, which is why I have taken this route as no extension allows me to massively import attachments to products.

This is for spec sheets and such... some products have multiple spec sheets. I want to use a single attribute to store multiple file names and have code that will differentiate between the two.

  • 写回答

1条回答 默认 最新

  • dql123000 2014-10-30 12:12
    关注

    you can use logic with explode function And change your if condition with my custom code as below

    <?php if ($_data['code'] == 'product_download'): ?>
    <?php
    $product_downloads = explode(",",$_product->getProductDownload());
    
    foreach($product_downloads as $download):
    ?>
            <td>
                        <a href="<?php echo Mage::getBaseUrl('web',true). "media/downloads/{$download}";?>">Product PDF</a>
            </td>
    <?php endforeach; ?>
            <?php else: ?>          
                    <?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
            <?php endif; ?>
    

    this is just logic you can use as per your thoughts as well.

    hope this will sure help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用