相关疑难解决方法(0)

在Observer方法中,如何告诉Magento在调度事件后不处理代码

我在结帐时有一些代码,我在会话中设置了一个密钥,如果在结帐时将该密钥设置为false,我需要将它们发送回结算页面.我有它的代码,但我也不能拥有通常在观察者之后运行的任何代码,因为它会调用第三方服务并因为会话中缺少此密钥而返回错误

这是我的代码,我有我想要的一切,但我需要立即发生的响应,并且在调度的事件行被发送后只发送回发送回浏览器的响应.

public function checkForOrdKey(Varien_Event_Observer $observer)
    {
        $controllerAction = $observer->getControllerAction();
        $request = $controllerAction->getRequest();
        $controllerName = $request->getControllerName();
        $stepData = $this->_getCheckoutSession()->getStepData();
        $ordKeyRemoved = $this->_getCheckoutSession()->getOrdKeyRemoved();
        // if it is the checkout onepage controller or inventory controller don't do anything
        if (isset($controllerName) && $controllerName === "onepage" && $stepData['shipping']['complete'] && $ordKeyRemoved) {
            $this->_getCheckoutSession()->setStepData('shipping', 'complete', false);
            $result['goto_section'] = 'billing';
            Mage::app()->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
            $this->_getCheckoutSession()->setOrdKeyRemoved(false);

        }
    }
Run Code Online (Sandbox Code Playgroud)

php observers magento

13
推荐指数
1
解决办法
1万
查看次数

来自Observer的Magento Redirect始终有效

我无法从观察者那里在Magento中创建一个工作重定向.

据我所知,有许多事件得到了响应对象(在$observer对象中).另一种方法是使用类似的东西

Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
Run Code Online (Sandbox Code Playgroud)

正如伟大的艾伦风暴在这里提到的/sf/answers/331114031/.

不幸的是,这对我不起作用,即使我这样添加sendResponse():

Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'))->sendResponse();
Run Code Online (Sandbox Code Playgroud)

例如:

我想阻止一些电子邮件地址订阅时事通讯.因此我为newsletter_subscriber_save_before事件创建了一个观察者.

在我的观察者方法中,我检查了一些案例,如果它们触发我想阻止保存新闻稿订阅.我的计划是添加这样的错误:

Mage::getSingleton('checkout/session')->addError('Email is spam!');
Run Code Online (Sandbox Code Playgroud)

然后让当前页面重新加载(显示错误消息),如上所示重定向(checkout/cart在示例中只是为了看它确实有效).

不幸的是重定向不起作用.为什么sendResponse在这种情况下不发送响应?

感谢帮助 :)

php events newsletter magento

7
推荐指数
3
解决办法
2万
查看次数

标签 统计

magento ×2

php ×2

events ×1

newsletter ×1

observers ×1