我尝试从 Magento 重写核心文件。但是重写 block 后它无法访问,我不知道为什么?
我尝试重写的文件是:Mage_Paypal_Block_Standard_Redirect
xml配置(位于:app/local/Ga/etc/config.xml):
<global>
<models>
<ga>
<class>Ga_Model</class>
</ga>
</models>
<blocks>
<ga>
<class>Ga_Block</class>
</ga>
<paypal>
<rewrite>
<standard_redirect>
Ga_Block_Paypal_Standard_Redirect
</standard_redirect>
</rewrite>
</paypal>
</blocks>
<helpers>
<ga>
<class>Ga_Helper</class>
</ga>
</helpers>
</global>
自定义 block (位于:app/local/Ga/Block/Paypal/Standard/Redirect.php):
class Ga_Block_Paypal_Standard_Redirect extends Mage_Paypal_Block_Standard_Redirect {
protected function _toHtml()
{
return 'test';
}
}
Paypal Controller 这样调用 block :
public function redirectAction()
{
$session = Mage::getSingleton('checkout/session');
$session->setPaypalStandardQuoteId($session->getQuoteId());
$this->getResponse()->setBody($this->getLayout()->createBlock('paypal/standard_redirect')->toHtml());
$session->unsQuoteId();
$session->unsRedirectUrl();
}
重写后“createBlock”方法不返回任何内容。
我不知道我做错了什么。
谢谢
编辑: 我找到了解决方案。问题来自于这样一个事实:有必要像这样在一行中编写自定义 block 类:
<blocks>
<ga>
<class>Ga_Block</class>
</ga>
<paypal>
<rewrite>
<standard_redirect>Ga_Block_Paypal_Standard_Redirect</standard_redirect>
</rewrite>
</paypal>
</blocks>
最佳答案
遵循这个结构
<global>
<blocks>
<paypal>
<rewrite>
<standard_redirect>MyNamespace_MyModule_Block_Standard_Redirect</standard_redirect>
</rewrite>
</paypal>
</blocks>
<global>
关于php - Magento 阻止 Paypal 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23489565/