Magento 1.9:使用事件sales_order_place_after检出页面不会重定向到成功页面

时间:2015-02-03 13:48:02

标签: php magento

我是magento& amp;的初学者尝试开发一个模块,用于在发出任何订单时发送消息,使用此模块我可以生成(发送/回收)消息但是检出页面不会重定向到成功页面 我也使用了以下活动
sales_order_place_before checkout_type_onepage_save_order &的 checkout_type_onepage_save_order_after
因为我的主题使用一页结账,但结果相同

etc/config.php

<?xml version="1.0"?>
<config>
    <modules>
        <Abc_Sms>
            <version>0.0.1</version>
        </Abc_Sms>
    </modules>
    <global>
        <models>
            <abc_sms>
                <class>Abc_Sms_Model</class>
            </abc_sms>
        </models>
         <events>
            <sales_order_place_after><!-- observe the event -->
                <observers>
                    <abc_sms>
                        <class>abc_sms/observer</class>
                        <method>newCheckout</method>
                    </abc_sms>
                </observers>
            </sales_order_place_after>
        </events>
    </global>
</config>

型号/ Oberver.php

<?php 
class Abc_Sms_Model_Observer {
    public function newCheckout($observer) {
$order_id = $observer->getEvent()->getOrder()->getId() ;
$order_no = $observer->getEvent()->getOrder()->getIncrementId() ;
$order = Mage::getModel("sales/order")->load($order_id);
$billing_address = $order->getBillingAddress(); 
$billing_telephone = $billing_address->getTelephone();
$msg = "Thank you for your purchase! Your order # is: ".$order_no;
//sms api start
$ch = curl_init();
$user="****@gmail.com:****";
$receipientno = $billing_telephone; 
$senderID="TEST SMS"; 
$msgtxt = $msg; 
curl_setopt($ch,CURLOPT_URL,  "http://api.mVaayoo.com/mvaayooapi/MessageCompose");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$user&senderID=$senderID&receipientno=$receipientno&msgtxt=$msgtxt");
$buffer = curl_exec($ch);
if(empty ($buffer))
{ echo " buffer is empty "; }
else
{ echo $buffer; } 
curl_close($ch);
//sms api end

    }    
}
?>

先谢谢你的帮助

3 个答案:

答案 0 :(得分:1)

试试这个:

将此添加为newCheckout功能的最后一行

return $this;

答案 1 :(得分:0)

试试这个:

按F12并使用防火虫打开控制台,您可以看到结果。

答案 2 :(得分:0)

您可以提出如下请求:

$client = new Varien_Http_Client('http://www.example.com/');
$client->setMethod(Varien_Http_Client::POST);
$client->setParameterPost('param1', $param1);
$client->setParameterPost('param2', $param2);
//more parameters
try{
    $response = $client->request();
    if ($response->isSuccessful()) {
        echo $response->getBody();
        return $this; // for redirection after save order event
    }
} catch (Exception $e) {
}

注意:请勿在响应成功后忘记实施return $this

参考:https://stackoverflow.com/a/8151632/6041121