Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

shopping cart help

0 views
Skip to first unread message

GUJUm0deL

unread,
Jan 13, 2004, 10:34:12 PM1/13/04
to
Hi folks, need some help here. I am using the "shopping cart" that is in the Ben Forta's CF book. The shopping cart does exactly what I need, except that my client has 3 diff. sizes instead of one. I get it to display all the sizes, with the prices, however its only when I try to "buy" a paticular size, or all three sizes that the problem occurs. It seems to add the quantity right, but instead of adding it to the specific size, it just adds to the default.


EX:
I add 10 4 oz. "Annatto Seed" (its sizes are: 4 oz., 8 oz, 16 oz.) to the cart, then I go back and try to add 10 8 oz. "Annatto Seed", but instead of the cart showing 10 4 oz. and 10 8 oz. it shows 20 4 oz., how come??


You can see it in action here: http://www.gujum0del.com/shopping/store.cfm

<!--- Create and cache the product list --->
<cfquery name="application.ItemsShort" datasource="#attributes.dsn#" cachedWithin="#cacheItemList#">

SELECT Products.ProductID, Products.ProductName, Categories.Name, Categories.Description,
Categories.CategoryID, ProductDetails.ProductDetailID
FROM Products, Categories, ProductDetails
WHERE Products.CategoryID = Categories.CategoryID
AND ProductDetails.ProductID = Products.ProductID
ORDER BY Categories.Name, Products.ProductName

</cfquery>

<!--- Create the shopping basket --->
<cfif not isDefined("session.basket")>
<cfset session.basket = queryNew("ProductID, quantity, saleDate")>
</cfif>

<cfif isdefined("url.do")>
<cfset session.do = url.do>
<cfelse>
<cfset session.do = "index">
</cfif>

<!--- Build query string --->
<cfif attributes.addtoken>
<cfset variables.querystring = "?#client.URLToken#&">
<cfelse>
<cfset variables.querystring = "?">
</cfif>

<!--- Do what we need to do --->
<cfif session.do is "action">
<!--- Handle events --->
...
...
...
<cfelseif action is "Add to basket">
<cf_quickStore_basket
action="add"
productID="#form.productID#"
ProductDetailID="#form.ProductDetailID#"
Quantity="#form.Quantity#">

<cfset session.do = "basket">

<cfelseif action is "Update basket">
<cf_quickStore_basket
action="update"
productID="#form.productID#">

<cfset session.do = "basket">
...
...
...
</cfif>

<cfcase value="index">

<!--- Main page --->
<cf_quickStore_catalog
action="index"
thispage="#thispage#"
querystring="#querystring#"
dsn="#attributes.dsn#">
</cfcase>

<cfcase value="search">
<!--- Search results --->
<cf_quickStore_catalog
action="search"
thispage="#thispage#"
querystring="#querystring#"
dsn="#attributes.dsn#">
</cfcase>

<cfcase value="list">
<!--- Product listing --->
<cf_quickStore_catalog
action="list"
thispage="#thispage#"
querystring="#querystring#"
dsn="#attributes.dsn#">
</cfcase>

<cfcase value="detail">
<!--- Product detail --->
<cf_quickStore_catalog
action="detail"
thispage="#thispage#"
querystring="#querystring#"
dsn="#attributes.dsn#">
</cfcase>

<cfcase value="basket">
<!--- The shopping basket --->
<cf_quickStore_basket
action="show"
thispage="#thispage#"
querystring="#querystring#"
dsn="#attributes.dsn#">
</cfcase>

displays the "add to basket" page

<cfelseif attributes.action is "detail">
<!--- Product detail --->
<cfquery name="ItemsLong" datasource="#attributes.dsn#">
SELECT Products.ProductID, Products.ProductName, Products.DescriptionShort, Categories.CategoryID,
Categories.Name, ProductDetails.ProductDetailID, ProductDetails.UnitSize, ProductDetails.UnitPrice
FROM Products, Categories, ProductDetails
WHERE Products.CategoryID = Categories.CategoryID
AND ProductDetails.ProductID = Products.ProductID
AND (ProductDetails.ProductID = #URL.ProductID#)
</cfquery>

<table cellspacing="0" cellpadding="2" border="1" width=80%>
<tr>
<td><cfoutput query="ItemsLong" maxrows=1><b>#ProductName#</b></cfoutput></td>
</tr>
<tr>
<td>
<table width="790" border=0>
<tr><td colspan=2><b>Detail</b><p></td></tr>
<cfoutput query="ItemsLong">
<cfform action="#thisPage##queryString#do=action">
<tr>
<td valign="top" width=39%>
<font size="2">#UnitSize# - #DollarFormat(UnitPrice)#
<cfinput type="Text" name="Quantity" value="1" validate="integer" required="No" size="2" maxlength="3">

</font>
</td>
<td valign="top" width=61%><strong>#DescriptionShort#</strong></td>
</tr>
<tr>
<td colspan=2>
<input type="Hidden" name="Quantity_integerinteger" value="You must enter a quantity as a numeric value.">
<b>Quantity</b>
<input type="Hidden" name="ProductID" value="#ProductID#">
<input type="Hidden" name="ProductDetailID" value="#ProductDetailID#">
<input type="Submit" name="action" value="Add to basket">
</td>
</tr>
</cfform>
</cfoutput>
</table>
</td>
</tr>
</table>

<!--- QuickStore_basket custom tag --->
<!--- Initialize --->
<cfparam name="attributes.productID" default="">
<cfparam name="attributes.ProductDetailID" default="">
<cfparam name="attributes.quantity" default="1">
<cfparam name="attributes.thispage" default="#GetFileFromPath(GetTemplatePath())#">
<cfparam name="attributes.querystring" default="?">

<cfset thisPage = attributes.thisPage>
<cfset queryString = attributes.queryString>

<cfif attributes.action is "show">
<!--- The shopping basket --->
<table cellspacing="0" cellpadding="2" border="1">
<tr>
<td><cfoutput><b>Shopping Basket</b></cfoutput>
</td>
</tr>
<tr>
<td>
<table border=0>
<tr>
<td colspan=2> <b>Items</b> </td>
</tr>
<tr>
<td> <b><font size="-1">Name</font></b> </td>
<td> <b><font size="-1">Qty.</font></b> </td>
<td> <b><font size="-1">Price</font></b> </td>
<td> <b><font size="-1">Total</font></b> </td>
<td> <b><font size="-1">Remove</font></b> </td>
</tr>
<cfset session.total = 0>
<cfform action="#thisPage##queryString#do=action">
<cfloop query="session.basket">
<!--- Get product information --->
<cfquery name="Item" datasource="#attributes.dsn#">
SELECT *
FROM Products, ProductDetails
WHERE ProductDetails.ProductID = #session.basket.productID#
</cfquery>
<tr>
<cfoutput>
<td valign="top"><b><a href="#thisPage##queryString#ProductID=#item.ProductID#&do=detail">#item.ProductName#</a></b></td>
<td valign="top">#item.UnitSize# - #session.basket.quantity# </td>
<td valign="top">#DollarFormat(item.UnitPrice)#</td>
<td valign="top">#DollarFormat(item.UnitPrice * session.basket.quantity)#</td>
<td valign="top"> <input type="checkbox" name="productID" value="#item.productID#"></td>
</cfoutput>
</tr>

<cfset session.total = evaluate(session.total + (item.UnitPrice * session.basket.quantity))>
</cfloop>
<tr>
<cfoutput>
<td colspan="2"> </td>
<td valign="top"><b>Over All Price:</b></td>
<td valign="top">#DollarFormat(session.total)#</td>
<td valign="top"> <input type="submit" value="Delete"> </td>
</cfoutput>
</tr>
</table>
<input type="hidden" name="action" value="Update basket">
</cfform>
</td>
</tr>
<tr>
<td><cfoutput><b>[<a href="#thisPage##queryString#">Home</a>] [<a href="#thisPage##queryString#do=form">Check out</a>]</b></cfoutput>
</td>
</tr>
</table>

<!--- Update shopping cart --->
<cfelseif attributes.action is "update">
<!--- Loop through basket and remove selected items --->
<cfset newBasket = queryNew("ProductID, Quantity, saleDate")>
<cfloop query="session.basket">
<!--- Add anything that isn't in the delete list --->
<cfif not listFind(attributes.productID, productID)>
<cfset tempValue = queryAddRow(newBasket)>
<cfset tempValue = querySetCell(newBasket, "saleDate", saleDate)>
<cfset tempValue = querySetCell(newBasket, "ProductID", ProductID)>
<cfset tempValue = querySetCell(newBasket, "Quantity", quantity)>
</cfif>
</cfloop>
<!--- set the basket to the new values --->
<cfset session.basket = newBasket>
<!--- Add product to query --->
<cfelseif attributes.action is "add">
<!--- check to see if the product is in the baset already --->
<cfset productRow = listFind(valueList(session.basket.productID), attributes.productID)>
<!--- Product is in basket, update quantity --->
<cfif productRow neq 0>
<!--- determine the new quantity and the correct row --->
<cfset oldQuantity = listGetAt(valueList(session.basket.quantity), productRow)>
<cfset newQuantity = attributes.quantity + oldQuantity>
<cfset tempValue = querySetCell(session.basket, "Quantity", newQuantity, productRow)>
<!--- Product is not in basket, add it --->
<cfelse>
<cfset tempValue = queryAddRow(session.basket)>
<cfset tempValue = querySetCell(session.basket, "saleDate", "#Now()#")>
<cfset tempValue = querySetCell(session.basket, "ProductID", attributes.ProductID)>
<cfset tempValue = querySetCell(session.basket, "Quantity", attributes.quantity)>
</cfif>
</cfif>

Thanks.

&quot;Life is complicated enough, without you interfering...&quot;

0 new messages