快速问题(阅读时请记住这一点):
为什么会产生此错误(在解释中)以及如何编辑 pdfRmaAction()
以使其正常工作(Mass Action Printing)???
**在与 v.1.10.1.0
相同的 Magento v.1.5.1.0
中工作
冗长的解释:
我已经下载了这个扩展 ( http://www.magentocommerce.com/magento-connect/admin-order-printing-extension.html ) 来添加一个按钮到 每个 订单,这样当你进入订单时,你有一个额外的按钮来打印 RMA(从这个扩展模型 pdf 定制 - 变成了一个自定义 RMA 表格以发票为准)
它工作得很好。但是,我想向其中添加 Mass Action 打印,以便您可以检查一些订单并从下拉列表中选择 Print 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 ”插入到“销售”>“订单”网格 View 屏幕上的下拉菜单中的预期结果。
在
OrderController.php
文件 (app/code/local/Nastnet/OrderPrint/controllers/) 中,我添加了这个 [从 app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php 中的 pdfinvoicesAction()
复制和编辑: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
但是,如果您进入订单并按下 Print RMA 按钮(而不是尝试 Mass Action 打印它),那么它可以正常工作 就好了!
我冗长的解释导致了这个: 为什么会产生这个错误,我如何编辑
pdfRmaAction()
才能正常工作(批量打印)??? 最佳答案
问题是您使用的 $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('*/*/');
}
关于php - Magento - 添加自定义批量操作 PDF,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9981315/