【问题标题】:Magento Block Paypal RewriteMagento 阻止 Paypal 重写
【发布时间】:2014-06-22 18:19:49
【问题描述】:

我尝试从 Magento 重写核心文件。但是改写块后就无法访问了,不知道为什么?

我尝试重写的文件是: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>

自定义块(位于: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 控制器这样调用块:

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" 方法重写后不返回任何内容。

我不知道我做错了什么。

谢谢

编辑: 我找到了解决方案。问题来自这样一个事实,即有必要像这样在一行中编写自定义块类:

    <blocks>
        <ga>
            <class>Ga_Block</class>
        </ga>
        <paypal>
            <rewrite>
                <standard_redirect>Ga_Block_Paypal_Standard_Redirect</standard_redirect>
            </rewrite>
        </paypal>
    </blocks>

【问题讨论】:

    标签: php magento paypal block


    【解决方案1】:

    遵循这个结构

    <global>
    <blocks>
        <paypal>
            <rewrite>
                 <standard_redirect>MyNamespace_MyModule_Block_Standard_Redirect</standard_redirect>
            </rewrite>
        </paypal>
    </blocks>
    <global>
    

    【讨论】:

    • 谢谢,但根本不重写。就像什么都不做一样,它不考虑配置,因为我们不应该添加类节点。
    • @BrunoMaurice:我很抱歉这个错误......你是否为你的模块使用了任何命名空间?查看我更新的代码
    • 当我找到解决方案时,您已经很好地回答了。谢谢;D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    相关资源
    最近更新 更多