Magento-SugarCRM integration guide
This is an old revision of the document!
Magento is a new professional open-source eCommerce solution offering unprecedented flexibility and control. With Magento,never feel trapped in your eCommerce solution again.Magento eCommerce Platforms provide the scalability, flexibility and features for business growth. Magento provides feature-rich eCommerce platforms that offer merchants complete flexibility and control over the presentation, content, and functionality of their online channel. Magento is developed to take full advantage of the newest technologies available, allowing your site the maximum flexibility without sacrificing speed.
SugarCRM is the World’s Leading provider of commercial open source Customer Relationship Management (CRM) software for companies of all sizes. Over 6,000 customers and more than half a million users in 75 different languages rely on SugarCRM to execute marketing programs, grow sales, retain customers and create custom business applications. SugarCRM’s Sugar Suite easily adopts to any businesses environment by offering a more flexible, cost-effective alternative than proprietary applications. SugarCRM’s open source architecture allows companies to more easily customize and integrate customer-facing businesses processes in order to build and maintain more profitable relationships.
Magento CRM As both the products are having a strong growth in their respective areas, there are some potential business needs which needs to think of integrating these products. The sales of the ecommerce site built on Magento can be improved further by improving the CRM capabilities of Magento. Magento has basic CRM capabilities which may not cater to our need of requiring a full fledged CRM functionality. So for that we need to think of leveraging the SugarCRM functionality in Magento to improve the sales and get more business.
Following are the typical business requirements to be considered
1. A lead should be created in SugarCRM when customer registers with the Magento site.
2. Converting sales to an Opportunity in SugarCRM when the registered customer tries to add a product to shopping cart in Magento.
3. A Contact has to be created in SugarCRM taking the customer details from Magento whenever a lead has been converted to an Opportunity.
4. When Customer place an Order in Magento, the order details should be immediately reflected in SugarCRM under any module
System Requirement for integration
1. Magento 1.3 Community Edition
2. SugarCRM 6.0.0 Community Edition
3. PHP-SOAP library
4. Netbeans IDE or Eclipse IDE
5. MySQL 5.1.x
6. Apache 2.2.x
Creating webservices users in Magento
In order to access webservices of Magento from outside of the application. You need to create a user and assign a role to it. This can be done under the Admin page of Magento as given below. Navigate to Sytem → WebServices→Uers
Navigate to Sytem → WebServices → Roles
Again Navigate back to System → Web Services→ Users and Assign the User Role which we have given above to the Webservice user.
Creating webservices users in SugarCRM
In order to access webservices of SugarCRM from outside of any application. We need to create a user and assign roles. With this user credentials we can get a session in SugarCRM and we can use this session to perform all the service related operations in SugarCRM.
Before Creating new User you need to go to Password management page to disable the Auto generated password function so that the user is allowed to enter their own password. This can be done by navigating to Password Management page under Administration. Disable the tab as shown below
Now Create a new user under SugarCRM. For this Navigate to SugarCRM Administration page and Click on User Management. Click on Create New User
Modifying AccountController.php file
In our business scenario of creating a lead , Whenever a new user registers in Magento site a lead is created under SugarCRM. For this to be achieved you need to Modify the AccountController.php file. This file is available under
Open the file and you can see all the customer related functions. Check for “CreatePostAction()” Function. This function is called when a customer click on register button after providing the details under the New Account Registration page of Magento.
When this function is called we must write the code block to call SugarCRM services and create a new lead by passing the customer related information from Magento to SugarCRM.
A session can be created under SugarCRM by calling the Login soap method as given below
The above code is a generic code which can be passed for opening a SugarCRM service connection and get the session id. This session id can be passed as one of the parameter in the methods of SugarCRM.
For example in AccountContoller.php file for passing the customer information from Magento to sugarCRM , it can done by adding the following lines next to the above lines under CreatePostAction() function.
The set_entry method is the generic method available in SugarCRM which can be used and we need to pass the corresponding module name as a parameter along with session_id as another parameter in order to create the entry under SugarCRM.
Similarly in order to convert a lead to opportunity, we need to edit the CartContoller.php file. This file is available under
There is a method called addAction() , This method is invoked whenever a customer click on Add to Cart button to add a product to the shopping cart. So we will utilize this method in getting the cart information , product information and customer information and pass it on the details to the SugarCRM in order to convert the existing lead to an opportunity. Also these informations are user in creating a Contact in SugarCRM after creating the opportunity in SugarCRM.
Fetching order status from Magento
A Note on SugarCRM Schedulers
Schedulers are nothing but the jobs which will be automated and be running under SugarCRM in a specified regular interval. In order to schedule a job in SugarCRM we need to get the cront tab working. This can be achieved by editing the cron tab and adding the following entry as shown below
Open the terminal and login as root
and type crontab -e
this will open a file to edit
type the following lines and save it.
After cd you need to specify the path of your sugarcrm installation.Now login into the SugarCRM administration page and click on Scheduler. Click on Create Scheduler and provide the job name and leave the Job dropdown empty and type the path of the file name where the scheduler source code resides in the OR field. Specify the interval and click save .
You can verify whether the job has been completed or not by viewing the scheduler job log as given below.
Troubleshooting the integration
Class not found exception
PHP Fatal error: Class ‘SoapClient’ not found in /path/to/filename.php
This error comes when php missing the SOAP extension. This is necessary to call api methods using SOAP. So we need to install the extension.
Automatic installation can be done by opening a terminal and type
sudo yum install php-soap. This command will resolve the dependency and install php-soap on your server. You need to restart Apache to apply the changes. However the above method will work only if you have direct internet connection. If you are on proxy you may need to manually download the corresponding rpm and install it. The corresponding rpm file should look like the one mentioned below
Open the terminal and type
sudo rpm -ivh path/to/php-soap-5.2.9-2.fc11.i586.rpm . This will install the rpm and you need to restart the apache for the changes to take effect.
Uncaught SoapFault exception
You may encounter an error similar to the one given below when trying to access a web service in Magento. [error] [client 172.17.198.61] PHP Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing Schema: can’t import schema from ‘http://schemas.xmlsoap.org/soap/encoding/’ in /var/www/html/magentoservice/customer.php
Magento cant able to import schema from the specified location . The reason is due to internet connection proxy does not allow you to communicate and check the schema on the website. Or it might be due to other connectivity issues.
A simple solution for this problem is
Go to app/code/core/Mage/Api/wsdl.xml
comment out the line
Now Magento webservices can be accessible as it will no more complain of this error.
You may sometimes encounter an error when you are trying to access an array in the following ways
Error : Cannot use object of type stdClass as array
Trying to print or call an array element directly using the below method may create this problem. For example
$ret[entry_list][’id’] Instead it can be called as below $ret→entry_list→id
Future integration capabilities
This guide explains you the basic integration of creating lead, opportunity and contacts under certain conditions triggered in magento. Practically there are many situations where a lead, opportunity, sales and contacts can be created. Following are some of the important business situations where we can consider
1. Notify Abandoned cart from Magento to the sales person of the sugarCRM so that he can take necessary actions in boosting the sales of the company by following the corresponding user. 2. Notify the “Active or Online customers” in the Magento to the sales person of SugarCRM , so that a promoting a product can be done. Or it will become easy for the sales person to track the customer and assist the customer in buying a product. 3. Notify the sales person of SugarCRM about the popular searches , tags, most viewed products, most viewed pages, most selling products and many more information about the product and services the customer is willing to use and buy. This information is useful for the sales person for email marketing and launching a campaign management and promoting the products to increase the sales. 4. Notify the sales person about the list of products added to the cart by all the customers in Magento. This can be useful to keep track of future buying prospective of the product. Also it can be useful to sell the product by providing some discount or assisting the customer to buy the product added in the cart.
The above guide expalains you about the kickstart hints in getting the webservices of both Magento and SugarCRM and calling the one from another according to the business needs. The business needs explained above are just a few and it can be extended further. Also the methods explained above is not as much generic as it should be. So Going forward we must make it generic by providing a plugin in SugarCRM in authenticating the Magento webservice hostname and user credentials and then allowing to utilize the API methods and services by displaying the available methods to the SugarCRM users. Same manner, a plugin at Magento end can authenticate the SugarCRM user by providing the hostname and user credentials allowing the user to utilize the webservices and methods which should be displayed to the user after authentication.
Also more importantly the plugin should be available as a community plugin and not a commercial one. We are working on the plugin.
Vignesh Sabapathi CEG - Opensource team Tata Consultancy Services Mail to : firstname.lastname@example.org