<!--- 
 Filename: MerchProviderCFC.cfc
 Author: Nate Weiss (NMW)
 Purpose: Creates a ColdFusion Component that supplies data about products
--->

<cfcomponent hint="Provides data about merchandise records." output="false">
 
<!--- getMerchList() function --->
<cffunction name="merchRecordsetProvider" returnType="query" access="remote" 
           hint="Returns a recordset of all products in the Merchandise table."
           output="false">

  <cfset var merchQuery = "">
  
	<!--- Query the database for merchandise records --->
	<cfquery name="merchQuery" datasource="ows">
	SELECT MerchID, MerchName
	FROM Merchandise
	ORDER BY MerchName
	</cfquery>
	
	<!--- Return the query --->
	<cfreturn merchQuery>
</cffunction>


<!--- merchDetailProvider() function --->
<cffunction name="merchDetailProvider" returnType="query" access="remote"
 hint="Returns details about a particular item in the Merchandise table."
 output="false">

	<!--- MerchID argument (required) ---> 
	<cfargument name="merchID" type="numeric" required="Yes"
	hint="The ID number of the desired Merchandise record.">
	
	<cfset var merchQuery = "">
	
	<!--- Query the database for merchandise records --->
	<cfquery name="merchQuery" datasource="ows" maxrows="1">
	SELECT MerchID, MerchName, MerchDescription, ImageNameSmall, MerchPrice
	FROM Merchandise 
	WHERE MerchID = #ARGUMENTS.merchID#
	</cfquery>
	
	<!--- Format the MerchPrice column in the appropriate currency format --->
	<!--- (It’s easier to do this with ColdFusion than with ActionScript) --->
	<cfset merchQuery.lerchPrice = lsCurrencyFormat(merchQuery.MerchPrice)>
	
	<!--- Return the query --->
	<cfreturn merchQuery> 
 </cffunction>

</cfcomponent>
