Charon Cart Version 2 Tutorial

This is a comprehensive tutorial outlining the steps neccessary to implement a shopping cart on a site using the excellent Charon Cart Extension. It is suitable for all but the very novice Ultradev user. The only requisite skills are an ability to create filtered recordsets and some familiarity with the Goto Link Page behaviour.

There are well illustrated steps to all the Charon Cart features, a short discussion on database design and a commented version of the server side code included with this extension.

This tutorial has been written with the kind permission of the extension author Jules Roberts. Corrections and suggestions are welcomed.

Adding Shipping Costs

There are three ways to calculate the shipping cost, two manually and one using a database table.

The simplest is clicking on the Charon Cart > Fixed Cost Shipping behaviour to open the following dialogue.

Simply enter the amount you wish to charge for shipping in the box and it will automatically be added to the GrandTotal and will be available for display from the Charon Cart recordset. This will be a fixed amount regardless of the final size or cost of the submitted order.

The next manual method is to click on the Charon Cart > Custom Shipping Costs behaviour to open this dialogue box.

This allows you to insert a function to calculate the shipping costs based on some criteria of the current carts contents. This is written in VBs using an If Then construct. In the default setting it sets the shipping variable (CCcart_Shipping) to equal 4 if the current orders subtotal (CCCart_SubTotal) is greater than 20. This will leave the shipping costs as zero if the subtotal is less than 20. As an example you could also write here;

If CCcart_Subtotal > 20 then CCcart_Shipping = 4 Else CCcart_Shipping = 3

This would also set the shipping costs to 4 if the subtotal were greater than 20 but would also set the shipping costs at 3 if the subtotal were not greater than 20, i.e. less than or equal to 20. If writing VBscript is not familiar to you then I would advise using either the fixed shipping costs behaviour or the database driven behaviour discussed below.

To use a database table to calculate shipping costs a table must first exist with the shipping costs and the upper and lower boundaries for whatever criteria you are using to calculate costs. In the sample access DB provided with the extension order value is used to calculate shipping costs. You could use weight for instance, or country for delivery.

Bear in mind that whatever criteria you use, it must be available in each order or item in the cart so that it can be compared to the table of shipping costs. There is no point in using weight to calculate shipping costs if you don't have the total weight of the order because there is no weight column included in the cart!

A sample table to calculate shipping costs is included in the extension and is shown below. So if an orders subtotal was 135 it would lie within record number 3's boundaries and shipping costs would be 15. You can edit this table to reflect whatever shipping you wish to levy. It is important that the boundaries for each row do NOT overlap as you will not be sure that the correct row is being retrieved when it is compared to the order subtotal.

To calculate shipping costs from a database table you must create a recordset that selects the correct shipping costs based on whatever criteria of the order you are using, in our example the order subtotal (CCcart_SubTotal). Create your recordset as shown below.

The SQL box should contain the following SQL statement;

Select * From Shipping_table
Where MinPurchase <= var AND MaxPurchase > var

Add a variable to the variable window by clicking on the plus key. Call it Var (so it matches the SQL statement) give it a default value (doesn't matter what) and then assign its runtime value to CCcart_Subtotal.

What this recordset is doing is grabbing all the records from the shipping table (whatever yours might be called) where the value of the CCcart_Subtotal lies within the upper and lower boundaries of the records min and max purchase columns. Which record is retrieved and the associated shipping costs will of course vary as the subtotal of the order changes from order to order.

next subtracting a discount....
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18

Comments

A VERY important tip for use with Dreamweaver MX

November 15, 2002 by Ivan Halen

I found that storing the Order and the Cart to a Database with Dreamweaver MX requires a slight modify to both the rsOrders and rsOrderDetails Recordsets (pages 13/14 of the tutorial).

In order to work properly, you have to change the LockType from Read Only (this is the default LockType in DreamweaverMX) to Optimistic. To do so, just select your Recordsets in the Server Behaviors Panel one at a time, then go to the Properties bar and change the Lock Type as I said above.

Maybe on Ultradev the default Lock Type is Optimistic (remember that's NOT so on Dreamweaver MX), so Rolf didn't mentioned in his tutorial. If you don't change the Lock Type, you'll get this error:

"ADODB.Recordset (0x800A0CB3)
Current Recordset does not support updating. This may be a limitation of
the provider, or of the selected locktype."

(as you see you find the word "locktype" in the error, and it's quite easy to understand: not so if you are using a non-english version of IIS or PWS, as me)

Oh, Rolf! Please change the Image029.gif on page 14: the selected Recordset is rsOrders and not rsOrderDetails, and that maybe confusing for the new user.

Happy Carting! :-)

About the Tutorial

November 17, 2002 by Kamran Aslam

I think the tutorial is tooo long. it will be better if it will be a little shorter or in other means " to the point" But anyways its good. but boaring too beacuse of too much text i guess.

Thanks anyways for the good things.

 

Pretty Good Until SSL

January 1, 2003 by James Threadgill

This was a pretty good tutorial until you left me hanging out to dry without a way to pass my cart over to my SSL connection. I found a form variable or a querystring works fine for this. In order to implement such a scheme one must create a modified version of the inc_CharonCart.asp, so that the function CookieToCart reads the values in from the form variable or querystring after one establishes the SSL connection. I modified it like so and saved it as ssl_inc_CharonCart.asp:

<%
CONST CC_ProductID = 0
CONST CC_Quantity = 1
CONST CC_Name = 2
CONST CC_Price = 3
CONST CC_UniqueKey = 4

CCcart=CookieToCart("SoftwareCart")
CCcart_SubTotal=0
CCcart_numItems=0
CCcart_Shipping=0
CCcart_Discount=0
CCcart_SalesTax=0
isFound=false

for i="0" to ubound(CCcart,2)
if CCcart(CC_ProductID,i) <> "" then
isFound=true
CCcart_SubTotal=CCcart_SubTotal + (CCcart(CC_Quantity,i)*CCcart(CC_Price,i))
CCcart_numItems=CCcart_numItems + 1
end if
next

function CCcart_LineTotal
CCcart_LineTotal=CCcart(CC_Quantity,i)*CCcart(CC_Price,i)
end function

function CCcart_GrandTotal
CCcart_GrandTotal=CCcart_SubTotal + CCcart_Shipping + CCcart_SalesTax - CCcart_Discount
end function

function CookieToCart(cookiename)
mystring=Request("Cart")
dim myarray(5,50)
productarray=split(mystring,"|")
for j="0" to ubound(productarray)
itemarray=split(productarray(j),"^")
for i="0" to 5
if itemarray(i) <> "" then
myarray(i,j)=itemarray(i)
else
myarray(i,j)=null
end if
next
next
CookieToCart=myarray
end function
%>

Notice the variable "mystring" in function CookieToCart now gets the cookie using a generic request.  The other difference is--unless you are allowing Cart Updates on your checkout page--is the the CartToCookie function and the code to initialize the cart array are no longer needed and can be removed for clarity as I have.  

RE: A VERY important tip for use with Dreamweaver MX

January 1, 2003 by James Threadgill
Thanks for this--saved me some head banging.
See all 20 Comments

You must me logged in to write a comment.