【问题标题】:Creating cumulative pdf of orders in magento在magento中创建订单的累积pdf
【发布时间】:2012-10-12 06:33:13
【问题描述】:

我想在 magento 中创建一个包含前 300 个订单的 pdf。我想要一个功能,我将获得前 300 个订单并以 pdf 格式打印他们的图像(每个订单都有不同的图像)。那么我如何在magento中实现这个功能。是否有任何扩展?

【问题讨论】:

    标签: magento-1.7 magento


    【解决方案1】:

    看看/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 条记录)

    magento orders list query

    变化:

    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");
    

    Error in generated pdf file using zend_pdf under Magento

    你也可以删除 $this->_redirect('//')

    【讨论】:

    • 如何用上面的数据打印pdf?在外部脚本中?
    猜你喜欢
    • 2011-11-29
    • 1970-01-01
    • 2016-11-24
    • 2012-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多