承接上篇文章,上篇文章完成了该插件的模块功能的开发
下面是后台模板代码
app\design\adminhtml\default\default\template\iverve\uploadpdf\catalog\product\tab
app\design\adminhtml\default\default\template\iverve\uploadpdf\catalog\product\tab\uploadpdf.phtml
<style type="text/css">
.uploadpdf-list td.label {
background: none repeat scroll 0 center transparent !important;
border: 0 none !important;
padding-bottom: 5px !important;
padding-left: 5px !important;
padding-top: 5px !important;
}
.tdf:hover {
background-color:#F5EEDF;
}
</style>
<?php $_pdfId = Mage::app()->getRequest()->getParam('editid'); ?>
<?php $_prodcutId = Mage::app()->getRequest()->getParam('id');?>
<div id="product_info_tabs_group_4_content">
<div class="entry-edit">
<div class="entry-edit-head">
<h4 class="icon-head head-edit-form fieldset-legend">
<?php if($_pdfId != ''): ?>
<?php $_editPDFDetails = $this->getEditPdfDetail($_pdfId); ?>
<?php $result = $_editPDFDetails->getData(); ?>
<?php endif; ?>
<?php if($_pdfId == ''): ?>
<?php echo $this->__('Upload'); ?>
<?php else: ?>
<?php echo $this->__("Edit ( ".$result[0]['pdfname']." )"); ?>
<?php endif; ?>
</h4>
</div>
<div id="group_fields4" class="fieldset fieldset-wide">
<div class="hor-scroll">
<table cellspacing="0" class="uploadpdf-list">
<tbody>
<tr>
<td class="label" width="100px"><label for="name"><?php echo $this->__('File Name'); ?></label></td>
<td class="value"><input type="text" value="<?php echo $result[0]['pdfname'] ?>" name="pdf_name" id="pdf_name"></td>
</tr>
<tr>
<td class="label" width="100px"><label for="name"><?php echo $this->__('Upload File'); ?></label></td>
<td class="value"><input type="file" value="" name="upload_pdf" id="Upload pdf file">
<?php echo $result[0]['pdf_file']; ?> <span><font color="#FF0000">(只允许PDF、ZIP、RAR、JPG、PNG、DOC、XLS格式,上传限制5个文件)</font></span></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="entry-edit">
<div class="entry-edit-head">
<h4 class="icon-head head-edit-form fieldset-legend"><?php echo Mage::helper('uploadpdf')->__('Manage File(s)') ?></h4>
</div>
<fieldset style="padding:0px">
<table cellspacing="0" border = "0" class="uploadpdf-list" id="table_color" style="width:100%">
<tr bgcolor="#EFE6E6">
<td class="label" width="60px"><b><?php echo $this->__('ID'); ?></b></td>
<td class="label"><b><?php echo $this->__('File Name'); ?></b></td>
<td class="label"><b><?php echo $this->__('File'); ?></b></td>
<?php /*<td class="label"><b><?php echo $this->__('Action'); ?></b></td>*/?>
<td class="label" width="60px"><b><?php echo $this->__('Remove'); ?></b></td>
</tr>
<?php $_pdfDetails = $this->getPdfDetails($_prodcutId); ?>
<?php $up = 1; ?>
<?php if($_pdfDetails->count()): ?>
<?php foreach($_pdfDetails as $_pdfDetail): ?>
<?php if($up%2==0): ?>
<tr bgcolor="#F6F6F6" class="tdf">
<?php else:?>
<tr bgcolor="#FFFFFF" class="tdf">
<?php endif; ?>
<td class="label"><?php echo $up; ?></td>
<td class="labezl"><?php echo $_pdfDetail->getPdfname();?></td>
<td class="label"><?php echo $_pdfDetail->getPdfFile();?></td>
<?php /*<td class="label"><a href="?editid=<?php echo $_pdfDetail->getPdfId(); ?>"
title="Edit (ID: <?php echo $_pdfDetail->getPdfId(); ?>)"> <?php echo $this->__('Edit'); ?> </a></td>*/?>
<td class="label"><input type="checkbox" class="testdelete" name = "chkdelete[]"
title="Delete (ID: <?php echo $_pdfDetail->getPdfId(); ?>)" value = "<?php echo $_pdfDetail->getPdfId(); ?>" /></td>
</tr>
<?php $up++; ?>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td class="label" colspan="3"><?php echo $this->__('No uploaded.'); ?></td>
</tr>
<?php endif; ?>
</table>
</fieldset>
</div>
下面是前台显示模板,请灵活运用到你想显示的位置
app\design\frontend\对应的主题\default\layout\iverve\uploadpdf
app\design\frontend\对应的主题\default\layout\iverve\uploadpdf\uploadpdf.xml
<?xml version="1.0" ?>
<layout version="0.1.0">
<catalog_product_view_tabs>
<reference name="product.info.tabs">
<block type="uploadpdf/uploadpdf" as="uploadpdfAs" template="iverve/uploadpdf/uploadpdf.phtml" />
</reference>
</catalog_product_view_tabs>
</layout>
app\design\frontend\对应的主题\default\template\iverve\uploadpdf
app\design\frontend\对应的主题\default\template\iverve\uploadpdf\uploadpdf.phtml
$_pdfDetails = $this->getPdfDetails();
if($_pdfDetails->count()){
?>
<style>
.down{
margin-bottom: 5px;
}
.down a{
font-size: 14px;
color: #626262;
}
.down a:hover{
color:#00a7e1;
text-decoration: underline;
}
</style>
<?php if($_pdfDetails->count()): ?>
<div class="collateral-box">
<div class="head">
<h2><?php echo $this->__('Downloads') ?></h2>
</div>
</div>
<?php foreach($_pdfDetails as $_pdfDetail): ?>
<?php $front = $_pdfDetail->getPdfFile(); ?>
<?php $pdfnm = $_pdfDetail->getPdfname(); ?>
<?php if($pdfnm == ""): ?>
<?php $ext = explode(".", $front); ?>
<li class="down"> <a target="_blank" href="<?php echo $_pdfDetail->getPdfPath(); ?>"><i class="fa fa-download"></i> <?php echo $ext[0]; ?> </a> </li>
<?php else: ?>
<li class="down"> <a target="_blank" href="<?php echo $_pdfDetail->getPdfPath(); ?>"><i class="fa fa-download"></i> <?php echo $pdfnm; ?> </a> </li>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php } ?>
最后是插件的开关配置文件
app\etc\modules\Iverve_Uploadpdf.xml
<?xml version="1.0"?>
<!--
@category Iverve
@package Iverve_Uploadpdf
-->
<config>
<modules>
<Iverve_Uploadpdf>
<active>true</active>
<codePool>local</codePool>
</Iverve_Uploadpdf>
</modules>
</config>
到此,产品上传附件的功能开发完毕