将步骤添加到OPC而不进行覆盖:更新部分 [英] add step to OPC without overriding: update section

查看:81
本文介绍了将步骤添加到OPC而不进行覆盖:更新部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是对此 one 的后续问题.
> 我要在观察员的运输方法之前增加一个步骤.我在获取用于更新步骤的标签内容的html时遇到问题.尽管我已尽力而为,但它仍然加载了运输方法步骤的html而不是我想要的html.
这是观察者的代码:

so this is a follow up question of this one.
I am adding a step before the shipping-methods by observer. I have a problem for getting the html used to update the step's tab content. Despite my best efforts it still loads the html of the shipping-method step instead of the html I want.
This is the code of the observer:

public function gotoViesStep($observer)
{
    $response = $observer->getEvent()->getControllerAction()->getResponse();
    $body = $response->getBody();
    $result = Mage::helper('core')->jsonDecode($body);

    if (in_array('error', $result)) {
        return;
    }

    //if conditions are met, go to vies check
    if ($result['goto_section'] == 'shipping_method') {
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        $shippingAddress = $quote->getShippingAddress();
        $countryId = $shippingAddress->getCountryId();

        if (($countryId != 'BE') && ($this->_countryInEU($countryId))) {
            $result['goto_section'] = 'vies';
            $result['allow_sections'][] = 'vies';
            $result['country_id'] = $countryId;

            $result['update_section'] = array(
                    'name' => 'vies',
                    'html' => $this->_getViesHtml()
                );

            $response->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }
}

protected function _getViesHtml()
{
    $layout = Mage::getSingleton('core/layout');
    $update = $layout->getUpdate();
    $update->load('checkout_onepage_vies');
    $layout->generateXml();
    $layout->generateBlocks();
    $output = $layout->getOutput();
    return $output;
}

以及该句柄checkout_onepage_vies的layout.xml:

and the layout.xml of that handle checkout_onepage_vies:

<checkout_onepage_vies>
    <remove name="right"/>
    <remove name="left"/>

    <block type="correctionvat/onepage_vies" name="root" output="toHtml" template="correctionvat/onepage/vies.phtml"/>
</checkout_onepage_vies>

如果我直接放置一些东西而不是尝试加载块,则它可以工作.即,如果我执行'html' => 'foobar'而不是'html' => $this->_getViesHtml(),则该步骤的内容为foobar.

If I put something directly instead of trying to load the block, it works. I.E., if, instead of 'html' => $this->_getViesHtml() I do 'html' => 'foobar', the content of the step is foobar.

因此,就像OnepageController已对输出/布局/块进行了充电一样,我尝试对其再次充电失败.
有什么事吗?

So it's like as the output/layout/blocks is already charged by the OnepageController my attempt to re-charge it again fails.
Any thaughts?

推荐答案

您面临的问题与添加的布局句柄列表有关.您需要在调用load()方法之前将其重置.另外,您还需要通过调用resetUpdates()方法来重置包含以前解析的xml的更新数组.

The problem you are facing is related to the list of added layout handles. You need to reset them before calling load() method. Also you need to reset updates array, that contain previously parsed xml by calling resetUpdates() method.

getViesHtml()最后应该看起来像这样:

You getViesHtml() should look like the following in the end:

protected function _getViesHtml()
{
    $layout = Mage::getSingleton('core/layout');

    $layout->getUpdate()
         ->resetHandles()
         ->resetUpdates()
         ->load('checkout_onepage_vies');

    $layout->generateXml()
         ->generateBlocks();

    $output = $layout->getOutput();
    return $output;
}

这篇关于将步骤添加到OPC而不进行覆盖:更新部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆