gpt4 book ai didi

php - Magento - 添加自定义批量操作 PDF

转载 作者:可可西里 更新时间:2023-10-31 22:57:43 25 4
gpt4 key购买 nike

快速提问(阅读时请记住这一点):

为什么会产生此错误(解释)以及如何编辑 pdfRmaAction()正常工作(Mass Action Printing)???

**在 Magento 中工作 v.1.10.1.0v.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>

在 (app/code/local/Nastnet/OrderPrint/Block/Sales/Order/) 中 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')));
}
}

这会导致将“打印 RMA”插入到“销售”>“订单” GridView 屏幕上的下拉菜单中的预期结果。

OrderController.php文件 (app/code/local/Nastnet/OrderPrint/controllers/) 我添加了这个 [从 pdfinvoicesAction() 复制和编辑]在 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出现错误...

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 按钮(而不是尝试通过 Mass Action 打印它),那么它很好!

我长篇大论的解释导致了这一点: 为什么会产生这个错误,我该如何编辑 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('*/*/');
}

关于php - Magento - 添加自定义批量操作 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9981315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com