This section explains techniques for adding from simple to sophisticated KonaKart functionality to web sites. Code examples are provided to add KonaKart shopping cart functionality to a JSP website.
There's a growing trend for owners of information-only websites to add shopping cart features to capitalize on the extraordinary growth of eCommerce around the globe.
This simple example shows how to add shopping cart functionality to a JSP website using a zero-cost, loosely-coupled, SOAP web services integration with KonaKart.
So what is the best way to add shopping cart functionality to a website?
One solution would be to code a complete shopping cart solution from scratch and merge this into your website. This has the potential to provide a good solution but would be a huge investment in time if anything but the most trivial cart was required. Before undertaking this development you should be aware of the extensive functionality provided by KonaKart which would be costly to reproduce. For example, there's customer management, catalogue management, promotions, payment gateways, shipping gateways, and some complicated tax calculations that depend on the location of the shopper and the store.
A quicker and less-risky solution is to integrate with KonaKart, deriving all the benefits of a sophisticated shopping cart solution without requiring a costly software change to your current site. With imaginative use of stylesheets it's straightforward for a creative web-designer to make the two sites have similar look and feel to give the impression of a more-seamless integration.
Loose coupling of your current site and the shopping cart site provides a painless migration of an information-only site to an eCommerce-enabled site with minimal effort. You could take this loose-coupling to extremes and introduce a single link from your existing store to your on-line shop and this is a solution many would be content with. However, with very little effort, you can do much better in bringing your site to life with live product information that will encourage your visitors to buy.
The power and simplicity of SOAP interfaces in KonaKart enables this loosely-coupled integration allowing you to maintain your information-only site and online shop completely independently and potentially running with different technologies.
Being SOAP, the simple example described below could have been written in any language that supports SOAP calls, but JSPs have been chosen in this case:
Let us imagine, for the sake of this article, that we have a "Movie Review" website that looks like this:
OK, it's a simple example! Let's say the site contains little more than reviews of the latest movies but has attracted a lively community who might even be contributing with their own reviews.
A natural extension of this website would be to offer DVDs for sale, so rather than build all that shopping cart functionality into Movie Review, we'll integrate with an external site.
The first step would be to add three simple links to the site to take the user directly to his current shopping cart, his account details (to review old orders), and directly to the checkout page. These are simple HTML links which do not require SOAP:
The links were added at the top right:
Now let's use the power of SOAP to access some information about the DVDs for sale and tempt the visitors of Movie Review to buy. A typical set of data that might be of interest would be a list of new products. We access this in the JSP, in just a few lines of code, as follows:
Please Note!! The code examples here are when you wish to use SOAP stubs generated from the WSDL. In fact we recommend that in a java environment you use the KKWSEng() engine to use the SOAP APIs. For details of using KKWSEng() please refer to the Using the SOAP Web Service APIs section of this User Guide.
// Get the products from the KonaKart engine using a SOAP call URL endpointUrl = new URL(kkSoapServiceUrl); KKWSEngIf eng = new KKWSEngIfServiceLocator().getKKWebServiceEng(endpointUrl); DataDescriptor dataDesc = new DataDescriptor(); dataDesc.setOffset(0); // Offset = 0 dataDesc.setLimit(3); // We only want to get back 3 products dataDesc.setOrderBy(DataDescConstants.ORDER_BY_DATE_ADDED); Products products = eng.getProductsPerCategory(null, /* Data Descriptor defining how many products, the offset and the sort order */ dataDesc, /* CategoryId. 3 is for DVD Movies */ 3, /* searchInSubCats */ true, /* The language id. -1 for the default store language */ -1); Product[] prods = products.getProductArray();
Once we have the products back in the SOAP response from the shop we can arrange them how we please on the screen.
Another interesting view we could add is to show a list of best sellers. The code is very similar, but we just use a different SOAP interface:
// Get the best sellers from the KonaKart engine using a SOAP call URL endpointUrl = new URL(kkSoapServiceUrl); KKWSEngIf eng = new KKWSEngIfServiceLocator().getKKWebServiceEng(endpointUrl); DataDescriptor dataDesc = new DataDescriptor(); dataDesc.setOffset(0); // Offset = 0 dataDesc.setLimit(16); // We only want to get back 16 products dataDesc.setOrderBy(DataDescConstants.ORDER_BY_TIMES_ORDERED); dataDesc.setOrderBy_1(DataDescConstants.ORDER_BY_NAME_ASCENDING); Product[] prods = eng.getBestSellers( /* Data Descriptor defining how many products, the offset and the sort order */ dataDesc, /* CategoryId. 3 is for DVD Movies */ 3, /* The language id. -1 for the default store language */ -1);
Adding these two sets of products to our Movie Review website we now get:
Every product shown has a link that takes the user directly to the shopping cart, just a few clicks from purchase.
Utilizing the rich set of SOAP APIs provided by KonaKart, the Movie Review website could be improved incrementally with tighter integration.
The simple SOAP calls illustrated above are supported by code that is generated directly from the KonaKart WSDL (at http://www.konakart.com/konakart/services/KKWebServiceEng?wsdl
The steps are simply:
All the source code and ANT build scripts used in this example are available for download in a basic development kit from http://www.konakart.com/kits/konakart-movie-review-dev-kit.zip
A WAR is also available which contains all the JSPs and everything you need to run the example in a container (such as tomcat) from http://www.konakart.com/kits/konakart-movie-review-war.zip
Feel free to try out the code in either format. It generates code that interfaces with the live KonaKart demo web site so you don't actually have to set up your own independent KonaKart website just to try out this example.