I have created a module. here is my config.xml:
<config>
<modules>
<Empresam_SugarIntegration>
<version>0.1.0</version>
</Empresam_SugarIntegration>
</modules>
<frontend>
<routers>
<sugarintegration>
<use>standard</use>
<args>
<module>Empresam_SugarIntegration</module>
<frontName>sugarintegration</frontName>
</args>
</sugarintegration>
</routers>
</frontend>
<global>
<events>
<customer_register_success>
<observers>
<Empresam_SugarIntegration_customertosugar_observer>
<type>singleton</type>
<class>Empresam_SugarIntegration_Model_Observer</class>
<method>sendtosugar</method>
</Empresam_SugarIntegration_customertosugar_observer>
</observers>
</customer_register_success>
</events>
</global>
</config>
Then, my class: 'Observer.php' inside Company_Module_Model:
<?php
class Empresam_SugarIntegration_Model_Observer {
public function sendtosugar($observer) {
$customer = $observer->getEvent();
$options = array(
"location" => '...',
"uri" => 'http://www.sugarcrm.com/sugarcrm',
"trace" => 1
);
$user_auth = array(
"user_name" => '...',
"password" => MD5('...'),
"version" => '4.1'
);
$client = new SoapClient(Null, $options);
$response = $client->login($user_auth, 'test');
$session_id = $response->id;
// Mapping...
$response = $client->set_entry($session_id, 'Leads', array(
array("name" => 'first_name', "value" => $customer->getFirstName()),
array("name" => 'last_name', "value" => $customer->getLastName()),
array("name" => 'email', "value" => $customer->getEmail()),
array("name" => 'account_name', "value" => $customer->getFirstName() . $customer->getLastname())
));
Mage::log($customer->getFirstName() . $customer->getLastname());
return $this;
}
}
The event i'll looking to dispatch is this in: Mage_Customer_AccountController, function createPostAction
:
Mage::dispatchEvent('customer_register_success',
array('account_controller' => $this, 'customer' => $customer)
);
My problem is, i'm getting empty leads on SugarCRM, and from what i see from this call:
Mage::log($customer->getFirstName() . $customer->getLastname());
The strings i'm getting are empty. Any idea why?
$customer = $observer->getEvent();
should be
$customer = $observer->getCustomer(); // or getEvent()->getCustomer();