php – Magento – 添加自定义批量操作PDF
快速提问(阅读时请记住这一点):
为什么会出现此错误(在解释中)以及如何编辑pdfRmaAction()以使其正常工作(批量操作打印)? **在Magento v.1.10.1.0中工作,与v.1.5.1.0相同 冗长的解释: 我已下载此扩展程序(http://www.magentocommerce.com/magento-connect/admin-order-printing-extension.html),为每个订单添加一个按钮,这样当您进入订单时,您有一个额外的按钮来打印RMA(从此扩展程序中自定义模型pdf – 转换为基于的自定义RMA表单发票) 它很棒.但是,我想向其添加批量操作打印,以便您可以检查一些订单并从下拉列表中选择打印RMA并打印这些订单的表单. 在扩展config.xml文件(app / code / local / Nastnet / OrderPrint / etc /)中,在< config>内标签是这样的: <modules> <Nastnet_OrderPrint> <version>0.1.3</version> </Nastnet_OrderPrint> </modules> <global> <blocks> <adminhtml> <rewrite> <sales_order_grid>Nastnet_OrderPrint_Block_Sales_Order_Grid</sales_order_grid> <!-- ADDED THIS FOR MASS ACTION PRINTING --> <sales_order_view>Nastnet_OrderPrint_Block_Sales_Order_View</sales_order_view> </rewrite> </adminhtml> </blocks> <rewrite> <Nastnet_OrderPrint_OrderController> <from><![CDATA[#/w+/sales_order/print/#]]></from> <to>/orderprint/order/print/</to> </Nastnet_OrderPrint_OrderController> </rewrite> <models> <Nastnet_OrderPrint> <class>Nastnet_OrderPrint_Model</class> </Nastnet_OrderPrint> </models> <pdf> <order> <default>Nastnet_OrderPrint/order_pdf_items_order_default</default> <grouped>Nastnet_OrderPrint/order_pdf_items_order_grouped</grouped> </order> </pdf> </global> <admin> <routers> <Nastnet_OrderPrint> <use>admin</use> <args> <module>Nastnet_OrderPrint</module> <!-- This is used when "catching" the rewrite above --> <frontName>orderprint</frontName> </args> </Nastnet_OrderPrint> </routers> </admin> 在Grid.php中的(app / code / local / Nastnet / OrderPrint / Block / Sales / Order /)是这样的: class Nastnet_OrderPrint_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid { protected function _prepareMassaction() { parent::_prepareMassaction(); // Append new mass action option $this->getMassactionBlock()->addItem('rmaprint',array('label' => $this->__('Print RMA'),'url' => $this->getUrl('orderprint/order/pdfRma'))); } } 这导致将“Print RMA”插入Sales>的下拉菜单中的所需结果.订单网格视图屏幕. 在OrderController.php文件(app / code / local / Nastnet / OrderPrint / controllers /)中,我添加了这个[从app / code / core / Mage / Adminhtml / controllers / Sales / OrderController中的pdfinvoicesAction()复制和编辑.PHP: public function pdfRmaAction(){ $orderIds = $this->getRequest()->getPost('order_ids'); //print_r($orderIds); $flag = false; if (!empty($orderIds)) { foreach ($orderIds as $orderId) { $invoices = Mage::getResourceModel('sales/order_invoice_collection') ->setOrderFilter($orderId) ->load(); //print get_class($invoices); //print_r($invoices->getSize()); if ($invoices->getSize() > 0) { $flag = true; if (!isset($pdf)){ $pdf = Mage::getModel('Nastnet_OrderPrint/order_pdf_order')->getPdf(array($order)); } else { $pages = Mage::getModel('Nastnet_OrderPrint/order_pdf_order')->getPdf(array($order)); $pdf->pages = array_merge ($pdf->pages,$pages->pages); } } } if ($flag) { return $this->_prepareDownloadResponse( 'rma'.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('*/*/'); } 这导致实际pdf中的错误… Fatal error: Call to a member function getStore() on a non-object in /chroot/home/artizara/dev.artizara.com/html/app/code/local/Nastnet/OrderPrint/Model/Order/Pdf/Order.php on line 60 但是,如果您按顺序并按下“打印RMA”按钮(而不是尝试“质量操作”打印它),那么它的工作正常! 我冗长的解释导致了这个问题:为什么会产生这个错误,如何编辑pdfRmaAction()才能正常工作(Mass Action Printing)? 解决方法
问题是您使用$order变量,该变量未设置为函数getPdf的参数.你可以使用这个功能:
public function pdfRmaAction() { $orderIds = $this->getRequest()->getPost('order_ids'); $flag = false; if (!empty($orderIds)) { foreach ($orderIds as $orderId) { $order = Mage::getModel('sales/order')->load($orderId); $flag = true; $order->setOrder($order); if (!isset($pdf)) { $pdf = Mage::getModel('Nastnet_OrderPrint/order_pdf_order')->getPdf(array($order)); } else { $pages = Mage::getModel('Nastnet_OrderPrint/order_pdf_order')->getPdf(array($order)); $pdf->pages = array_merge($pdf->pages,$pages->pages); } } if ($flag) { return $this->_prepareDownloadResponse( 'rma'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').'.pdf','application/pdf' ); } else { $this->_getSession()->addError($this->__('There are no printable documents related to selected orders.')); $this->_redirect('*/*/'); } } $this->_redirect('*/*/'); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |