在Magento中停止从事件观察者停止检出的正确方法是什么? [英] What is the correct way to stop a checkout from an event observer in Magento?

查看:90
本文介绍了在Magento中停止从事件观察者停止检出的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在检查checkout_controller_onepage_save_shipping_method事件期间正在验证运输报价,如果验证失败,我想让用户返回选择运输方法,但我还想显示一条消息,说明为什么失败. Magento有内置的方法吗?

I am verifying shipping quotes during the event checkout_controller_onepage_save_shipping_method and if the verification fails i want to send the user back to shipping method selection but I would also like to display a message saying why it failed. Does Magento have a way of doing this built in?

我已经在验证数据,我只是缺少重定向到运输方式和显示消息的方式.

I am already verifying the data I just lack the redirect to shipping methods and way to display a message.

推荐答案

艾伦·斯托姆(Alan Storm)的答案一如既往地富有启发性.但是在这种情况下,一页结帐主要是AJAX,它会忽略会话错误消息,直到离开结帐页,您才会看到它.

Alan Storm's answer is, as ever, informative and enlightening. But in this situation the onepage checkout is mostly AJAX which ignores the session error message, you won't see it until leaving the checkout page.

saveShippingMethodAction中有以下行:

$result = $this->getOnepage()->saveShippingMethod($data);

...然后$ result是JSON编码的.如果您覆盖Mage_Checkout_Model_Type_Onepage::saveShippingMethod来执行检查然后控制返回的内容,则可以插入一条错误消息,该错误消息将返回到浏览器并在弹出窗口中显示给用户.

...and then $result is JSON encoded. If you override Mage_Checkout_Model_Type_Onepage::saveShippingMethod to perform your check then control what is returned you can insert an error message that will be returned to the browser and shown to the user in a popup.

您的替代项可能看起来像这样:

Your override might look something like this:

public function saveShippingMethod($shippingMethod)
{
    if ($this->doesntApplyHere()) {
        return array('error' => -1, 'message' => $this->_helper->__('Explain the problem here.'));
    }
    return parent::saveShippingMethod($shippingMethod);
}

这篇关于在Magento中停止从事件观察者停止检出的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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