user1773888
user1773888

Reputation: 11

Magento 1.6.2 event observer doesnt work

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.

Upvotes: 1

Views: 595

Answers (2)

Guerra
Guerra

Reputation: 2790

Your config.xml is wrong,

<global>
<models>
    <test_shipping>
        <class>Test_Shipping_Model</class>
    </test_shipping>
</models>   
</global>

 <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>

Upvotes: -1

Jscti
Jscti

Reputation: 14440

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

Upvotes: 0

Related Questions