1

I need to update the customers data from magento to ERP.

whenever customer going to check out the order,it ask for Guest or Register and checkout. when we select the Register and check out option,it ask for billing information.after filling these details it ask for shipping details,for instance if we select billing address as shipping address,then ask for shipping method(for instance we select free shipping),then ask for payment method(for instance,if we select cash on deliver),after that order review.

how can i send these customer information and order details to our ERP,using event Observer? (iam new to magento,if anyone have idea pls share here).

these files i created,Is there any mistakes these files,please correct here?

Observer.php[app/code/local/Wli/SalesOrderafter/Model]

<?php

class Wli_SalesOrderafter_Model_Observer {

    public function SalesOrderafter(Varien_Event_Observer $observer) {

        $event = $observer->getEvent();


        $order = $order->getBillingAddress()->getEmail();

        echo "email:$order";


        exit();
    }

}

config.xml [app/code/local/Wli/SalesOrderafter/etc]

<config>
  <modules>
    <Wli_SalesOrderafter>
      <version>0.1.0</version>
    </Wli_SalesOrderafter>
  </modules>
  <global>
  <events>
    <sales_order_place_after>
      <observers>
        <Wli_SalesOrderafter_sales_order_place_after>
          <type>singleton</type>
          <class>Wli_SalesOrderafter_Model_Observer</class>
          <method>SalesOrderafter</method>
        </Wli_SalesOrderafter_sales_order_place_after>
     </observers>
    </sales_order_place_after>
  </events>
  </global>
</config>

Wli_SalesOrderafter.xml[app/etc/modules]

<?xml version="1.0"?>
<config>
  <modules>
    <Wli_SalesOrderafter>
      <active>true</active>
     <codePool>local</codePool>
    </Wli_SalesOrderafter>
  </modules>
</config>
2

You can use following events:

sales_order_place_before
sales_order_place_after
checkout_onepage_controller_success_action
checkout_multishipping_controller_success_action

In your case, you would like to get info after successful order creation. In that case you should use sales_order_place_after.

Sending data to your ERP would completely depend upon ERP's system requirements. You will need to understand how they can receive data or in what format.

You can check all events here: https://www.nicksays.co.uk/magento-events-cheat-sheet-1-9/

Update

your observer function:

public function SalesOrderafter(Varien_Event_Observer $observer)
{   $order = $observer->getEvent()->getOrder(); 
    $email = $order->getBillingAddress()->getEmail(); 
    //echo "email:$order"; exit(); 

    Mage::log($email . " - order placed", null, 'custom_log.log');
}

This should create a file called custom_log.log in /var/log folder on order submit.

Update 2

Your event should be this

<events>
    <sales_order_place_before>
      <observers>
        <unique_name>
          <type>singleton</type>
          <class>Wli_SalesOrderafter_Model_Observer</class>
          <method>SalesOrderafter</method>
        </unique_name>
     </observers>
    </sales_order_place_before>
  </events>
  • using sales_order_place_after.Can i get customer data? – Rizwan Sep 2 '15 at 6:58
  • You can get everything that customer has entered. – Adarsh Khatri Sep 2 '15 at 6:59
  • when am using sales_order_place_after...it shows empty page – Rizwan Sep 3 '15 at 7:05
  • you can see the code here,which i was using magento.stackexchange.com/questions/80645/… – Rizwan Sep 3 '15 at 7:07
  • If customer is not register then calling getCustomerEmail() will not return anything. You have to call $order->getBillingAddress()->getEmail(); And what do you mean by empty page? – Adarsh Khatri Sep 3 '15 at 7:16
2

Your question is quite broad so no ready-to-go answer but a list of what you need to know / check in order to build a module like this.

If you run into specific problems, feel free to post another question.

  • How to build a custom module in Magento, check this and this but remember, you only need a model in your case.
  • Check this tutorial about observers.
  • The events: https://www.nicksays.co.uk/magento-events-cheat-sheet-1-9/
  • To check what data is in an event, go to the event in the code. It'll look somewhat like Mage::dispatchEvent('[event]', array('order' => $order)); which means you can get the order in your observer via $observer->getOrder();
  • And finally, read the documentation from the ERP on how to send the data to them.

But just to give you a little extra info, you're looking for the sales_order_place_after event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.