一旦订单在magento商店完成,Magento和salesforce整合就可以创造机会,因为已经完成了销售

时间:2012-01-04 11:59:30

标签: soap curl salesforce magento

我实施了与magento订单的salesforce集成。为实现这一目标,我遵循了下面给出的步骤。在用户帐户中插入salesforce_company_id和salesforce_contact_id时,我在第4步做错了。

1)在管理员中添加自定义选项“已关闭”以完成任何订单。

public function massCompleteAction(){
$orderIds = $this->getRequest()->getPost('order_ids', array());
$countCompleteOrder = 0;
foreach ($orderIds as $orderId) {
$order = Mage::getModel('sales/order')->load($orderId);
if ($order->canComplete()) {
$order->complete()->save();
$countCompleteOrder++;
}
}
if ($countCompleteOrder>0) {
$this->_getSession()->addSuccess($this->__('%s order(s) successfully put on complete', $countCompleteOrder));
}else {
// selected orders is not available for hold
}
$this->_redirect('*/*/');
} 

2)为用户帐户,Salesforce Company和Salesforce Contact添加两个附加字段。

我已关注以下链接http://www.excellencemagentoblog.com/customer-registration-fields-magento1-6

3)创建自定义转销商注册表单,该表单将创建一个简单的magento用户

public function createResellerAction()
{

$params = $this->getRequest()->getParams();
  $customer = Mage::getModel('customer/customer');
  $password = $params["password"];
  $email = $params["email"];
  $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
  $customer->loadByEmail($email);
 //Zend_Debug::dump($customer->debug()); exit;
if(!$customer->getId()) {
$customer->setEmail($email);
$customer->setFirstname($params["firstname"]);
$customer->setLastname($params["lastname"]);
$customer->setPassword($password);

 try {
$customer->save();
$customer->setConfirmation(null);
$customer->save();
Mage::getSingleton('customer/session')->loginById($customer->getId());
   }
   catch (Exception $ex) {
//Zend_Debug::dump($ex->getMessage());
}

$_custom_address = array (
'firstname' => $params["firstname"],
'lastname' => $params["lastname"],
'street' => array (
    '0' => $params["add1"],
    '1' => $params["add2"],
),

'city' => $params["city"],
'region_id' => '',
'region' => '',
'postcode' => $params["zipcode"],
'country_id' => '', /* Croatia */
'telephone' => $params["phone"],
);

$customAddress = Mage::getModel('customer/address');
$customAddress->setData($_custom_address)
        ->setCustomerId($customer->getId())
        ->setIsDefaultBilling('1')
        ->setIsDefaultShipping('1')
        ->setSaveInAddressBook('1');

    try {
$customAddress->save();
        }
    catch (Exception $ex) {
//Zend_Debug::dump($ex->getMessage());
    } 

4)在转销商行动期间在salesforce中创建公司和联系

$sObject1 = new stdclass();
            $sObject1->Name = $params["company"];    
            $createResponse1 = $mySforceConnection->create(array($sObject1), 'Account');
            foreach ($createResponse1 as $createResult1) {
                $compid = $createResult1->id;
                 }

            $sObject3 = new stdclass();
            $sObject3->FirstName = $params["firstname"];
            $sObject3->LastName = $params["lastname"];
            $sObject3->Email = $params["email"];
            $sObject3->AccountId = $compid;  
            $createResponse2 = $mySforceConnection->create(array($sObject3), 'Contact');
            foreach ($createResponse2 as $createResult2) {
                $contid = $createResult2->id;
                 }
             $saledata = array (
            'salesforce_company_id' => $compid,
             'salesforce_contact_id' => $contid,
             );
             $customersale = Mage::getModel('customer/customer');
            $customersale->setWebsiteId(Mage::app()->getWebsite()->getId());
  $customersale->loadByEmail($email);
 //Zend_Debug::dump($customer->debug()); exit;
if($customersale->getId()) {
              $customersale->setData($saledata);
                   try {
                    $customersale->save();
                     $customersale->setConfirmation(null);
                     $customersale->save();
                  }
                catch (Exception $ex) {
                 $message = $this->__($customer);
                //Zend_Debug::dump($ex->getMessage());
                Mage::getSingleton('core/session')->addError($message);
                }
            }

请在第4步

中查看我错误的代码
$saledata = array (
            'salesforce_company_id' => $compid,
             'salesforce_contact_id' => $contid,
             );
             $customersale = Mage::getModel('customer/customer');
            $customersale->setWebsiteId(Mage::app()->getWebsite()->getId());
  $customersale->loadByEmail($email);
 //Zend_Debug::dump($customer->debug()); exit;
if($customersale->getId()) {
              $customersale->setData($saledata);
                   try {
                    $customersale->save();
                     $customersale->setConfirmation(null);
                     $customersale->save();
                  }
                catch (Exception $ex) {
                 $message = $this->__($customer);
                //Zend_Debug::dump($ex->getMessage());
                Mage::getSingleton('core/session')->addError($message);
                }
            }

我等待你的回复。

1 个答案:

答案 0 :(得分:0)

magento有一个很棒的扩展,它可以为您提供更多功能,甚至更多:https://products.crunchyconsulting.com/crunchy-products/crunchy-magforce.html

看看帮助& docs选项卡,您可以在其中找到包含用例场景的电影

https://www.youtube.com/watch?v=TjxvjGcAGqY

https://www.youtube.com/watch?v=cmf4Ksv3uRM