managing product stock levels cont...

hi guys,

i have created the following function which creates a product structure 
including information about any options loaded and inventory levels.

this seems to work fine when just needing to display one product. however, when 
i need to display more than one eg. index page (and i need to know info about 
the stock levels) it becomes VERY inefficient to call this function multiple 
times.

can anyone let me know if there is a better path i should be following for this?

<cffunction name="get_product_struct" output="false" access="public" 
returntype="struct">
                <cfargument name="product_id" type="numeric" required="true">
                
                <cfset var qGetProduct = "">
                <cfset var product = structNew()>
                
                <cfquery name="qGetProduct" datasource="#variables.dsn#" 
password="#variables.DBpassword#" username="#variables.DBusername#">
                        SELECT product.*, product_description.*
                        FROM product 
                        INNER JOIN product_description ON product.product_id = 
product_description.product_id
                        WHERE 1=1
                        AND product.product_id = <cfqueryparam 
cfsqltype="cf_sql_integer" value="#arguments.product_id#">
                </cfquery>
                
                <cfset product = variables.utils.queryToStruct(qGetProduct)>
                
                <cfset getOptions = 
get_options_loaded(product_id=arguments.product_id)>
                
                <cfif getOptions.recordcount GT 0>
                        <cfset arrOptions = arrayNew(2)>
                        <cfloop query="getOptions">
                                <cfset arrOptions[getOptions.currentRow][1] = 
getOptions.product_options_id>
                                <cfset arrOptions[getOptions.currentRow][2] = 
getOptions.product_options_title>
                                <cfset arrOptions[getOptions.currentRow][3] = 
getOptions.stock_level>
                                <cfset arrOptions[getOptions.currentRow][4] = 
getOptions.reorder_level>
                                <cfset arrOptions[getOptions.currentRow][5] = 
getOptions.order_key>
                                <cfset arrOptions[getOptions.currentRow][6] = 
getOptions.isActive>
                                
                                <!--- define whether action is required on 
inventory --->
                                <cfif qGetProduct.track_stock AND 
(getOptions.stock_level EQ 0)>
                                        <cfset product.inventory_action_req = 
true>
                                </cfif>
                        </cfloop>
                        <cfset product.options = arrOptions>
                        
                <cfelse>
                
                        <!--- define whether action is required on inventory 
--->
                        <cfif qGetProduct.track_stock AND 
(qGetProduct.stock_level EQ 0)>
                                <cfset product.inventory_action_req = true>
                        </cfif>
                </cfif>
                
                <cfreturn product />
                
        </cffunction> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k

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

Reply via email to