【问题标题】:Magento and salesforce integration to create opportunity as closed won inside salesfore once order become complete in magento storeMagento 和销售人员整合创造机会,一旦订单在 Magento 商店完成,就会在内部销售中获胜
【发布时间】:2012-01-04 11:59:29
【问题描述】:

我已经实现了与 magento 订单的销售团队集成。为了实现这一点,我遵循了下面给出的步骤。在用户帐户中插入 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 公司和 Salesforce 联系人。

我关注了以下链接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) 在经销商行动期间在销售人员中创建公司和联系人

$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);
                }
            }

我等待您的回复。

【问题讨论】:

  • 对客户调用 setData() 会覆盖该模型中存在的数据。尝试使用addData()
  • 谢谢@nick,我找到了解决方案。 $customer->setSalesforce_company_id($compid); $customer->setSalesforce_contact_id($contid);试试 { $customer->save(); } catch (Exception $ex1) { //Zend_Debug::dump($ex->getMessage()); }
  • 是的,没错。如果您使用->setData($key, $value) 而不是->setData(array()),您只会替换数据存储中的一项,而不是全部。使用->addData() 会做你想要的:)
  • 谢谢@Nick,这个问题解决了

标签: soap curl salesforce magento


【解决方案1】:

magento 有一个很棒的扩展,它可以为你做这一切,甚至更多:https://products.crunchyconsulting.com/crunchy-products/crunchy-magforce.html

查看帮助和文档选项卡,您甚至可以在其中找到带有用例场景的电影

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

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

【讨论】:

    猜你喜欢
    • 2015-05-02
    • 2012-11-25
    • 1970-01-01
    • 2013-10-12
    • 2014-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多