2013-04-03 83 views
0

我在Magento新的。其實我想Magento的糖CRM 我休耕本指南http://www.magentocommerce.com/wiki/3_-_store_setup_and_management/magento-sugarcrm_integration_guide的Magento和糖CRM的整合問題

,但我無法得到客戶姓,名和電子郵件整合,通過這段代碼。

當一個客戶在magento中創建一個賬戶時,一個潛在客戶在CRM中創建但空的領域。 我怎樣才能得到客戶的名字姓氏和電子郵件。

感謝提前分配 這是我的代碼,但仍然無法獲取客戶信息。 公共職能createPostAction() {

$session = $this->_getSession(); 




    if ($session->isLoggedIn()) { 
     $this->_redirect('*/*/'); 
     return; 
    } 
    $session->setEscapeMessages(true); // prevent XSS injection in user input 
    if ($this->getRequest()->isPost()) { 
     $errors = array(); 

     if (!$customer = Mage::registry('current_customer')) { 
      $customer = Mage::getModel('customer/customer')->setId(null); 
     } 

     /* @var $customerForm Mage_Customer_Model_Form */ 
     $customerForm= Mage::getModel('customer/form'); 
     $customerForm->setFormCode('customer_account_create') 
      ->setEntity($customer); 

     $customerData= $customerForm->extractData($this->getRequest()); 

     if ($this->getRequest()->getParam('is_subscribed', false)) { 
      $customer->setIsSubscribed(1); 
     } 


     /** 
     * Initialize customer group id 
     */ 
     $customer->getGroupId(); 

     if ($this->getRequest()->getPost('create_address')) { 
      /* @var $address Mage_Customer_Model_Address */ 
      $address = Mage::getModel('customer/address'); 
      /* @var $addressForm Mage_Customer_Model_Form */ 
      $addressForm = Mage::getModel('customer/form'); 
      $addressForm->setFormCode('customer_register_address') 
       ->setEntity($address); 

      $addressData = $addressForm->extractData($this->getRequest(), 'address', false); 
      $addressErrors = $addressForm->validateData($addressData); 
      if ($addressErrors === true) { 
       $address->setId(null) 
        ->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false)) 
        ->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false)); 
       $addressForm->compactData($addressData); 
       $customer->addAddress($address); 

       $addressErrors = $address->validate(); 
       if (is_array($addressErrors)) { 
        $errors = array_merge($errors, $addressErrors); 
       } 
      } else { 
       $errors = array_merge($errors, $addressErrors); 
      } 




     } 
     foreach (Mage::getConfig()->getFieldset('customer_account') as $code=>$node) { 
       if ($node->is('create') && isset($data[$code])) { 
        switch($code) { 
         case 'email': 
          $data[$code] = trim($data[$code]); 
          echo $email = $data[$code]; 
         break; 
         case 'firstname': 
          echo $firstname = $data[$code]; 
         break; 
         case 'lastname': 
          echo $lastname = $data[$code]; 
         break; 
        }    
       } 
      } 
     $options= array("location"=>'http://addres.com/soap.php',"uri"=>'http://addres.com/',"trace"=>1); 
     $user_auth=array ("user_name"=>'name', 
     "password"=>md5('password'), 
     "version"=>'6.2.4' 
     ); 


     $client=new SoapClient(Null,$options); 
     $response=$client->login($user_auth,'name'); 
     $session_id=$response->id; 

     $response=$client->set_entry($session_id,'Leads',array(
     array("name"=>'first_name',"value"=>$firstname), 
     array("name"=>'last_name',"value"=>$lastname), 
     array("name"=>'email',"value"=>$email)));    


     try { 
      $customerErrors = $customerForm->validateData($customerData); 
      if ($customerErrors !== true) { 
       $errors = array_merge($customerErrors, $errors); 
      } else { 
       $customerForm->compactData($customerData); 
       $customer->setPassword($this->getRequest()->getPost('password')); 
       $customer->setConfirmation($this->getRequest()->getPost('confirmation')); 
       $customerErrors = $customer->validate(); 
       if (is_array($customerErrors)) { 
        $errors = array_merge($customerErrors, $errors); 
       } 
      } 

      $validationResult = count($errors) == 0; 

      if (true === $validationResult) { 
       $customer->save(); 



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

       if ($customer->isConfirmationRequired()) { 
        $customer->sendNewAccountEmail(
         'confirmation', 
         $session->getBeforeAuthUrl(), 
         Mage::app()->getStore()->getId() 
        ); 
        $session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail()))); 
        $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true))); 
        return; 
       } else { 
        $session->setCustomerAsLoggedIn($customer); 
        $url = $this->_welcomeCustomer($customer); 
        $this->_redirectSuccess($url); 
        return; 
       } 
      } else { 
       $session->setCustomerFormData($this->getRequest()->getPost()); 
       if (is_array($errors)) { 
        foreach ($errors as $errorMessage) { 
         $session->addError($errorMessage); 
        } 
       } else { 
        $session->addError($this->__('Invalid customer data')); 
       } 
      } 
     } catch (Mage_Core_Exception $e) { 
      $session->setCustomerFormData($this->getRequest()->getPost()); 
      if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) { 
       $url = Mage::getUrl('customer/account/forgotpassword'); 
       $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url); 
       $session->setEscapeMessages(false); 
      } else { 
       $message = $e->getMessage(); 
      } 
      $session->addError($message); 
     } catch (Exception $e) { 
      $session->setCustomerFormData($this->getRequest()->getPost()) 
       ->addException($e, $this->__('Cannot save the customer.')); 
     } 
    } 


    $this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true))); 



} 
+2

請標記爲正確答案或添加自己的答案並標記爲正確的。 – Kamal

回答

0

您可以覆蓋Mage_Customer_AccountController和改變createPostAction中,你可以得到使用下面的代碼的客戶領域:

 

    foreach (Mage::getConfig()->getFieldset('customer_account') as $code=>$node) { 
     if ($node->is('create') && isset($data[$code])) { 
      switch($code) { 
       case 'email': 
        $data[$code] = trim($data[$code]); 
        $email = $data[$code]; 
       break; 
       case 'firstname': 
        $firstname = $data[$code]; 
       break; 
       case 'lastname': 
        $lastname = $data[$code]; 
       break; 
      }    
     } 
    } 

您可以通過衍生變量到你的方法來處理進一步。

+0

感謝您的回覆,這是我的功能。將你的代碼添加到函數中,但仍然無法獲取並傳遞客戶信息 –

+0

您是否檢查過$ email,$ firstname和$ lastname是否包含所需的值? – Kamal

0

您是否嘗試過使用

$this->getRequest()->getPost() 

我知道,Magento的接觸形式,它產生一個數組,看起來像這樣讓所有的POST數據 - 可能是創建一個帳戶非常相似。

(
    [name] => test 
    [email] => [email protected]com 
    [telephone] => 
    [comment] => test 
    [captcha] => Array 
     (
      [contact_form] => tttt 
     ) 

    [hideit] => 
) 
0

這爲我工作:

// Pass customer information from Magento to SugarCRM 
$customer_info = array(array('name' => 'first_name', 'value' => $this->getRequest()->getPost('firstname')), 
        array('name' => 'last_name', 'value' => $this->getRequest()->getPost('lastname')), 
        array('name' => 'email2', 'value' => $this->getRequest()->getPost('email'))); 

$response = $client->set_entry($session_id, 'Leads', $customer_info); 
0

相反overidding控制器文件,你也可以使用Magento的事件處理的。

customer_save_after是在新客戶註冊後被調用的事件。

http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/events

<events> 
    <customer_save_after> 
     <observers> 
      <yournamespace_yourmodule_order_observer> 
       <type>singleton</type> 
       <class>Yournamespace_Yourmodule_Model_Observer</class> 
       <method>sendemail</method> 
      </yournamespace_yourmodule_order_observer> 
     </observers> 
    </customer_save_after> 
</events> 

這裏是被包含在你的模塊配置文件中的文件

現在創建一個名稱Observer.php模型中的文件夾中的文件,示例代碼,並把下面的代碼:

<?php 
class Yournamespace_Yourmodule_Model_Observer 
{ 
    public function __construct() 
    { 
     //Just constrcutor for fun :-) 
    } 

    public function sendemail($observer) 
    { 
     //$observer contains the object returns in the event. 
     $event = $observer->getEvent(); 
     $order = $event->getOrder(); 
     mage::log($order->getId()); 
     //Write code to send email 
     return $this; 
    } 

}

現在,只要你的Wi將從您的magento商店的任何地方下訂單,您的函數sendemail將被執行。