我试图覆盖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格式?
答案 0 :(得分: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{
...
}
了解更多@
The Basics Of Creating A Magento Module
Magento: Overriding Core Files (Blocks, Models, Resources, Controllers)