1

我正在尝试覆盖 magento 类

class Mage_Adminhtml_Controller_Sales_Invoice extends Mage_Adminhtml_Controller_Action

我创建了一个主管和文件 local/myModules/Adminhtml/Controller/Sales/Invoice.php,它的代码是。

include_once("Mage/Adminhtml/controller/Sales/Invoice.php");


class myModules_Adminhtml_Controller_Sales_Invoice extends Mage_Adminhtml_Controller_Sales_Invoice
{
    public function printAction()
   {
    echo "child class";exit;
    if ($invoiceId = $this->getRequest()->getParam('invoice_id')) {
        if ($invoice = Mage::getModel('sales/order_invoice')->load($invoiceId)) {
            $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
            $this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').
                '.pdf', $pdf->render(), 'application/pdf');
        }
    }
    else {
        $this->_forward('noRoute');
    }
  }
}

而 local/myModules/Adminhtml/config.xml 是

  <?xml version="1.0"?>
  <config>
<modules>
    <myModules_Adminhtml>
        <version>1.1</version>
    </myModules_Adminhtml>
</modules>


<global>
        <blocks>
            <adminhtml>
                <rewrite>
                  <sales_order_view>myModules_Adminhtml_Block_Sales_Order_View</sales_order_view>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>

<admin>
        <routers>
            <adminhtml> 
                <use>admin</use>
                <args>
                    <modules> 
                        <myModules_Adminhtml before="Mage_Adminhtml">myModules_Adminhtml</myModules_Adminhtml>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

在浏览器中我有网址

/index.php/admin/sales_order_invoice/print/invoice_id/49191/

但它不显示“子类”;

实际上我想覆盖发票打印功能。我在 XML 中缺少什么?

4

1 回答 1

0

1) 'myModules' 应该是MyModules

2)由于您正在使用<myModules_Adminhtml before="Mage_Adminhtml">

代替

class Mage_Adminhtml_Controller_Sales_Invoice extends Mage_Adminhtml_Controller_Action

include_once Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'Sales' . DS . 'InvoiceController.php';

class MyModules_Adminhtml_Sales_InvoiceController extends Mage_Adminhtml_Sales_InvoiceController{
    ...
}

阅读更多 @

创建 Magento 模块的基础知识

如何重载控制器

Magento:覆盖核心文件(块、模型、资源、控制器)

于 2012-12-19T23:10:47.543 回答