1

我创建了一个模块。这是我的 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>

然后,我的班级:Company_Module_Model 中的“Observer.php”:

<?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;
    }

}

我要调度的事件是:Mage_Customer_AccountController,函数createPostAction

 Mage::dispatchEvent('customer_register_success',
                        array('account_controller' => $this, 'customer' => $customer)
 );

我的问题是,我在 SugarCRM 上得到了空的线索,从这个电话中我看到:

Mage::log($customer->getFirstName() . $customer->getLastname());

我得到的字符串是空的。知道为什么吗?

4

1 回答 1

0
$customer = $observer->getEvent();

应该

$customer = $observer->getCustomer(); // or getEvent()->getCustomer();
于 2013-04-12T17:17:30.320 回答