<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lotushints &#187; e-commerce</title>
	<atom:link href="http://www.lotushints.com/tag/e-commerce/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lotushints.com</link>
	<description>Lotus Notes tips &#38; tricks you always hoped you will not need</description>
	<lastBuildDate>Wed, 14 Jul 2010 06:00:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Design patterns &#8211; Part 1: Strategy pattern</title>
		<link>http://www.lotushints.com/2008/10/design-patterns-part-1-strategy-pattern/</link>
		<comments>http://www.lotushints.com/2008/10/design-patterns-part-1-strategy-pattern/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 08:00:05 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Code optimization]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[custom classes]]></category>
		<category><![CDATA[LotusScript]]></category>
		<category><![CDATA[object-oriented]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=60</guid>
		<description><![CDATA[One of the simplest and most commonly used patterns is definitely strategy pattern. We cannot pass a boring definition, so here you go: The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy algorithm vary independently from clients that use it. You will find out that all strategy pattern [...]]]></description>
			<content:encoded><![CDATA[<p>One of the simplest and most commonly used patterns is definitely strategy pattern. We cannot pass a boring definition, so here you go:</p>
<blockquote><p>The <strong>Strategy Pattern</strong> defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy algorithm vary independently from clients that use it.</p></blockquote>
<p>You will find out that all strategy pattern really enforces is you to plan your code for change. In this article, I would like to present use of Strategy pattern in LotusScript. <span id="more-60"></span></p>
<p>More details can be found at <a href="http://en.wikipedia.org/wiki/Strategy_pattern" target="_blank">Wikipedia</a> or <a href="http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;tag=lotus05-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596007124">Head First Design Patterns</a><img style="border:none !important; margin:0px !important;" src="http://www.assoc-amazon.com/e/ir?t=lotus05-20&amp;l=as2&amp;o=1&amp;a=0596007124" border="0" alt="" width="1" height="1" /> book.</p>
<p>For the presentation example I have chosen product handling in a shopping cart. Why? Mainly because e-commerce is something most of us, Lotus developers have to deal with at some point in our careers.</p>
<p>So, imagine following scenario. You got a job at a software company that produces and sales business software. They used to do it via a simple product (e.g. events, electronic downloads, hard copies etc.) list on the web (using notes database) and a telephone number next to it. The company feels they should focus more on their customers and make them a friendly web environment for browsing and shopping. Thus, eliminating that phone call that no one likes to make. Now, you are the person to do it. And of course, they want it yesterday.</p>
<p>First, you need to sit down and think. They have at least three types of products, each displaying differently due to its delivery behavior. Also, a user can have a discount for a certain product. Here, the strategy pattern jumps in to help.</p>
<p>You need to create a behavioral interfaces. Or in this case two (first for delivery, second for discount). Unfortunately, LotusScript doesn&#8217;t do interfaces, so you will have to replace that with an abstract class.<br />
So, two abstract classes, with single methods in it as shown below.</p>
<pre>Class CProductDeliveryBehaviour
	Sub doDeliveryDisplay()
	End Sub
End Class

Class CProductDiscountBehaviour
	Sub doDiscount()
	End Sub
End Class</pre>
<p>Next, you need to create all behavioral classes that you need. For delivery, you have three behaviors: on-site event, electronic download, or mailing the hard copy. For discount, there are only two behaviors thus far: discount and no discount. Pseudo-code is shown below.</p>
<pre>Class CEDownload As CProductDeliveryBehaviour
	Sub doDeliveryDisplay
		'do e-download delivery display
	End Sub
End Class

Class CHardCopy As CProductDeliveryBehaviour
	Sub doDeliveryDisplay
		'do hardCopy delivery display
	End Sub
End Class

Class COnSiteEvent As CProductDeliveryBehaviour
	Sub doDeliveryDisplay
		'do onSite delivery display
	End Sub
End Class

Class CDiscount As CProductDiscountBehaviour
	Sub doDiscount
		'do discount handling
	End Sub
End Class

Class CNoDiscount As CProductDiscountBehaviour
	Sub doDiscount
		'do no discount handling
	End Sub
End Class</pre>
<p>Now it is time you start thinking of products. Different product types normally do not share all properties. Thus, it is wise to create an abstract class for products and then several classes that inherit from that abstract class. In this example we obviously have at least two different product types. One are events, the other one is software. Pseudo-code is shown below.</p>
<pre>Class CProduct
	Private m_deliveryBehaviour As CProductDeliveryBehaviour
	Private m_discountBehaviour As CProductDiscountBehaviour
	Private m_dPrice As Double
	Private m_strCode As String
	Private m_strName As String
	Private m_strDescription As String

	Property Set DeliveryBehaviour As CProductDeliveryBehaviour
		Set m_deliveryBehaviour = DeliveryBehaviour
	End Property

	Property Set DiscountBehaviour As CProductDiscountBehaviour
		Set m_discountBehaviour = DiscountBehaviour
	End Property

	Sub addToCart
	End Sub

	Sub addDiscount
		If (m_discountBehaviour Is Nothing) Then Exit Sub
		Call m_discountBehaviour.doDiscount
	End Sub

	Sub doBuy
	End Sub

	Sub doDisplay
		If (m_deliveryBehaviour Is Nothing) Then Exit Sub
		Call m_deliveryBehaviour.doDeliveryDisplay
	End Sub

	Sub removeFromCart
	End Sub

	Sub showDisplay
	End Sub
End Class

Class CEvent As CProduct
	Private m_dtStart As NotesDateTime
	Private m_dtEnd As NotesDateTime
	Private m_strLocation As String

	Sub New
	End Sub

	Sub showDisplay
		'do whatever you need to display a product
		Messagebox "I am an Event!"
	End Sub
End Class

Class CSoftware As CProduct
	Private m_strUrl As String

	Sub New
	End Sub

	Sub showDisplay
		'do whatever you need to display a product
		Messagebox "I am Software!"
	End Sub
End Class</pre>
<p>Usage:</p>
<pre>Sub Initialize
	Dim product As CProduct

	Set product = New CEvent
	Set product.deliveryBehaviour = New COnSiteEvent
	Set product.discountBehaviour = New CNoDiscount

	Call product.doDisplay
	Call product.addDiscount
	Call product.showDisplay

	Set product = New CSoftware
	Set product.deliveryBehaviour = New CHardCopy
	Set product.discountBehaviour = New CDiscount

	Call product.doDisplay
	Call product.addDiscount
	Call product.showDisplay

	Set product.deliveryBehaviour = New CEDownload
	Set product.discountBehaviour = New CDiscount

	Call product.doDisplay
	Call product.addDiscount
	Call product.showDisplay
End Sub</pre>
<p>That is all there is to the Strategy Pattern. Please refer to above mentioned links for further guidance. If you have any further questions, comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2008/10/design-patterns-part-1-strategy-pattern/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Transaction logging class for Google Analytics</title>
		<link>http://www.lotushints.com/2008/09/transaction-logging-class-for-google-analytics/</link>
		<comments>http://www.lotushints.com/2008/09/transaction-logging-class-for-google-analytics/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 08:00:19 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[custom classes]]></category>
		<category><![CDATA[Google Analytics]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=14</guid>
		<description><![CDATA[At work, we are using Google Analytics tool to monitor user behaviour on our web pages. One of the things we really desired in earlier versions and is now finally available is e-commerce transaction logging. This extension uses passed data in many cool ways, creating several impressive reports (e.g. how many times a user visited [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we are using <a href="http://www.google.com/analytics">Google Analytics</a> tool to monitor user behaviour on our web pages. One of the things we really desired in earlier versions and is now finally available is e-commerce transaction logging. This extension uses passed data in many cool ways, creating several impressive reports (e.g. how many times a user visited our page prior making purchase).<span id="more-14"></span></p>
<p>Documentation on transaction logging implementation can be found <a href="http://code.google.com/apis/analytics/docs/gaJSApiEcommerce.html">here</a>. There is a slight error in documentation (applies before this post was published). When adding an <strong>Item</strong>, first parameter is not <strong>Item number,</strong> but <strong>Transaction Id</strong>! Well, if you want your reports to behave like they should according to specifications.</p>
<p>Anyway, to cut a long story short. I created a set of custom classes that will help you implement GA e-commerce code into LotusScript. It is compatible with Google Analytics e-commerce Documentation, meaning that optional parameters are optional in this class as well.</p>
<p><strong>How to install?</strong></p>
<p>First, you need to <a href="http://www.lotushints.com/uploads/GALib.zip">download this file</a> to your computer and unzip it. Create a LotusScript library in destination database. Choose File-&gt;Import and select extracted file.  Save and close the library.</p>
<p><strong>How to test?</strong><br />
Here is my testing code from an agent:</p>
<pre>Use "GoogleAnalytics" 'GA script library

Dim ga As New CGoogleAnalytics
Dim trans As New CGATransaction
Dim item As New CGAItem

trans.OrderId = "1234"
trans.Affiliation = "Test store"
trans.Total = "20.00"
trans.Tax = "4.00"
trans.Shipping = "0.00"
trans.City = "Ljubljana"
trans.State = "SI"
trans.Country = "Slovenia"

'item 1
item.OrderId = trans.OrderId
item.SKU = "ItemSKU"
item.ItemName = "ItemName1"
item.Category = "ItemCategory1"
item.Price = "5.00"
item.Quantity = "1"
Call trans.AddItem (item)

'item 2
item.OrderId = trans.OrderId
item.SKU = "ItemSKU"
item.ItemName = "ItemName2"
item.Category = "ItemCategory2"
item.Price = "15.00"
item.Quantity = "1"
Call trans.AddItem (item)

'Debug parameter is added only for testing purposes.
'Default is false. If true, it strips script tags from output.
ga.Debug = True
Set ga.Transaction = trans
Messagebox ga.Serialize ("SiteName")</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2008/09/transaction-logging-class-for-google-analytics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
