I must be missing something. 

I'm using the following to update a structure. If the product is a category 16, 
then update the unit price, based on values in a table. I'm not getting an 
error, but it's not updating the unit price position for category 16 items 
either.

I just don't see why not!  



<!--- recalculate all the unit prices for products  --->


<!--- // The item structure of cart
                                
        //              1.  The item id
        //              2.  The item name
        //              3.  The price per unit
        //              4.  The quantity
        //              5.  The category      --->

<cfoutput>
 <cfset totalproducts = 0>
                        <!--- how many products in the cart?--->
                <cfloop collection="#session.cart#" item="i">
           <cfif #session.cart[i][5]# is 16>
               <cfset totalproducts = totalproducts + (#session.cart[i][4]# * 
1)>
                        </cfif>
        </cfloop>

 <cfloop collection="#session.cart#" item="i">
<!--- update unit price (position3) of each item in the cart where the product 
category is 16 --->
               <cfif #session.cart[i][5]# is 16>
                            <cfset quantityadded = #totalproducts#>
                  
                  
<!--- with the itemid, go to the table and get the unit prices based on qty --->
                                                        <CFQUERY 
name="Getproductsprice" datasource="#request.orderdsn#" dbtype="ODBC">
                                     SELECT *
                                     FROM products
                                     WHERE productid='#session.cart[i][1]#'
                                 </CFQUERY>
                           

           <!--- set the new price --->
                               <cfif #quantityadded# is 1>
                                            <cfset 
attributes.newprice="#Getproductsprice.list#">
                                                    <cfelseif #quantityadded# 
is 2>
                                                            <cfset 
attributes.newprice="#Getproductsprice.two#">
                                                  </cfif>


                        
          <!--- now go through and update unit price in the structure for this 
one item --->
                     <cfscript>
                                
                     tempvalue = 
listtoarray('#attributes.id#,#attributes.name#,#attributes.newprice#,#attributes.quantity#,#attributes.category#');
                                        if (not(structKeyExists(session.cart, 
attributes.id))) {
                                
StructInsert(session.cart,attributes.id,tempvalue);
                                   }

                                // if the item is already in the cart, update 
the item price
                                else {
                                        tempvalue[3]=attributes.newprice;
                                        
StructUpdate(session.cart,attributes.id,tempvalue);
                                }
                                                </cfscript>
                            </cfif>
</cfloop>
</cfoutput>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:257872
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to