0

我试图用以下代码覆盖Mage_Payment_Block_Form_Container类:

<blocks>
    <module>
        <class>NS_Module_Block</class>
    </module>
    <payment>
        <rewrite>
            <form_container>NS_Module_Block_Payment_Form_Container</form_container>
        </rewrite>
    </payment>
</blocks>

然后在 app/code/community/NS/Module/Block/Payment/Form/Container.php 我简单地写下这段代码:

class NS_Module_Block_Payment_Form_Container extends Mage_Payment_Block_Form_Container {
    public function getMethods() {
      echo 'hi';die;
    }
}

然后我访问单页结帐,但这段代码永远不会被执行。我的代码有问题吗?

4

1 回答 1

3

如果你想修改one-page checkout form,你必须覆盖正确的块,因为 的instance不是Mage_Payment_Block_Form_Container直接调用的,因此它不会被直接重写覆盖。

需要重写的类是Mage_Checkout_Block_Onepage_Payment_Methods因为它最终扩展Mage_Payment_Block_Form_Container并且是实际被调用的类。所以你的重写需要阅读:

您的config.cml文件应包含

<global>
      <blocks>
        <checkout>
         <rewrite>
           <onepage_payment_methods>MyCompany_Checkout_Block_Onepage_Payment_Methods</onepage_payment_methods>
         </rewrite>
        </checkout>
       </blocks>
     </global>

并且您的班级声明为:

class MyCompany_Checkout_Block_Onepage_Payment_Methods extends Mage_Checkout_Block_Onepage_Payment_Methods
{

     //do your stuff here

} 

如果您有任何疑问,请告诉我

于 2014-06-03T16:36:30.687 回答