いくつかのカスタム ユーザー入力でコア販売注文機能を拡張するカスタム Magento モジュールを作成しました。注文後、このデータを管理エリアの注文詳細ページのカスタム タブに表示したいと考えています。タブリストに新しいタブを表示することができましたが、タブをクリックすると404が表示されます。
これが私のコードです:
アプリ/コード/ローカル/ザック/攻撃/etc/config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Zac_Attack>
<version>0.1.0</version>
</Zac_Attack>
</modules>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<!-- Override Adminhtml module here. -->
<Zac_Attack_Adminhtml before="Mage_Adminhtml">Zac_Attack_Adminhtml</Zac_Attack_Adminhtml>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<attack>
<file>attack.xml</file>
</attack>
</updates>
</layout>
</adminhtml>
<global>
<blocks>
<attack>
<class>Zac_Attack_Block</class>
</attack>
</blocks>
<!-- models, resources, etc -->
</global>
</config>
app/code/local/Zac/Attack/Block/Adminhtml/Sales/Order/View/Tab/Attack.php:
<?php
class Zac_Attack_Block_Adminhtml_Sales_Order_View_Tab_Design extends Mage_Adminhtml_Block_Template
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
protected function _construct()
{
parent::_construct();
$this->setTemplate( 'attack/sales/order/view/tab/attack.phtml' );
}
public function getTabLabel()
{
return $this->__( 'Attack' );
}
public function getTabTitle()
{
return $this->__( 'Attack' );
}
public function getTabClass()
{
return '';
}
public function getClass()
{
return $this->getTabClass();
}
public function getTabUrl()
{
// Here the url gets rewritten to my custom name, throws 404 when called...
// The url takes the form:
// http://mydomain.com/admin/sales_order/attack/order_id/1/key/65cbb0c2956dd9413570a2ec8761bef5/
return $this->getUrl('*/*/attack', array('_current' => true));
}
public function canShowTab()
{
return true;
}
public function isHidden()
{
return false;
}
public function getOrder()
{
return Mage::registry( 'current_order' );
}
}
app/code/local/Zac/Attack/controllers/Adminhtml/Sales/OrderController.php:
<?php
require_once "Mage/Adminhtml/controllers/Sales/OrderController.php";
class Zac_Attack_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
public function viewAction()
{
// This doesn't get called when viewing the default order detail page.
// I should see the <h1> output as the only content on the page but I don't.
die( '<h1>viewAction()</h1>' );
}
public function attackAction()
{
// This should be called when the url has the pattern '*/*/attack' (as it does
// when displaying my custom tab) however clicking this tab gives a 404.
die('<h1>attackAction()</h1>');
}
}
app/design/adminhtml/default/default/layout/attack.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<adminhtml_sales_order_view>
<reference name="sales_order_tabs">
<action method="addTab">
<name>order_design_details</name>
<block>attack/adminhtml_sales_order_view_tab_design</block>
</action>
</reference>
</adminhtml_sales_order_view>
</layout>
失敗しているように見えるのは、コントローラーのオーバーライドです。オーバーライドされたメソッド「viewAction()」もカスタム アクション「attackAction()」も呼び出されません。「Mage::getConfig()->getNode('admin/routers/adminhtml')」を出力すると、次の出力が表示されるため、構成が取得されていることがわかります。
Mage_Core_Model_Config_Element Object
(
[args] => Mage_Core_Model_Config_Element Object
(
[module] => Mage_Adminhtml
[modules] => Mage_Core_Model_Config_Element Object
(
[Mage_Index] => Mage_Index_Adminhtml
[Mage_Paygate] => Mage_Paygate_Adminhtml
[Mage_Paypal] => Mage_Paypal_Adminhtml
[widget] => Mage_Widget_Adminhtml
[Mage_GoogleOptimizer] => Mage_GoogleOptimizer_Adminhtml
[Mage_GoogleBase] => Mage_GoogleBase_Adminhtml
[Mage_Authorizenet] => Mage_Authorizenet_Adminhtml
[Mage_Bundle] => Mage_Bundle_Adminhtml
[Mage_Centinel] => Mage_Centinel_Adminhtml
[Mage_Compiler] => Mage_Compiler_Adminhtml
[connect] => Mage_Connect_Adminhtml
[Mage_Downloadable] => Mage_Downloadable_Adminhtml
[importexport] => Mage_ImportExport_Adminhtml
[Mage_PageCache] => Mage_PageCache_Adminhtml
[xmlconnect] => Mage_XmlConnect_Adminhtml
[EM_DeleteOrder_Adminhtml] => EM_DeleteOrder_Adminhtml
[find_feed] => Find_Feed_Adminhtml
[moneybookers] => Phoenix_Moneybookers
[Zac_Attack_Adminhtml] => Zac_Attack_Adminhtml
)
[frontName] => admin
)
[use] => admin
)
そこで、私の最初の質問は、カスタム タブをページに追加するための正しいアプローチに従っているかということです。
正しいアプローチに従っていない場合は、正しいアプローチを教えてください。または、アプローチ全体を明確に概説するリンクを提供してください (Magento 情報を検索すると、回答の断片が多すぎて、回答全体が十分ではありません)。
正しいアプローチに従っている場合、コントローラーがオーバーライドされないのはなぜですか?
さて、問題を明確にするのに十分な詳細を提供できたことを願っています。そうでない場合は、コメントにフォローアップの質問を投稿してください。方法がわかれば、喜んで詳しく説明します.
提供されたヘルプに事前に感謝します。
乾杯、ザック
PSコミュニティセクションに同じコントローラーをオーバーライドする別のモジュールがあることに気付きましたが、そのオーバーライドも有効になっていないようです。とにかく、干渉がないことを確認するために、デバッグの目的でサードパーティのモジュールを完全に削除しました。