我想在magento中创建前300个订单的pdf。我想要一个功能,我将获得前300个订单并在pdf中打印他们的图像(每个订单有不同的图像)。那么我怎样才能在magento中实现这个功能。那有什么延伸吗?
答案 0 :(得分:3)
看看/app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php
public function pdfinvoicesAction(){
$orderIds = $this->getRequest()->getPost('order_ids');
$flag = false;
if (!empty($orderIds)) {
foreach ($orderIds as $orderId) {
$invoices = Mage::getResourceModel('sales/order_invoice_collection')
->setOrderFilter($orderId)
->load();
if ($invoices->getSize() > 0) {
$flag = true;
if (!isset($pdf)){
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
} else {
$pages = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
$pdf->pages = array_merge ($pdf->pages, $pages->pages);
}
}
}
if ($flag) {
return $this->_prepareDownloadResponse(
'invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').'.pdf', $pdf->render(),
'application/pdf'
);
} else {
$this->_getSession()->addError($this->__('There are no printable documents related to selected orders.'));
$this->_redirect('*/*/');
}
}
$this->_redirect('*/*/');
}
从上面的函数中,您可以将前300个订单ID分配给$ orderIds(或修改Mage :: getResourceModel('sales / order_invoice_collection以获取前300个记录)
变更:
public function pdfinvoicesAction(){
$orderIds = $this->getRequest()->getPost('order_ids');
To(类似)
public function pdfinvoices($orderIds){
$orderIds = (array) $orderIds; // first 300 record ids
更改行以将pdf保存到文件
return $this->_prepareDownloadResponse(
'invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').'.pdf', $pdf->render(),
'application/pdf'
);
要
$pdf->render();
// use the order_id for the pdf name like
$pdf->save("{$orderId}.pdf");
请参阅Error in generated pdf file using zend_pdf under Magento
你也可以删除$ this-> _redirect(' / /')