我想在 magento 中创建前 300 个订单的 pdf。我想要一个功能,我将获得前 300 个订单并以 pdf 格式打印他们的图像(每个订单都有不同的图像)。那么我如何在magento中实现这个功能。有什么扩展吗?
			
			2400 次
		
1 回答
            4        
        
		
看看/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');
到(类似)
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");
请参阅Magento 下使用 zend_pdf 生成的 pdf 文件中的错误
您也可以删除 $this->_redirect(' / /')
于 2012-10-12T16:56:26.283   回答