hey guys,
I find myself in need of a new function added into a CF_Application that I
inherited along with this project/job.

I need to add a function that will allow for the updating of the quantity of
items in a cart.

I have the following:

<!--- 'ADD' function; needs ITEM, QTY and CART --->
<cfif Attributes.Function eq "add">
    <!--- store the cart into a temporary variable --->
    <cfset SC_temp = Evaluate(SC_cart) >
    <!--- check to make sure the correct quantity is passed --->
    <cfif (Attributes.Qty neq 0) AND (Len(Attributes.Qty) gt 0) >
        <!--- check to see if the item already exists in the cart --->
        <cfif ListContains(SC_temp, Attributes.Item, "*") >
            <!--- set the position of the item in the 'main list' --->
            <cfset SC_position = ListContains(SC_temp, Attributes.Item, "*") >
            <!--- set the sub-list in the 'main list' to a temporary variable --->
            <cfset SC_item = ListGetAt(SC_temp, SC_position, "*") >
            <!--- add the old number to the new number --->
            <cfset SC_qty = ListGetAt(SC_item, 2, "&") + Attributes.Qty >
            <!--- change the quantity in the sub-list --->
            <cfset SC_item = ListSetAt(SC_item, 2, SC_qty, "&") >
            <!--- change the value of the entry in the 'main list' --->
            <cfset SC_temp = ListSetAt(SC_temp, SC_position, SC_item, "*") >
        <cfelse>
            <!--- set up the item to add to the cart --->
            <cfset SC_add = Trim(Attributes.Item) & "&" & Trim(Attributes.Qty) >
            <!--- append the new item to the cart --->
            <cfset SC_temp = ListAppend(SC_temp, SC_add, "*") >
        </cfif>
        <!--- set the count variable to zero --->
        <cfset caller.ShoppingCart_Items = 0 >
        <!--- loop for each item in the cart --->
        <cfloop index="SC_index" list="#SC_temp#" delimiters="*">
            <!--- set the count variable in the caller template --->
            <cfset caller.ShoppingCart_Items = caller.ShoppingCart_Items + 
ListGetAt(SC_index, 2, "&") >
        </cfloop>
        <!--- re-assign the cart to the client variable --->
        <cfset "#SC_cart#" = SC_temp >
    <cfelse>
        <cfabort showerror="quantity error, should be a number greater than 0" >
    </cfif>

<!--- 'REMOVE' function; needs ITEM, CART and may contain QTY --->
<cfelseif Attributes.Function eq "remove">
    <!--- store the cart into a temporary variable --->
    <cfset SC_temp = Evaluate(SC_cart) >
    <!--- set the number of items to remove --->
    <cfif (Attributes.Qty neq 0) AND (Len(Attributes.Qty) gt 0) >
        <!--- if there is a number passed then set that number to the ammount to 
remove --->
        <cfset SC_remove = Attributes.Qty >
    <cfelse>
        <!--- if there is no quantity passed then remove only one item --->
        <cfset SC_remove = 1 >
    </cfif>
    <!--- check to see if the item is in the 'main-list' if not just ignore the 
command --->
    <cfif ListContains(SC_temp, Attributes.Item, "*")>
        <!--- item is in the cart, alter the quantity --->
        <!--- set the position of the item in the main 'main list' --->
        <cfset SC_position = ListContains(SC_temp, Attributes.Item, "*") >
        <!--- set the sub-list in the 'main list' to a temporary variable --->
        <cfset SC_item = ListGetAt(SC_temp, SC_position, "*") >
        <!--- subtract the old number from the new number --->
        <cfset SC_qty = ListGetAt(SC_item, 2, "&") - SC_remove >
        <!--- check to see if the value is below zero, if it is remove the item from 
the 'main list' --->
        <cfif SC_qty lte 0>
            <!--- less than/equal to zero, remove item from cart --->
            <cfset SC_temp = ListDeleteAt(SC_temp, SC_position, "*") >
        <cfelse>
            <!--- still above zero, just replace quantity --->
            <!--- change the quantity in the sub-list --->
            <cfset SC_item = ListSetAt(SC_item, 2, SC_qty, "&") >
            <!--- change the value of the entry in the 'main list' --->
            <cfset SC_temp = ListSetAt(SC_temp, SC_position, SC_item, "*") >
        </cfif>
    </cfif>
    <!--- set the count variable to zero --->
    <cfset caller.ShoppingCart_Items = 0 >
    <!--- loop for each item in the cart --->
    <cfloop index="SC_index" list="#SC_temp#" delimiters="*">
        <!--- set the count variable in the caller template --->
        <cfset caller.ShoppingCart_Items = caller.ShoppingCart_Items + 
ListGetAt(SC_index, 2, "&") >
    </cfloop>
    <!--- re-assign the cart to the client variable --->
    <cfset "#SC_cart#" = SC_temp >

Knowing that, how would I go about making an "update" or "recalculate" function?

-- 
***********************************************
 Jon Tillman
 LINUX USER: #141163
 ICQ: 4015362
 http://www.eruditum.org
 [EMAIL PROTECTED]
***********************************************
Help Jon build a network!
Looking for giveaway computers & parts
Current Need: Tape Drive & PI/PII processors
Email me to find out how you can help
***********************************************

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to