Magento-添加自定义大规模动作PDF [英] Magento - Add Custom Mass Action PDF
问题描述
快速提问(阅读时请记住这一点):
为什么会产生此错误(解释中为 ),如何编辑pdfRmaAction()
以使其正常工作(质量动作打印)?
Why is this error being produced (in explanation) and how can I edit the pdfRmaAction()
to work correctly (Mass Action Printing)???
**在Magento v.1.10.1.0
中工作,与v.1.5.1.0
**Working in Magento v.1.10.1.0
which is the same as v.1.5.1.0
详尽的解释:
我已经下载了此扩展程序( http://www .magentocommerce.com/magento-connect/admin-order-printing-extension.html )为每个订单添加一个按钮,这样当您进入该订单时,就会有一个额外的按钮以打印RMA(根据此扩展模型pdf进行自定义-根据发票已转换为自定义RMA表单)
I've downloaded this extension (http://www.magentocommerce.com/magento-connect/admin-order-printing-extension.html) to add a button to each order so that when you go into the order, you have an extra button to print an RMA (Customized from this extensions Model pdf - turned into a custom RMA form based on invoice)
效果很好.但是,我想在其中添加Mass Action打印,以便您可以检查一些订单,然后从下拉菜单中选择 Print RMA 并为这些订单打印表格.
It works great. However, I want to add Mass Action printing to it so that you can check a few orders and choose Print RMA from the dropdown and print the forms for those orders.
在扩展名config.xml
文件(应用程序/代码/本地/Nastnet/OrderPrint/etc/)中,<config>
标记内部是这样的:
In the extensions config.xml
file (app/code/local/Nastnet/OrderPrint/etc/), inside the <config>
tags is this:
<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/)中是这样的:
In (app/code/local/Nastnet/OrderPrint/Block/Sales/Order/) in Grid.php
is this:
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')));
}
}
这将导致在销售">订单"网格视图屏幕上的下拉菜单中插入"打印RMA "的预期结果.
This leads to the desired result of inserting "Print RMA" into the dropdown menu on the Sales > Orders grid view screen.
在OrderController.php
文件(app/code/local/Nastnet/OrderPrint/controllers/)中,我在[c7>的app/code/core/Mage/Adminhtml/controllers/中复制并编辑了此文件Sales/OrderController.php:
In the OrderController.php
file (app/code/local/Nastnet/OrderPrint/controllers/) I've added this [copied and edited from the pdfinvoicesAction()
in app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.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错误...
This leads to an error in the actual 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 按钮(而不是尝试进行大规模动作打印),则它会正常运行 就好了!
However, if you go into the order and press the Print RMA button (instead of trying to Mass Action print it) then it works Just Fine!
我冗长的解释导致此错误: 为什么会产生此错误,我该如何编辑pdfRmaAction()
以使其正常工作(大规模动作打印)? >
My long winded explanation leads to this: Why is this error being produced and how can I edit the pdfRmaAction()
to work correctly (Mass Action Printing)???
推荐答案
问题是您使用的$order
变量未设置为函数getPdf
的参数.您可以使用此功能:
The problem is that you use an $order
variable which is not set as a parameter for the function getPdf
. You should be fine with this function:
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('*/*/');
}
这篇关于Magento-添加自定义大规模动作PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!