【问题标题】:add step to OPC without overriding: update section在不覆盖的情况下向 OPC 添加步骤:更新部分
【发布时间】:2013-01-21 23:53:08
【问题描述】:

所以这是one 的后续问题。
我在观察者的运输方法之前添加了一个步骤。我在获取用于更新步骤选项卡内容的 html 时遇到问题。尽管我尽了最大努力,它仍然加载运输方法步骤的 html,而不是我想要的 html。
这是观察者的代码:

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:

<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' =&gt; $this-&gt;_getViesHtml() 我做'html' =&gt; 'foobar',则步骤的内容是foobar。

所以就像输出/布局/块已经被 OnepageController 充电一样,我再次尝试重新充电失败了。
有什么想法吗?

【问题讨论】:

    标签: magento layout checkout observers


    【解决方案1】:

    您面临的问题与添加的布局句柄列表有关。您需要在调用load() 方法之前重置它们。您还需要通过调用 resetUpdates() 方法重置包含先前解析的 xml 的更新数组。

    你getViesHtml()最后应该如下所示:

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

    【讨论】:

    • thanx Ivan,再一次 :-) 我试过了,但是没有用。我刚刚在全新安装上尝试过它并且它可以工作:那么其他东西会妨碍我,我将不得不挖掘自定义模块。
    猜你喜欢
    • 2018-12-09
    • 2018-08-29
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-27
    相关资源
    最近更新 更多