我想上传多个pdf与制造商如何在magento中执行此操作?我可以使用plugin上传制造商的徽标,但我无法添加多个pdf文件与制造商。有人可以用代码或插件指导我
答案 0 :(得分:0)
我已根据需要自定义此插件
我已在插件form.php文件中添加此代码
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$select = $connection->select()
->from('manufacturer_pdf', array('*')) // select * from tablename or use array('id','title') selected values
->where('menufecturer_name=?',Mage::registry('manufacturer_data')->getData('menufecturer_name')) // where id =1
->group('pdfname'); // group by title
$_SESSION['adminmanufacuterquery']=$rowsArray = $connection->fetchAll($select); // return all rows
$rowArray =$connection->fetchRow($select); //return row
$i=1;
foreach($rowsArray as $key=>$pdf){
$_SESSION['admindbmanufacuter']="yes";
$name=$pdf['pdfname'];
$fieldset->addField('pdfnameload'.$key, 'hidden', array(
'required' => false,
'name' => 'hidden',
'after_element_html' => '<span id="pdfrow'.$key.'" class="hint"><a href="'.Mage::getBaseUrl('media')."Manufacturer/".$name.'">'.$name.'</a> <span><input type="hidden" name="oldpdf'.$key.'" value="'.$pdf['manufacturer_id'].'" /></span><span style="cursor: pointer;" onclick="test('.$key.');">Delete</span></span>'
));
$_SESSION['mycustomefield']=$i;$i++;
}
用于保存在数据库中
if(isset($_FILES['pdfname']['name']) && $_FILES['pdfname']['name'] != '') {
foreach($_FILES['pdfname']['name'] as $key=>$pdf){
if(isset($pdf) && $pdf != '') {
$pdfname=explode(".", $pdf);
if($pdfname[1]=='pdf'){
$connectionWrite = Mage::getSingleton('core/resource')->getConnection('core_write');
$pdf= str_replace(" ","_",$pdf);
$newdata['pdfname']= time().'_'.$pdf;
$newdata['menufecturer_name']=$data['menufecturer_name'];
$connectionWrite->insert('manufacturer_pdf', $newdata);
$path = Mage::getBaseDir('media') . DS ."Manufacturer".DS;
move_uploaded_file($_FILES['pdfname']['tmp_name'][$key],$path.$newdata['pdfname']);
$connectionWrite->commit();
}else{
Mage::getSingleton('adminhtml/session')->addError("Upload PDF Files Only");
Mage::getSingleton('adminhtml/session')->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
}
}