dongshanyan0322 2012-10-25 11:15
浏览 51

Magento 1.6.2事件观察员不起作用

I am trying to implement observer in my module (app/code/community/Test/Shipping).

My files are: app/code/community/Test/Shipping/etc/config.xml global part only

<global>
    <models>
        <test_shipping>
            <class>Test_Shipping_Model</class>
        </test_shipping>
    </models>
    <events>
        <checkout_type_onepage_save_order_after>
            <observers>
                <Test_Shipping_Observer>
                    <type>singleton</type>
                    <class>test_shipping/observer</class>
                    <method>checkout_type_onepage_save_order_after</method>
                </Test_Shipping_Observer>
            </observers>
        </checkout_type_onepage_save_order_after>
    </events>
</global>

app/code/community/Test/Shipping/Model/Observer.php i replaced some values in curl but its tested and works with correct values.

<?php

class Test_Shipping_Model_Observer {

public function checkout_type_onepage_save_order_after(Varien_Event_Observer $observer) {
    $requests = array(
        "username" => "test",
        "password" => "test",
        "environment" => "development",
        "action" => "ship",
        "service_id" => "1"
    );
    $url = "";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requests));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($ch);
    curl_close($ch);
}

}

app/etc/modules/Test_Shipping.xml with starting and ending config tags to, couldnt get them in my code example.

<modules>
    <Test_Shipping>
        <active>true</active>
        <codePool>community</codePool>
    </Test_Shipping>
</modules>

But observer doens't work, can anyone help me please? Is there a way to check if method is called so i would know that observer works but my curl doesnt.

  • 写回答

2条回答 默认 最新

  • douyi9705 2012-10-25 11:33
    关注

    Can you show us the <config>/<modules> part of your config.xml ?

    Anyways, apart from the function name of your observer that is non-magento friendly, it should work (you should call like executeCurlAfterOrderSave())

    To be sure it is called :

    • Activate the Log functionnality in Backoffice (Menu System / Configuration / Developer / Log Settings

    • add a Mage::log('event just dispatched'); just after the

      Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$this->getQuote()));

    that is called in the Mage_Checkout_Model_Type_Onepage (or Mage_Checkout_Model_Cart_Api is you're using the API) note: revert this change that's only for debugging purpose as you must not modify core files.

    • add a Mage::log('even should be captured here'); in the beginning of your Observer method

    • test your code and look at the var/log folder to see if what happened (what has been logged)

    Good luck

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大