I'll attach some simple shopping cart / update code here. You can adapt it to your
needs.
---mark
<!-- begin dsp_public_cart_view.cfm -->
<h3>Cart</h3>
<cfif get_cart_lineitems.recordcount eq 0>
<cfoutput>
There are no items in your cart. <cfif session.loggedin neq 1>If you think
there should be items in your cart, try <a
href="#session.web_root_path#/login/index.cfm?fuseaction=login_form">logging
in</a>.</cfif>
</cfoutput>
<cfelse>
Note: You can remove a product by updating its quantity to zero and updating the cart.
<br>
<br>
<cfoutput>
<form action="#script_name#" method="post">
<input type="hidden" name="fuseaction" value="#fuseaction#">
<input type="hidden" name="totalrows" value="#get_cart_lineitems.recordcount#">
<table
width="#session.table_width#"
border="#session.table_border#"
cellspacing="#session.table_cellspacing#"
cellpadding="#session.table_cellpadding#"
align="#session.table_align#"
bordercolor="#session.table_bordercolor#"
bordercolorlight="#session.table_bordercolorlight#"
bordercolordark="#session.table_bordercolordark#"
bgcolor="#session.table_bgcolor#">
<tr>
<td valign="top" bgcolor="#session.headerrowcolor#"><font
face="#session.fontface#" size="#session.fontsize#"> </td>
<td valign="top" bgcolor="#session.headerrowcolor#"><font
face="#session.fontface#" size="#session.fontsize#"><b>Product Name</b></td>
<td valign="top" bgcolor="#session.headerrowcolor#"><font
face="#session.fontface#" size="#session.fontsize#"
bgcolor="#session.headerrowcolor#"><b>Price</b></td>
<td valign="top" bgcolor="#session.headerrowcolor#"><font
face="#session.fontface#" size="#session.fontsize#"
bgcolor="#session.headerrowcolor#"><b>Quantity</b></td>
<td valign="top" bgcolor="#session.headerrowcolor#"><font
face="#session.fontface#" size="#session.fontsize#"
bgcolor="#session.headerrowcolor#"><b>Extended Price</b></td>
</tr>
</cfoutput>
<cfset sub_total = 0>
<cfoutput query="get_cart_lineitems">
<cfif currentrow mod 2 eq 1>
<cfset currentrowbgcolor = session.rowcolor1>
<cfelse>
<cfset currentrowbgcolor = session.rowcolor2>
</cfif>
<input type="hidden" name="ID_CART_LINEITEM_#currentrow#"
value="#ID_CART_LINEITEM#">
<input type="hidden" name="ID_PRODUCT_#currentrow#" value="#id_product#">
<input type="hidden" name="VA_PRICE_#currentrow#" value="#va_price#">
<tr>
<td valign="top" bgcolor="#currentrowbgcolor#"><font face="#session.fontface#"
size="#session.fontsize#">#currentrow#</td>
<td valign="top" bgcolor="#currentrowbgcolor#"><font face="#session.fontface#"
size="#session.fontsize#"><a
href="#session.web_root_path#/products/index.cfm?fuseaction=public_products_display_detail&id_product=#ID_PRODUCT#">#Product_Name#</a></td>
<td valign="top" align="right" bgcolor="#currentrowbgcolor#"><font
face="#session.fontface#" size="#session.fontsize#">#DollarFormat(va_price)#</td>
<td valign="top" align="center" bgcolor="#currentrowbgcolor#"><font
face="#session.fontface#" size="#session.fontsize#">
<cfif va_price eq 0>
<input type="text" name="quantity_#currentrow#" value="#quantity#" size="3"
maxlength="5" style="text-align: center;" readonly>
<cfelse>
<input type="text" name="quantity_#currentrow#" value="#quantity#" size="3"
maxlength="5" style="text-align: center;">
</cfif>
</td>
<cfset extended_price = va_price*quantity>
<cfset sub_total = sub_total+extended_price>
<td valign="top" align="right" bgcolor="#currentrowbgcolor#"><font
face="#session.fontface#" size="#session.fontsize#">#DollarFormat(extended_price)#</td>
</tr>
</cfoutput>
<cfoutput>
<tr>
<td align="center" colspan="3"><font face="#session.fontface#"
size="#session.fontsize#">
<table
width="#session.table_width#"
border="#session.table_border#"
cellspacing="#session.table_cellspacing#"
cellpadding="#session.table_cellpadding#"
align="#session.table_align#"
bordercolor="#session.table_bordercolor#"
bordercolorlight="#session.table_bordercolorlight#"
bordercolordark="#session.table_bordercolordark#"
bgcolor="#session.table_bgcolor#">
<tr>
<td valign="top"><font face="#session.fontface#" size="#session.fontsize#"><input
type="submit" name="cart_action" value="Update Cart"></td>
<td valign="top"><font face="#session.fontface#" size="#session.fontsize#"><cfif
session.id_contact eq 0>
<input type="submit" name="cart_action" value="Login and Checkout">
<cfelse>
<input type="submit" name="cart_action" value="Checkout">
</cfif></td></form>
<td valign="top"><font face="#session.fontface#" size="#session.fontsize#">
<form action="#http_referer#" method="post">
<input type="submit" value="Continue Shopping"></form></td>
</tr>
</table>
</td>
<td align="right" valign="top" colspan="2"><font face="#session.fontface#"
size="#session.fontsize#"><b>Sub Total:</b> #DollarFormat(sub_total)#</td>
</tr>
</tr>
</table>
<br>
</cfoutput>
</cfif>
<!-- end dsp_public_cart_view.cfm -->
<!-- begin act_public_cart_update_lineitems.cfm -->
<cfif http_referer does not contain "#server_name#">
<h1>Warning!</h1>
<b>Your hack attempt has been logged. Hacking is a federal crime, punishable as a
felony. Leave now or face the consequences.</b>
<cfelse>
<cfloop index="row" from="1" to="#totalrows#">
<cfset ControlName1 = "Form.quantity_" & row>
<cfset Quantity = Evaluate("#ControlName1#")>
<cfif IsNumeric(quantity) eq "no">
<cflocation url="#script_name#?fuseaction=#fuseaction#" addtoken="no">
</cfif>
<!--- <cfoutput>
Quantity: #quantity# |
</cfoutput> --->
<cfset ControlName2 = "Form.ID_CART_LINEITEM_" & row>
<cfset ID_CART_LINEITEM = Evaluate("#ControlName2#")>
<!--- <cfoutput>
ID_CART_LINEITEM: #ID_CART_LINEITEM# |
</cfoutput> --->
<cfset ControlName3 = "Form.ID_PRODUCT_" & row>
<cfset ID_PRODUCT = Evaluate("#ControlName3#")>
<!--- <cfoutput>
ID_PRODUCT: #ID_PRODUCT#<br>
</cfoutput> --->
<cfset ControlName4 = "Form.VA_PRICE_" & row>
<cfset VA_PRICE = Evaluate("#ControlName4#")>
<cfif VA_PRICE eq 0>
<cfset Quantity = 1>
</cfif>
<cfif Quantity eq 0>
<!--- remove the lineitem --->
<cfquery name="remove_lineitem" datasource="#session.dsn#">
DELETE FROM CARTS_LINEITEMS
WHERE ID_CART_LINEITEM = #ID_CART_LINEITEM#
</cfquery>
<!--- now look for free items that are associated with this product
--->
<cfquery name="check_PRODUCTS_TO_FREE_PRODUCTS"
datasource="#session.dsn#">
SELECT ID_PRODUCT_FREE
FROM PRODUCTS_TO_FREE_PRODUCTS
WHERE ID_PRODUCT = #id_product#
</cfquery>
<!--- <cfoutput>
check_PRODUCTS_TO_FREE_PRODUCTS.recordcount:
#check_PRODUCTS_TO_FREE_PRODUCTS.recordcount#<br>
</cfoutput> --->
<!--- is this free product already in the cart? --->
<cfloop query="check_PRODUCTS_TO_FREE_PRODUCTS">
<cfquery name="check_cart" datasource="#session.dsn#">
SELECT ID_CART_LINEITEM
FROM CARTS_LINEITEMS
WHERE ID_PRODUCT = #id_product_free#
</cfquery>
<!--- this free item is in the cart. remove it now --->
<cfif check_cart.recordcount neq 0>
<cfquery name="remove_free_item"
datasource="#session.dsn#">
DELETE FROM CARTS_LINEITEMS
WHERE ID_CART_LINEITEM = #check_cart.ID_CART_LINEITEM#
</cfquery>
</cfif>
</cfloop>
<cfelse>
<!--- update the quantity of the lineitem --->
<cfquery name="update_quanity" datasource="#session.dsn#">
UPDATE CARTS_LINEITEMS
SET QUANTITY = #quantity#
WHERE ID_CART_LINEITEM = #ID_CART_LINEITEM#
</cfquery>
<!--- now look for free items that are associated with this
product --->
<cfquery name="check_PRODUCTS_TO_FREE_PRODUCTS"
datasource="#session.dsn#">
SELECT ID_PRODUCT_FREE
FROM PRODUCTS_TO_FREE_PRODUCTS
WHERE ID_PRODUCT = #ID_PRODUCT#
</cfquery>
<!--- <cfoutput>
check_PRODUCTS_TO_FREE_PRODUCTS.recordcount:
#check_PRODUCTS_TO_FREE_PRODUCTS.recordcount#<br>
</cfoutput>
--->
<!--- is this free product already in the cart? --->
<cfloop query="check_PRODUCTS_TO_FREE_PRODUCTS">
<cfquery name="check_cart" datasource="#session.dsn#">
SELECT ID_PRODUCT
FROM CARTS_LINEITEMS
WHERE ID_PRODUCT = #ID_PRODUCT_FREE#
</cfquery>
<!--- <cfoutput>
check_cart.recordcount: #check_cart.recordcount#
</cfoutput> --->
<!--- this free item isn't in the cart. add it now --->
<cfif check_cart.recordcount eq 0>
<CFINCLUDE
TEMPLATE="#session.template_path#/global_templates/act_global_get_key.cfm">
<cfset ID_CART_LINEITEM = id_key>
<cfquery name="insert_free_item"
datasource="#session.dsn#">
INSERT INTO CARTS_LINEITEMS (ID_CART_LINEITEM,
ID_CART, ID_PRODUCT, QUANTITY)
VALUES (#ID_CART_LINEITEM#, #session.id_cart#,
#ID_PRODUCT_FREE#, 1)
</cfquery>
</cfif>
</cfloop>
</cfif>
<!--- <cfoutput>
ID_CART_LINEITEM: #ID_CART_LINEITEM# - Qty.: #quantity#<br>
</cfoutput> --->
</cfloop>
<cflocation url="#script_name#?fuseaction=#fuseaction#" addtoken="no">
</cfif>
<!-- end act_public_cart_update_lineitems.cfm -->
========================================Mark Warrick - Fusioneers.com
Personal Email: [EMAIL PROTECTED]
Business Email: [EMAIL PROTECTED]
Phone: 714-547-5386
Efax: 801-730-7289
Personal URL: http://www.warrick.net
Business URL: http://www.fusioneers.com
ICQ: 125160 / AIM: markwarric
========================================
-----Original Message-----
From: John Paitel [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 24, 2001 11:33 AM
To: CF-Talk
Subject: RE: CFFORM vs. CFGRID
>Why not enter the products directly into the Access database?
This is not my inventory, it is their inventory. There may be multiple
locations entering in their own inventory. (Think more along the lines of
an office inventory rather than a store inventory).
>I wouldn't recommend CFGRID or CFFORM. Those are limited functions.
Ok, alternatives?
>You can loop through 10 record entries at a time the same way you would
>loop through a shopping cart to update quantities. There's just a bunch
>more fields involved.
Array type? Remember, I am somewhat new to this part of it.
John
>---mark
>
>========================================Mark Warrick - Fusioneers.com
>Personal Email: [EMAIL PROTECTED]
>Business Email: [EMAIL PROTECTED]
>Phone: 714-547-5386
>Efax: 801-730-7289
>Personal URL: http://www.warrick.net
>Business URL: http://www.fusioneers.com
>ICQ: 125160 / AIM: markwarric
>=======================================>
>-----Original Message-----
>From: John Paitel [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, July 24, 2001 9:55 AM
>To: CF-Talk
>Subject: CFFORM vs. CFGRID
>
>
>Hey all...
>
>Question about editing database information. I have an inventory database
>that I want users to be able to update via a web interface. For the initial
>entry, I have a screen that enters a single item, then updates the database
>(Access at the moment). For editing purposes, I'd like them to be able to
>edit up to 10 records at a time.
>
>Is this suited more to CFGRID, or CFFORM? (As you can tell, I am on the
>newer side of the CF fence.)
>
>And, does CFGRID handle entering in 10 new records at a time? Or should I
>stick with the single page entry? (Users sometimes will be entering in
>quite a few new items, and single screen entry gets long and tedious).
>
>Any opinions? Or is there something even better out there that I haven't
>seen yet?
>
>John Paitel
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists