[英]Magento - Add Custom Mass Action 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>
在(应用程序/代码/本地/ Nastnet / OrderPrint /座/销售/订单/)在Grid.php
是这样的:
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> Orders网格视图屏幕的下拉菜单中的所需结果。
在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', $pdf->render(),
'application/pdf'
);
} else {
$this->_getSession()->addError($this->__('There are no printable documents related to selected orders.'));
$this->_redirect('*/*/');
}
}
$this->_redirect('*/*/');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.