Saturday, November 20, 2010

Mageto and SalesForce Synchronization

OK, guys I am back to blogging after long time.

This blog is about synchronizing Magento inventory with Saleforce. I have briefly mentioned what is saleforce in my previous blog. You can read it from here.

The requirement was to sync Magento Inventory to Salefroce. For the first time it should synchronize all the products form Magento to Salesforce and then it should synchronize only recently added and updated products to Magento. First of all we need to understand how we can have products in Saleforce. This information is missing in my previous blog so I am explaining here.

In Saleforce you can expose your organization data in form of Custom Objects. Its like your table in your database. When you define a custom object, in salesforce it defines a table. All the attributes of that object can be defined as column of that table. For example let's consider custom object product with few attributes like Product name, quantity etc. You can imagine that Force.com platform has created a table called product and with columns product name and quantity.

Once you have defined a custom object in Salesforce you can add number of products in it. So its like you have a table called product and you have number of rows in it. This is how you can define custom objects in Salesforce. Salesforce custom objects supports various data types like NUMBER, TEXT, LIST, MULTI SELECT, FORMULA and various other. You can enforce security on it by providing crate,read,modify access to group of users or specific user.

So this was the introduction about saleforce custom object, now lets go further.

Salesforce has some APIs using which third party can access the data inside the Salesforce platform. We have used this APIs in Magento. Those APIs are nothing but a web services. You have to download WSDL file from your salesforce account and using it you can connect to salesforce from third party.

For PHP toolkit is available that you can download from SalesForce. It defines all the classes and interface required to access salesforce data form PHP applications. You have to include some files from this toolkit and wsdl file into your PHP application. Following is the simple code snippet to authenticate user to access salesforce data.

$wsdl = 'your wsdl.wsdl';
$user = 'your username';
$pass = 'your password';
$token = 'security token';

$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$client->login($user, $pass . $token);

if($client->login($user, $pass . $token))
echo "Connection Succcess";

Here security you have to generate from your salesforce account and username and password is of your salesforce account.

After successful authentication you can retrieve list of custom objects from salesfroce or you can add,update,delete custom objects in salesforce. For that various methods are defined in toolkit but we will focus on method UPSERT. This is the combination of insert and update. When you use this method, salesforce will update object its available or it will create new custom object.

For products in Magento we have to map each product attributes to custom object fields. Look at the following code snippet.

$fieldset['Title__c']=$name;
$fieldset['NAME']=$sku;
$fieldset['Unit_Weight__c']=$weight;
$fieldset['Supplier__c']=$supplier;
$fieldset['Warehouse_Location__c']=$warehouse;
$fieldset['Manufacturer__c']=$manufacturer;
$fieldset['External_Product_ID__c']=$pid;
$fieldset['Price__c']=$price;
$fieldset['Cost__c']=$cost;
$fieldset['Image_1_URL__c']=$imageurl;
$fieldset['Quantity__c']=$qty;
$sObject = new sObject();
$sObject->type = 'TDS__Product__c';
$sObject->fields = $fieldset;

$client->upsert("External_Product_ID__c", $sObject);

Here important field is External_Product_ID__c. Its like foreign key. When you want to access salesforce custom object from third party, you have to specify some field as a external which must have datatype Text,Auto number.

Using above code it will either update custom object in Salesforce with specified values if its available or it will create new one.

So this is how you can synchronize Magento products to salesforce. I hope that this blog helps you. Let me know if you have any questions for the same.





Saturday, September 25, 2010

Grid based layout on Magento product view page.
















Recently I got requirement to display product options in grid based layout on product view page for Magento. See the the image above. So the user can select particular combination from the available option. So I have started R & D on it and come up with solution that I will do it through JavaScript. Because here products were configurable products. So when product view page gets loaded, you have a JSON object with all the product options. It has all the things you want like product options,price of particular option, how many products available in options. Options may be dependent on each other like if size depends on color. This dependency is also mentioned in JSON object.

So I have used that JSON object to build this grid based layout. What you have to do is when your JSON object gets loaded, you can write JavaScript code to insert controls at runtime. In case of configurable products you have to write this code inside /product/view/type/options/configurable.phtml file. While in case of normal product where you have custom options , this code will be in options.phtml.

This is just the grid based layout on top of drop downs on product view page.Product option drop downs are hidden. When you select particular option from grid layout, the corresponding options in drop downs gets selected. So when user add product to basket product with particular options gets added in to basket.

I can not mention complete code over here.But this is the technique to design any required layout on product view page. If you need further help in this you can contact me.




Tuesday, September 14, 2010

Cloud Computing

I think everybody must have heard the word "CLOUD COMPUTING" now a days. So this blog is about little bit introduction about cloud computing and cloud computing platforms.

Wikipedia gives following definition of cloud computing.

"Cloud computing is internet-based computing, whereby shared resources, software, and information are provided to computers and other devices on demand, like the electricity grid."

That's a really good definition. Now a days cloud computing is the Buzz. Everybody is talking about it. Legends like Microsoft has invested heavily in cloud computing. So many companies are entering in to cloud computing business. CIOs/CTOs of any company want to bring Cloud Computing to their business. They are exploring options available for cloud computing platform. After cloud computing two new words are introduced.

SaaS: Software as a Service
PaaS: Platform as a Service

So what is this all about? Lets explore it in details. First of all lets talk about Cloud Computing. Why its been introduced? What was wrong with earlier approach? If you consider scenario before cloud computing , you have one server available. You use it for almost all your computing need. But the problem was CPU idle time. When server is busy with some request. It can not pay attention to other request. Also CPU is also in idle mode. What if we can utilize CPU idle time for other computing needs. But how we can do it? Then something called Virtualization is introduced. Yes this is the technology upon which cloud computing is built. My physical CPU is only one while I have more than one Virtual CPUs on top of it. Which can use my physical CPU. Virtual CPUs use almost all the real CPU cycle. Real CPU will never be in ideal mode.

So I have some hardware + software combinations which boost up my server performance. This is what is Virtualization. This is what is cloud computing. There are some large data centers in which bunch of servers are there. In those servers virtulazation is used so that each server can act as more than one server. This is the Magic of cloud computing.

Now lets talk about Cloud computing platforms available in market. There are various platforms available in market for cloud computing, but I will discuss about only two platform that I know.

As a former Microsoft .Net developer (although I am still passionate about .Net), first platform comes in my mind is Microsoft Windows Azure

Microsoft Windows Azure:

Microsoft definition for Windows Azure: "
The Windows Azure platform is a flexible cloud–computing platform that lets you focus on solving business problems and addressing customer needs."



Microsoft has invested heavily in data centers for Azure. Windows Azure is the platform using which one can develop cloud based application. If you want to develop .Net based application on local machine, you need certain things like .Net Framework,Sql Server, Windows server etc. This all provided by Windows Azure Platform in slightly different manner through App fabric, Sql Azure.

So in short It’s a platform for running Windows applications and storing their data in the cloud.

Its designed in a way that developer can develop cloud based application using various .Net supported languages like C#,VB.Net.

I will not go in more details as lots of stuff are available for windows azure on internet. Let's discuss the second cloud computing platform.

Salesforce:

Its a leading cloud platform now a days. Using it you can build your on demand internet application five time faster than any other app building platform. Its built on multi tenant architecture. It provides a very good interface to build business objects, and apps. Its service is composed of two main parts

1) appExchange Directory: market place to share your app
2) Force.com platform: This is the platform upon which applications are developed.

The language which is used to build the app is Apex Code. Force.com platform provides various features that makes easy to develop,maintain, publish and customize any app. Force.com platform have various features like multi tenancy that make its unique.

So this is the little bit introduction about cloud computing and cloud computing platforms. I will publish detailed blogs in future.