This page contains a selection of ColdFusion custom functions (user defined functions or UDFs) that I wrote specifically for AbleCommerce.

These functions help make several tasks in AbleCommerce much easier.

  • GetNewID() - Gets and increments the next ID for an AC 5.5 Database Table.
  • UpdateMaxIDLookup() - Updates current 5.5 records in Max_ID_Lookup.
  • GetCustNum() - Gets a customer's CustNum.
  • getCategoryTrail() - This function returns the category trail for the object passed to it.
  • W2MUpdateField() - Updates W2M Custom Fields in the database.
  • W2MGetField() - Gets W2M Custom Fields in the database.
  • AdjustShipping() - Enters adjusted shipping information when an order is placed, including price, name, and SKU.
  • DisplayDiscounts() - This function will display the discount pricing for a product in a table. It can be edited to adjust the HTML output.

 
Download GetNewID() function: This function gets and increments the next ID for an AC 5.5 Database Table.


<!--- ============ GETNEWID() - GETS AND INCREMENTS THE NEXT ID FOR AN AC 5.5 DATABASE TABLE ============ --->
<cffunction name="GetNewID" hint="Gets and increments the next ID for an AC 5.5 Database Table." ReturnType="Numeric">

<!---
	#####################################################
	## Author: George Jaros                            ##
	## Script Name: ColdFusion GetNewID Function       ##
	## Copyright 2006 George Jaros & Web 2 Market      ##
	## www.georgejaros.com  www.web2market.com         ##
	## This code may be replicated as long as this     ##
	## header statement is included.  The Instructions ##
	## below may be removed.                           ##
	#####################################################
--->

	<cfargument name="aDSN" type="string" required="Yes">
	<cfargument name="TableName" type="string" required="Yes">
	<cfSET TableNames = "ADDRESSES,AFFILIATES,ATTRIBUTES,CATEGORIES,COUPONS,CURRENCIES,CUSTOMFIELDS,DISCOUNT_LINK_ASSN,DISCOUNT_MATRIX,DISCOUNTS,DOWNLOADS,EMAIL_CONTENTS,EMAIL_ENVELOPES,EMAILGATEWAYS,EMAILS,FILE_EMAIL_ASSN,FILES,GIFTCERTS,GROUPS,KIT_COMPONENT_ASSN,KIT_PRODUCT_ASSN,LICENSEKEYS,LICENSORS,LINKS,M_EVENTS,M_STOREGROUPS,M_STORES,M_TEMPLATES,M_VARIABLES,NOTICES,OPTIONS,ORDERFILES,ORDERITEMS,ORDERNOTES,ORDERS,ORDERSTATUSES,ORDERSTATUSRULES,OSD,PAYGATEWAYS,PAYMENTS,PAYMETHODS,PAYVALIDATORS,PRODUCTS,PROVINCES,RIGHTS,SHIPGATEWAYS,SHIPMATRIX,SHIPMENTS,SHIPMETH,SPECIALS,STORES,TAXCODES,TAXGATEWAYS,TAXRULES,TRACKING,TRANSACTIONS,USERS,VENDORS,WAREHOUSES,WEBPAGES,WISHLIST_PRODUCT_ASSN,WISHLISTS,WRAPGROUPS,WRAPSTYLES"> 
	<cfSET tableIDs = "ADDRESS_ID,AFFILIATE_ID,ATTRIBUTE_ID,CATEGORY_ID,COUPON_ID,CURRENCY_ID,CUSTOMFIELD_ID,DISCOUNTLINK_ID,DISCOUNTMATRIX_ID,DISCOUNT_ID,DOWNLOAD_ID,CONTENT_ID,ENVELOPE_ID,EMAILGATEWAY_ID,EMAIL_ID,FILEEMAIL_ID,FILE_ID,GIFTCERT_ID,GROUP_ID,COMPONENT_ID,KITPRODUCT_ID,LICENSEKEY_ID,LICENSOR_ID,LINK_ID,EVENT_ID,STOREGROUP_ID,STORE_ID,TEMPLATE_ID,VARIABLE_ID,NOTICE_ID,OPTION_ID,ORDERFILE_ID,ORDERITEM_ID,ORDERNOTE_ID,ORDER_ID,ORDERSTATUS_ID,ORDERSTATUSRULE_ID,OSD_ID,PAYGATEWAY_ID,PAYMENT_ID,PAYMETHOD_ID,PAYVALIDATOR_ID,PRODUCT_ID,PROVINCE_ID,RIGHT_ID,SHIPGATEWAY_ID,SHIPMATRIX_ID,SHIPMENT_ID,SHIPMETHOD_ID,SPECIAL_ID,STORE_ID,TAXCODE_ID,TAXGATEWAY_ID,TAXRULE_ID,TRACKING_ID,TRANSACTION_ID,USER_ID,VENDOR_ID,WAREHOUSE_ID,WEBPAGE_ID,WISHLISTPRODUCT_ID,WISHLIST_ID,WRAPGROUP_ID,WRAPSTYLE_ID">
<CFOUTPUT>
<CFSET tmpIntID = 0>
<CFIF IsDefined("TableName") AND Trim(TableName) NEQ "" >
	<CFSET intListNumber = ListFindNoCase(TableNames,TableName)>
	<CFIF intListNumber LTE 0>
		<CFRETURN 0><!--- TABLE NOT FOUND --->
	<CFELSE>
		<CFSET ID = ListGetAt(tableIDs,intListNumber)>
		<cftry>
			<!--- GET MAX PRODUCT ID --->
			<CFQUERY name="GetMaxID" datasource="#aDSN#">
				SELECT Max_ID
					FROM MAX_ID_LOOKUP
						WHERE TableName = '#UCase(TableName)#'
			</CFQUERY>
			<CFIF GetMaxID.RecordCount EQ 0>
				<CFQUERY name="GetMaxID" datasource="#aDSN#">
					SELECT Max(#ID#) AS Max_ID
						FROM #UCase(TableName)#
				</CFQUERY>
				<CFQUERY name="UpdateMaxID" datasource="#aDSN#">
					INSERT INTO MAX_ID_LOOKUP
						(Max_ID,TableName) VALUES (0,'#UCase(TableName)#')
				</CFQUERY>
			</CFIF>
			<!--- SET MAX PRODUCT ID --->
			<CFIF GetMaxID.Max_ID EQ "">
				<CFSET tmpIntID = 1>
			<CFELSE>
				<CFSET tmpIntID = GetMaxID.Max_ID + 1>
			</CFIF>
				
			<!--- UPDATE MAX PRODUCT ID --->
			<CFQUERY name="UpdateMaxID" datasource="#aDSN#">
				UPDATE MAX_ID_LOOKUP
					SET Max_ID = #tmpIntID#
						WHERE TableName = '#UCase(TableName)#'
			</CFQUERY>
			<CFRETURN tmpIntID><!--- SUCCESS --->
		<cfcatch>
			<CFRETURN -1><!--- UPDATE FAILED --->
		</cfcatch>
		</cftry>
	</CFIF>
<CFELSE>
	<CFRETURN -2><!--- NO TABLENAME DEFINED --->
</CFIF>
</CFOUTPUT>
</cffunction>
<!--- ============ END GETNEWID() ============ --->
  • GetNewID() - Gets and increments the next ID for an AC 5.5 Database Table.
  • UpdateMaxIDLookup() - Updates current 5.5 records in Max_ID_Lookup.
  • GetCustNum() - Gets a customer's CustNum.
  • getCategoryTrail() - This function returns the category trail for the object passed to it.
  • W2MUpdateField() - Updates W2M Custom Fields in the database.
  • W2MGetField() - Gets W2M Custom Fields in the database.
  • AdjustShipping() - Enters adjusted shipping information when an order is placed, including price, name, and SKU.
  • DisplayDiscounts() - This function will display the discount pricing for a product in a table. It can be edited to adjust the HTML output.
Back To Top
Download UpdateMaxIDLookup() function: This function updates current 5.5 records in Max_ID_Lookup. If you specify a table name only the record for that table will be updated.


<!--- ============ UPDATEMAXIDLOOKUP() - UPDATES THE MAX ID RECORDS IN AN AC 5.5 DATABASE ============ --->
<cffunction name="UpdateMaxIDLookup" hint="Updates current 5.5 records in Max_ID_Lookup">

<!---
	########################################################
	## Author: George Jaros                               ##
	## Script Name: ColdFusion UpdateMaxIDLookup Function ##
	## Copyright 2006 George Jaros & Web 2 Market         ##
	## www.georgejaros.com  www.web2market.com            ##
	## This code may be replicated as long as this        ##
	## header statement is included.  The Instructions    ##
	## below may be removed.                              ##
	########################################################
--->

	<cfargument name="aDSN" type="string" required="Yes">
	<cfargument name="TableName" type="string" required="No">
	<cfSET TableNames = "ADDRESSES,AFFILIATES,ATTRIBUTES,CATEGORIES,COUPONS,CURRENCIES,CUSTOMFIELDS,DISCOUNT_LINK_ASSN,DISCOUNT_MATRIX,DISCOUNTS,DOWNLOADS,EMAIL_CONTENTS,EMAIL_ENVELOPES,EMAILGATEWAYS,EMAILS,FILE_EMAIL_ASSN,FILES,GIFTCERTS,GROUPS,KIT_COMPONENT_ASSN,KIT_PRODUCT_ASSN,LICENSEKEYS,LICENSORS,LINKS,M_EVENTS,M_STOREGROUPS,M_STORES,M_TEMPLATES,M_VARIABLES,NOTICES,OPTIONS,ORDERFILES,ORDERITEMS,ORDERNOTES,ORDERS,ORDERSTATUSES,ORDERSTATUSRULES,OSD,PAYGATEWAYS,PAYMENTS,PAYMETHODS,PAYVALIDATORS,PRODUCTS,PROVINCES,RIGHTS,SHIPGATEWAYS,SHIPMATRIX,SHIPMENTS,SHIPMETH,SPECIALS,STORES,TAXCODES,TAXGATEWAYS,TAXRULES,TRACKING,TRANSACTIONS,USERS,VENDORS,WAREHOUSES,WEBPAGES,WISHLIST_PRODUCT_ASSN,WISHLISTS,WRAPGROUPS,WRAPSTYLES"> 
	<cfSET tableIDs = "ADDRESS_ID,AFFILIATE_ID,ATTRIBUTE_ID,CATEGORY_ID,COUPON_ID,CURRENCY_ID,CUSTOMFIELD_ID,DISCOUNTLINK_ID,DISCOUNTMATRIX_ID,DISCOUNT_ID,DOWNLOAD_ID,CONTENT_ID,ENVELOPE_ID,EMAILGATEWAY_ID,EMAIL_ID,FILEEMAIL_ID,FILE_ID,GIFTCERT_ID,GROUP_ID,COMPONENT_ID,KITPRODUCT_ID,LICENSEKEY_ID,LICENSOR_ID,LINK_ID,EVENT_ID,STOREGROUP_ID,STORE_ID,TEMPLATE_ID,VARIABLE_ID,NOTICE_ID,OPTION_ID,ORDERFILE_ID,ORDERITEM_ID,ORDERNOTE_ID,ORDER_ID,ORDERSTATUS_ID,ORDERSTATUSRULE_ID,OSD_ID,PAYGATEWAY_ID,PAYMENT_ID,PAYMETHOD_ID,PAYVALIDATOR_ID,PRODUCT_ID,PROVINCE_ID,RIGHT_ID,SHIPGATEWAY_ID,SHIPMATRIX_ID,SHIPMENT_ID,SHIPMETHOD_ID,SPECIAL_ID,STORE_ID,TAXCODE_ID,TAXGATEWAY_ID,TAXRULE_ID,TRACKING_ID,TRANSACTION_ID,USER_ID,VENDOR_ID,WAREHOUSE_ID,WEBPAGE_ID,WISHLISTPRODUCT_ID,WISHLIST_ID,WRAPGROUP_ID,WRAPSTYLE_ID">

<CFIF IsDefined("TableName") AND Trim(TableName) NEQ "" >
	<CFSET intListNumber = ListFindNoCase(TableNames,TableName)>
	<CFIF intListNumber LTE 0>
		<cfoutput>Table #UCase(TableName)# Does Not Exist</cfoutput>
	<CFELSE>
		<CFSET ID = ListGetAt(tableIDs,intListNumber)>
		<cftry>
			<cfquery name="theMax" datasource="#aDSN#">
			SELECT Max(#ID#) AS ID
				FROM #UCase(TableName)#	
			</cfquery>
			<cfquery name="CheckTable" datasource="#aDSN#">
			SELECT Max_ID
				FROM MAX_ID_LOOKUP WHERE TableName = '#UCase(TableName)#'
			</cfquery>
			<cfif CheckTable.RecordCount GT 0>
				<cfquery name="upd" datasource="#aDSN#">
				UPDATE MAX_ID_LOOKUP 
					SET Max_ID = #Val(theMax.ID)#	
						WHERE TableName = '#UCase(TableName)#'
				</cfquery>
			<cfelse>
				<cfquery name="upd" datasource="#aDSN#">
					INSERT INTO MAX_ID_LOOKUP (
						TableName,
						Max_ID
					)
					Values (
						'#UCase(TableName)#',
						#Val(theMax.ID)#
					)
				</cfquery>
			</cfif>
		<cfcatch>
			<cfoutput><p>UPDATE failed for #UCase(TableName)#</p></cfoutput>
		</cfcatch>
		</cftry>
	</CFIF>
<CFELSE>
	<cfSET k=1>
	<cftry>
		<cfloop list="#tableIDs#" index="ID">
			<cfquery name="theMax" datasource="#aDSN#">
			SELECT Max(#ID#) AS ID
				FROM #UCase(listGetAt(TableNames,k))#	
			</cfquery>
			<cfquery name="CheckTable" datasource="#aDSN#">
			SELECT Max_ID
				FROM MAX_ID_LOOKUP WHERE TableName = '#UCase(listGetAt(TableNames,k))#'	
			</cfquery>
			<cfif CheckTable.RecordCount GT 0>
				<cfquery name="upd" datasource="#aDSN#">
				UPDATE MAX_ID_LOOKUP 
					SET Max_ID = #Val(theMax.ID)#	
						WHERE TableName = '#UCase(listGetAt(TableNames,k))#'
				</cfquery>
			<cfelse>
				<cfquery name="upd" datasource="#aDSN#">
					INSERT INTO MAX_ID_LOOKUP (
						TableName,
						Max_ID
					)
					Values (
						'#UCase(listGetAt(TableNames,k))#',
						#Val(theMax.ID)#
					)
				</cfquery>
			</cfif>
			<p><cfoutput>#listGetAt(TableNames,k)#: #theMax.ID#</cfoutput></p>
			<cfSET k=k+1>
		</cfloop>
	<cfcatch>
		<cfoutput><p>List failed at #ID# | #listGetAt(TableNames,k)#</p></cfoutput>
	</cfcatch>
	</cftry>
</CFIF>
</cffunction>
<!--- ============ END UPDATEMAXIDLOOKUP() ============ --->
  • GetNewID() - Gets and increments the next ID for an AC 5.5 Database Table.
  • UpdateMaxIDLookup() - Updates current 5.5 records in Max_ID_Lookup.
  • GetCustNum() - Gets a customer's CustNum.
  • getCategoryTrail() - This function returns the category trail for the object passed to it.
  • W2MUpdateField() - Updates W2M Custom Fields in the database.
  • W2MGetField() - Gets W2M Custom Fields in the database.
  • AdjustShipping() - Enters adjusted shipping information when an order is placed, including price, name, and SKU.
  • DisplayDiscounts() - This function will display the discount pricing for a product in a table. It can be edited to adjust the HTML output.
Back To Top
Download GetCustNum() function: If you add a custom field the the Users table in AbleCommerce this function gets a customer's CustNum if you pass the customer's User_ID.


<!--- ============ GET CUSTNUM ============ --->
<CFFUNCTION name="GetCustNum" returntype="any" output="no" hint="If you add a custom field the the Users table in AbleCommerce this function gets a customer's CustNum if you pass the customer's User_ID.">

<!---
	#####################################################
	## Author: George Jaros                            ##
	## Script Name: ColdFusion GetCustNum Function     ##
	## Copyright 2006 George Jaros & Web 2 Market      ##
	## www.georgejaros.com  www.web2market.com         ##
	## This code may be replicated as long as this     ##
	## header statement is included.  The Instructions ##
	## below may be removed.                           ##
	#####################################################
--->

<CFARGUMENT name="intUserID" type="string" required="Yes">
	<CFTRY>
		<CFQUERY name="FindUser" datasource="#DataSource#">
			SELECT CustNum 
			FROM Users 
			WHERE User_ID = #intUserID#
		</CFQUERY>
		<CFCATCH>
			<CFRETURN "">
		</CFCATCH>
	</CFTRY>
	<CFRETURN Trim(FindUser.CustNum)>
</CFFUNCTION>
<!--- ============ END GET CUSTNUM ============ --->
  • GetNewID() - Gets and increments the next ID for an AC 5.5 Database Table.
  • UpdateMaxIDLookup() - Updates current 5.5 records in Max_ID_Lookup.
  • GetCustNum() - Gets a customer's CustNum.
  • getCategoryTrail() - This function returns the category trail for the object passed to it.
  • W2MUpdateField() - Updates W2M Custom Fields in the database.
  • W2MGetField() - Gets W2M Custom Fields in the database.
  • AdjustShipping() - Enters adjusted shipping information when an order is placed, including price, name, and SKU.
  • DisplayDiscounts() - This function will display the discount pricing for a product in a table. It can be edited to adjust the HTML output.
Back To Top
Download getCategoryTrail() function: This function returns the category trail for the object passed to it. The return value is a list of the parent categories for any given object's ID (Category, Product, Webpage, or Link).


<!--- ============ GET CATEGORY TRAIL ============ --->
<CFFUNCTION name="getCategoryTrail" returntype="any" output="no" hint="This function returns the category trail for the object passed to it.">

<!---
	#######################################################
	## Author: George Jaros                              ##
	## Script Name: ColdFusion getCategoryTrail Function ##
	## Copyright 2006 George Jaros & Web 2 Market        ##
	## www.georgejaros.com  www.web2market.com           ##
	## This code may be replicated as long as this       ##
	## header statement is included.  The Instructions   ##
	## below may be removed.                             ##
	#######################################################
--->

<CFARGUMENT name="Object_ID" type="numeric" required="Yes">
<CFARGUMENT name="ObjectType" type="numeric" required="Yes"><!--- 0 = Category, 1 = Product, 2 = Webpage --->
<CFARGUMENT name="IDs_Names" type="numeric" required="No" Default="0"><!--- 0 = IDs, 1 = Names --->
<CFARGUMENT name="UseThisCategory" type="boolean" required="No" Default="1"><!--- True uses the category of the currently displayed page.  False displays the first category that the object is found in. --->
<CFARGUMENT name="strDelimiter" type="string" required="No" Default=",">

<CFSET tmpDirCategoryID = 0>
<CFIF UseThisCategory>
	<CFIF IsDefined("intCategoryID")><CFSET tmpDirCategoryID = intCategoryID></CFIF>
<CFELSE>	
	<CFIF ObjectType EQ 0>
		<CFSET tmpDirCategoryID = Object_ID>
	<CFELSE>
		<CFQUERY name="GetCategory" datasource="#DataSource#">
			SELECT Object_ID1 
				FROM Object_Assn 
					WHERE Object_ID2 = #Object_ID# AND ObjectType1 = 0 AND ObjectType2 = #ObjectType# AND Visible = 3
		</CFQUERY>
		<CFIF GetCategory.RecordCount GT 0>
			<CFSET tmpDirCategoryID = GetCategory.Object_ID1>
		</CFIF>
	</CFIF>
</CFIF>
	
	<CFSET CatList = 0>
	<CFSET strDelimiter = Left(strDelimiter,1)>
	<CFIF IDs_Names EQ 0>
		<CFSET arrDirTree = token.getcnnSG().queryArrayAsObject("SELECT C.Category_ID FROM CATEGORY_ASSN CA LEFT JOIN CATEGORIES C ON CA.Parent_ID=C.Category_ID WHERE CA.Category_ID=" & tmpDirCategoryID & " AND C.Store_ID=" & token.getSID() & " AND CA.Parent_ID > 0 ORDER BY CA.ParentLevel")>
	<CFELSEIF IDs_Names EQ 1>
		<CFSET arrDirTree = token.getcnnSG().queryArrayAsObject("SELECT C.Name FROM CATEGORY_ASSN CA LEFT JOIN CATEGORIES C ON CA.Parent_ID=C.Category_ID WHERE CA.Category_ID=" & tmpDirCategoryID & " AND C.Store_ID=" & token.getSID() & " AND CA.Parent_ID > 0 ORDER BY CA.ParentLevel")>
	</CFIF>
	<CFIF ListUtils.hasResults(arrDirTree) >
		<CFSET arrDirLen = arrDirTree.length(javacast("boolean",true))>
		<CFLOOP index="i" from="0" to="#arrDirLen - 1#">
			<CFSET CatList = ListAppend(CatList,arrDirTree.getValue(javacast("int",0),javacast("int",i)),"#strDelimiter#")>
		</CFLOOP>
	</CFIF>
	
	<CFRETURN CatList>

</CFFUNCTION>
<!--- ============ END GET CATEGORY TRAIL ============ --->
  • GetNewID() - Gets and increments the next ID for an AC 5.5 Database Table.
  • UpdateMaxIDLookup() - Updates current 5.5 records in Max_ID_Lookup.
  • GetCustNum() - Gets a customer's CustNum.
  • getCategoryTrail() - This function returns the category trail for the object passed to it.
  • W2MUpdateField() - Updates W2M Custom Fields in the database.
  • W2MGetField() - Gets W2M Custom Fields in the database.
  • AdjustShipping() - Enters adjusted shipping information when an order is placed, including price, name, and SKU.
  • DisplayDiscounts() - This function will display the discount pricing for a product in a table. It can be edited to adjust the HTML output.
Back To Top
Download W2MUpdateField() function: This function updates a Custom Field in the AbleCommerce database.


<!--- =============== W2MUPDATEFIELD() - UPDATES W2M CUSTOM FIELDS IN THE DATABASE. =============== --->
<CFFUNCTION name="W2MUpdateField" returnType="string" output="no" hint="Updates a Custom Field in the AbleCommerce database.">

<!---
	#####################################################
	## Author: George Jaros                            ##
	## Script Name: ColdFusion W2MUpdateField Function ##
	## Copyright 2006 George Jaros & Web 2 Market      ##
	## www.georgejaros.com  www.web2market.com         ##
	## This code may be replicated as long as this     ##
	## header statement is included.  The Instructions ##
	## below may be removed.                           ##
	#####################################################
--->

<!--- 
	Add this function to pages where you want to update custom fields in the database.
	It is usually placed within the IF block where OBJECT.save(token) is called.  For example:
			if (objProduct.save(objToken) ){
				// HERE IS WHERE I ADD THE W2M CUSTOM FIELDS - GJAROS
				W2MUpdateField(objProduct.getID(),"Product_ID","Products","ExpectedDate",FORM.txtExpectedDate,"date");
				strMessage = "Product Saved";
			}else{
				strMessage = "Product Not Saved";
			}
	
	NOTE: Updates to fields with a value of NULL should always be type 'numeric'.
	
	Arguments are:
		W2MUpdateField(Object_ID as integer,ID_Name_In_DB as string,Table_Name_In_DB as string,Field_Name_In_DB as string,Value,Field_Type_In_DB as string)
--->
<CFARGUMENT name="Table_ID" type="any" required="true">
<CFARGUMENT name="ID_Name" type="string" required="true">
<CFARGUMENT name="TableName" type="string" required="true">
<CFARGUMENT name="FieldName" type="string" required="true">
<CFARGUMENT name="FieldValue" type="string" required="true">
<CFARGUMENT name="FieldType" type="string" required="false" default="string"> <!--- string, numeric, date, boolean --->
<CFARGUMENT name="KeyType" type="string" required="false" default="numeric"> <!--- string, numeric, date, boolean --->
<CFSWITCH expression="#FieldType#">
	<CFCASE value="numeric,boolean">
		<CFSWITCH expression="#KeyType#">
			<CFCASE value="string,date">
				<CFQUERY name="UpdateField" datasource="#DataSource#">
				UPDATE #UCase(TableName)#
					SET #FieldName# = <CFIF Trim(FieldValue) NEQ "">#FieldValue#<CFELSE>NULL</CFIF>
						WHERE #ID_Name# = '#Table_ID#'
				</CFQUERY>
			</CFCASE>
			<CFDEFAULTCASE>
				<CFQUERY name="UpdateField" datasource="#DataSource#">
				UPDATE #UCase(TableName)#
					SET #FieldName# = <CFIF Trim(FieldValue) NEQ "">#FieldValue#<CFELSE>NULL</CFIF>
						WHERE #ID_Name# = #Table_ID#
				</CFQUERY>
			</CFDEFAULTCASE>
		</CFSWITCH>
	</CFCASE>
	<CFDEFAULTCASE>
		<CFSWITCH expression="#KeyType#">
			<CFCASE value="string,date">
				<CFQUERY name="UpdateField" datasource="#DataSource#">
				UPDATE #UCase(TableName)#
					SET #FieldName# = <CFIF Trim(FieldValue) NEQ "">'#FieldValue#'<CFELSE>NULL</CFIF>
						WHERE #ID_Name# = '#Table_ID#'
				</CFQUERY>
			</CFCASE>
			<CFDEFAULTCASE>
				<CFQUERY name="UpdateField" datasource="#DataSource#">
				UPDATE #UCase(TableName)#
					SET #FieldName# = <CFIF Trim(FieldValue) NEQ "">'#FieldValue#'<CFELSE>NULL</CFIF>
						WHERE #ID_Name# = #Table_ID#
				</CFQUERY>
			</CFDEFAULTCASE>
		</CFSWITCH>
	</CFDEFAULTCASE>
</CFSWITCH>
</CFFUNCTION>
<!--- =============== END W2MUPDATEFIELD() =============== --->
  • GetNewID() - Gets and increments the next ID for an AC 5.5 Database Table.
  • UpdateMaxIDLookup() - Updates current 5.5 records in Max_ID_Lookup.
  • GetCustNum() - Gets a customer's CustNum.
  • getCategoryTrail() - This function returns the category trail for the object passed to it.
  • W2MUpdateField() - Updates W2M Custom Fields in the database.
  • W2MGetField() - Gets W2M Custom Fields in the database.
  • AdjustShipping() - Enters adjusted shipping information when an order is placed, including price, name, and SKU.
  • DisplayDiscounts() - This function will display the discount pricing for a product in a table. It can be edited to adjust the HTML output.
Back To Top
Download W2MGetField() function: This function gets a Custom Field in the AbleCommerce database.


<!--- =============== W2MGETFIELD() - GETS W2M CUSTOM FIELDS IN THE DATABASE. =============== --->
<CFFUNCTION name="W2MGetField" returnType="any" output="no" hint="Gets a Custom Field in the AbleCommerce database.">

<!---
	#####################################################
	## Author: George Jaros                            ##
	## Script Name: ColdFusion W2MGetField Function    ##
	## Copyright 2006 George Jaros & Web 2 Market      ##
	## www.georgejaros.com  www.web2market.com         ##
	## This code may be replicated as long as this     ##
	## header statement is included.  The Instructions ##
	## below may be removed.                           ##
	#####################################################
--->

<!--- 
	Add this function to pages where you want to get custom fields from the database.
	
	Arguments are:
		W2MGetField(Object_ID as integer,ID_Name_In_DB as string,Table_Name_In_DB as string,Field_Name_In_DB as string)
	Example:
		W2MGetField(objProduct.getID(),"Product_ID","Products","ExpectedDate");
--->
<CFARGUMENT name="Table_ID" type="any" required="true">
<CFARGUMENT name="ID_Name" type="string" required="true">
<CFARGUMENT name="TableName" type="string" required="true">
<CFARGUMENT name="FieldName" type="string" required="true">
<CFARGUMENT name="KeyType" type="string" required="false" default="numeric"> <!--- string, numeric, date, boolean --->
<CFSWITCH expression="#KeyType#">
	<CFCASE value="string,date">
		<CFQUERY name="GetField" datasource="#DataSource#">
		SELECT #FieldName# 
			FROM #UCase(TableName)#
				WHERE #ID_Name# = '#Table_ID#'
		</CFQUERY>
	</CFCASE>
	<CFDEFAULTCASE>
		<CFQUERY name="GetField" datasource="#DataSource#">
		SELECT #FieldName# 
			FROM #UCase(TableName)#
				WHERE #ID_Name# = #Table_ID#
		</CFQUERY>
	</CFDEFAULTCASE>
</CFSWITCH>
<CFRETURN Trim(evaluate("GetField.#FieldName#"))>
</CFFUNCTION>
<!--- =============== END W2MGETFIELD() =============== --->
  • GetNewID() - Gets and increments the next ID for an AC 5.5 Database Table.
  • UpdateMaxIDLookup() - Updates current 5.5 records in Max_ID_Lookup.
  • GetCustNum() - Gets a customer's CustNum.
  • getCategoryTrail() - This function returns the category trail for the object passed to it.
  • W2MUpdateField() - Updates W2M Custom Fields in the database.
  • W2MGetField() - Gets W2M Custom Fields in the database.
  • AdjustShipping() - Enters adjusted shipping information when an order is placed, including price, name, and SKU.
  • DisplayDiscounts() - This function will display the discount pricing for a product in a table. It can be edited to adjust the HTML output.
Back To Top
Download AdjustShipping() function: This function enters adjusted shipping information when an order is placed, including price, name, and SKU. This is useful for converting the SKU of a shipping method from something unfriendly (like 2_03) to something friendly (like UPS_Grnd). It is also useful for adjusting the price of the shipping method or the name. You must pass both the Shipment ID and the Order ID.



<CFFUNCTION name="AdjustShipping" returnType="any" hint="Enters adjusted shipping information when an order is placed, including price, name, and SKU.">

<!---
	#####################################################
	## Author: George Jaros                            ##
	## Script Name: ColdFusion AdjustShipping Function ##
	## Copyright 2007 George Jaros & Web 2 Market      ##
	## www.georgejaros.com  www.web2market.com         ##
	## This code may be replicated as long as this     ##
	## header statement is included.  The Instructions ##
	## below may be removed.                           ##
	#####################################################
	
	NOTE: In order to use this function effectively on the Shipmeth.cfm page, especially if you are adjusting the shipping charges,
		you must comment out the objBasket.calculateShipping() lines in paymeth.cfm.  Otherwise AbleCommerce will re-calculate shipping 
		charges on the paymeth page, overwriting any adjustments you have made.
--->

   <CFARGUMENT name="objShipment" type="any" required="true">
   <CFARGUMENT name="strNewName" type="string" required="false" default="">
   <CFARGUMENT name="decNewCost" type="numeric" required="false" default="-1">
   <CFARGUMENT name="strNewSKU" type="string" required="false" default="">

	<CFQUERY name="GetShippingOI" datasource="#DataSource#">
		SELECT OrderItem_ID FROM ORDERITEMS WHERE Order_ID=#objShipment.getOrderID()# AND Shipment_ID=#objShipment.getShipmentID()# AND Product_ID = -2 AND SKU <> 'HANDLING'
	</CFQUERY>
	<CFIF GetShippingOI.RecordCount GT 0>
		<CFQUERY name="UpdateShippingCost" datasource="#DataSource#">
			UPDATE ORDERITEMS
				SET 
					<CFIF decNewCost GTE 0>ExtPrice = #decNewCost#, UnitPrice = #decNewCost#, </CFIF>
					<CFIF Trim(strNewName) NEQ "">Name = '#strNewName#', </CFIF>
					<CFIF Trim(strNewSKU) NEQ "">SKU = '#strNewSKU#', </CFIF>
					Shipment_ID = Shipment_ID
				WHERE Order_ID=#objShipment.getOrderID()# AND Shipment_ID=#objShipment.getShipmentID()# AND Product_ID = -2 AND SKU <> 'HANDLING'
		</CFQUERY>
	<CFELSE>
		<CFSET intOrderItemID = GetNewID(DataSource,"ORDERITEMS")>
		<CFQUERY name="UpdateShippingCost" datasource="#DataSource#">
			INSERT INTO ORDERITEMS
				(
					OrderItem_ID,
					Shipment_ID,
					Order_ID,
					Product_ID,
					Wishlist_ID,
					Warehouse_ID,
					Parent_ID,
					Name,
					SKU,
					Quantity,
					UnitPrice,
					UnitWeight,
					ExtPrice,
					ExtWeight,
					ExtPriceAdj,
					ExtWeightAdj,
					Shippable,
					TaxCode_ID,
					StockAdj,
					WrapStyle_ID,
					OrderBy
				) VALUES (
					#intOrderItemID#,
					#objShipment.getShipmentID()#,
					#objShipment.getOrderID()#,
					-2,
					0,
					0,
					#intOrderItemID#,
					<CFIF Trim(strNewName) NEQ "">'#strNewName#'<CFELSE>'#objShipment.getDisplayName()#'</CFIF>, 
					<CFIF Trim(strNewSKU) NEQ "">'#strNewSKU#'<CFELSE>'#objShipment.getSGObjectID()#_#objShipment.getShipMethodCode()#'</CFIF>, 
					1,
					<CFIF decNewCost GTE 0>#decNewCost#<CFELSE>0</CFIF>, 
					0,
					<CFIF decNewCost GTE 0>#decNewCost#<CFELSE>0</CFIF>, 
					0,
					0,
					0,
					0,
					0,
					0,
					0,
					30
				)
		</CFQUERY>
	</CFIF>

</CFFUNCTION>
<!--- ============ END W2M ADJUST SHIPPING ============ --->
  • GetNewID() - Gets and increments the next ID for an AC 5.5 Database Table.
  • UpdateMaxIDLookup() - Updates current 5.5 records in Max_ID_Lookup.
  • GetCustNum() - Gets a customer's CustNum.
  • getCategoryTrail() - This function returns the category trail for the object passed to it.
  • W2MUpdateField() - Updates W2M Custom Fields in the database.
  • W2MGetField() - Gets W2M Custom Fields in the database.
  • AdjustShipping() - Enters adjusted shipping information when an order is placed, including price, name, and SKU.
  • DisplayDiscounts() - This function will display the discount pricing for a product in a table. It can be edited to adjust the HTML output.
Back To Top
Download DisplayDiscounts() function: This function will display the discount pricing for a product in a table. It can be edited to adjust the HTML output. If you call this function from one of the product display pages (product1.cfm, etc.) you can add Wizard fields to the ac_product_01.wzf file (or _02.wzf or _03.wzf) for SHOWDISCOUNTTITLE (show or hide the name of the discount), PRICETITLE (the title of the price column), or MAXDISCOUNTTEXT (text that should display for quantities that exceed the maximum listed for the discount).


<!--- ============ W2M DISPLAY DISCOUNTS ============ --->
<CFFUNCTION name="DisplayDiscounts" ReturnType="string" hint="This function will display the discount pricing for a product in a table.  It can be edited to adjust the HTML output.">

<!---
	#######################################################
	## Author: George Jaros                              ##
	## Script Name: ColdFusion DisplayDiscounts Function ##
	## Copyright 2006 George Jaros & Web 2 Market        ##
	## www.georgejaros.com  www.web2market.com           ##
	## This code may be replicated as long as this       ##
	## header statement is included.  The Instructions   ##
	## below may be removed.                             ##
	#######################################################
--->

<CFARGUMENT name="objProductTMP" required="Yes">
<CFARGUMENT name="objCustomerTMP" required="Yes">
<CFARGUMENT name="ShowTitle" required="No" type="boolean" default="#wizard.get("SHOWDISCOUNTTITLE",0)#">
<CFARGUMENT name="strPriceTitle" required="No" type="boolean" default="#wizard.get("PRICETITLE","YOUR PRICE")#">
<CFARGUMENT name="strMaxDiscountText" required="No" type="boolean" default="#wizard.get("MAXDISCOUNTTEXT",0)#">

<CFSET CustomerGroupList = objCustomerTMP.getGroups().getList()>
<CFSET lstCatList = getCategoryTrail(objProductTMP.getID(),1)>
<CFQUERY name="GetIndividualDiscounts" datasource="#DataSource#">
SELECT D.* 
FROM DISCOUNTS D INNER JOIN DISCOUNT_MATRIX M ON D.Discount_ID = M.Discount_ID
WHERE (
	D.Discount_ID IN ( #objProductTMP.getDiscounts().getList()# )
	OR 
	D.Discount_ID IN ( SELECT Discount_ID FROM CATEGORY_DISCOUNT_ASSN WHERE Category_ID IN (#lstCatList#) )
	) AND D.Store_ID = #token.getStore().getID()# AND M.MinQty <= 1
</CFQUERY>
<CFIF objProductTMP.getSpecials().getCount() GT 0 AND GetIndividualDiscounts.RecordCount EQ 0>
	<CFSET ProductPrice = objProductTMP.GetExtPrice(objCustomerTMP.getGroups().getList() )>
<CFELSEIF objProductTMP.getSpecials().getCount() GT 0 AND GetIndividualDiscounts.RecordCount NEQ 0>
	<CFSET ProductPrice = objProductTMP.GetUnitPrice()>
	<CFLOOP from="0" to="#objProductTMP.getSpecials().getCount() - 1#" index="idx">
		<CFSET tmpSpecial = objProductTMP.getSpecials().getElementAt(javacast("int",idx))>
		<CFSET tmpPrice = tmpSpecial.getPrice()>
		<CFSET tmpGroups = tmpSpecial.getGroups()>
		<CFIF ListCompare(tmpGroups,CustomerGroupList) OR tmpGroups EQ "" AND tmpSpecial.getStartDT() LTE Now() AND DateAdd("d",1,tmpSpecial.getEndDT()) GTE Now()>
			<CFSET ProductPrice = Min(tmpPrice,ProductPrice)>
		</CFIF>
	</CFLOOP>
<CFELSE>
	<CFSET ProductPrice = objProductTMP.GetUnitPrice()>
</CFIF>
<CFSET tmpDiscount = createObject("java","com.ablecommerce.ac5.discount.Discount")>

<CFQUERY name="GetDiscounts" datasource="#DataSource#">
SELECT * 
FROM DISCOUNTS
WHERE (
	Discount_ID IN ( #objProductTMP.getDiscounts().getList()# )
	OR 
	Discount_ID IN ( SELECT Discount_ID FROM CATEGORY_DISCOUNT_ASSN WHERE Category_ID IN (#lstCatList#) )
	) AND Store_ID = #token.getStore().getID()#
</CFQUERY>

<CFSET ShowDiscounts = False>
<CFSET ShowOnlyOnePrice = True>
<CFIF GetDiscounts.RecordCount EQ 0>
		<CFSET ShowDiscounts = True>
		<CFSET ShowOnlyOnePrice = True>
<CFELSE>
	<CFLOOP query="GetDiscounts">
		<CFIF ListCompare(GetDiscounts.Groups,CustomerGroupList) OR GetDiscounts.Groups EQ "">
			<CFSET ShowDiscounts = True>
			<CFSET ShowOnlyOnePrice = False>
		</CFIF>
	</CFLOOP>
</CFIF>
<CFIF ShowDiscounts>
<CFOUTPUT>
<table class="MenuBox" cellspacing="0" style="width:auto;" align="center">
<tr>
	<th class="MenuBox">Pricing</th>
</tr>
<tr>
	<td class="MenuBox" style="text-align:center;">

<CFIF ShowOnlyOnePrice EQ True OR ProductPrice EQ 0>
	<table class="MenuBox" style="border:none;" cellspacing="0" align="center">
		<tr>
			<td class="MenuBox" style="text-align:center;font-size:11px;" colspan="2"><b>#strPriceTitle#</b></td>
			<td class="MenuBox">#locale.formatCurrency(store, ProductPrice, "<BR>", JavaCast("boolean",true) )#</td>
		</tr>
	</table>
<CFELSE>
	<CFLOOP query="GetDiscounts">
	<CFSET tmpDiscount.Load(token,GetDiscounts.Discount_ID)>
	<CFIF ListCompare(tmpDiscount.getGroups(),CustomerGroupList) OR tmpDiscount.getGroups() EQ "">
		<CFQUERY name="GetDiscountMatrix" datasource="#DataSource#">
		SELECT * 
			FROM DISCOUNT_MATRIX
				WHERE Discount_ID = #tmpDiscount.getDiscountID()#
					ORDER BY MinQty Asc
		</CFQUERY>
		<CFSET intDiscountType = Int(GetDiscounts.DiscountType)>
		<table class="MenuBox" <CFIF NOT ShowTitle>style="border:none;" </CFIF>cellspacing="0">
		<CFIF ShowTitle>
			<tr>
				<th class="MenuBox" colspan="4">#tmpDiscount.getDisplayName()#</th>
			</tr>
		</CFIF>
			<tr>
				<td class="MenuBox" style="text-align:center;font-size:11px;width:50%;" colspan="3"><b>QTY</b></td>
				<td class="MenuBox" style="text-align:left;font-size:11px;width:50%;"><b>PRICE</b></td>
			</tr>
				<CFIF intDiscountType EQ 0>
					<CFSET tmpMinQty = Int(GetDiscountMatrix.MinQty)>
					<CFSET tmpMaxQty = tmpMinQty - 1>
					<CFIF tmpMaxQty EQ 0>
						<CFSET tmpMaxQty = "--">
					</CFIF>
				<CFELSE>
					<CFSET tmpMinQty = Int(GetDiscountMatrix.MinQty/ProductPrice) - 1>
					<CFSET tmpMaxQty = tmpMinQty - 1>
					<CFIF tmpMaxQty EQ 0>
						<CFSET tmpMaxQty = "--">
					</CFIF>
				</CFIF>
				<CFIF tmpMinQty GT 1>
					<CFSET tmpMaxQty = tmpMaxQty>
	<!--- This Section Displays Min Qty and Max Qty in one cell. --->
	<!---
				<tr>
					<CFIF tmpMaxQty EQ "--" OR tmpMaxQty EQ 1>
						<td class="MenuBox" nowrap style="text-align:center;" colspan="3">1<CFIF tmpMaxQty EQ "--">+</CFIF></td>
					<CFELSE>
						<td class="MenuBox" nowrap style="text-align:center;" colspan="3">1 - #NumberFormat(tmpMaxQty,",")#</td>
					</CFIF>
					<td class="MenuBox" nowrap style="text-align:left;padding-left:10px;">#locale.formatCurrency(store, ProductPrice, "<BR>", JavaCast("boolean",true) )##/td>
				</tr>
	--->
	<!--- This Section Displays Min Qty and Max Qty in separate cells. --->
				<tr>
					<CFIF tmpMaxQty EQ "--" OR tmpMaxQty EQ 1>
						<td class="MenuBox" nowrap style="text-align:center;" colspan="3">1<CFIF tmpMaxQty EQ "--">+</CFIF></td>
					<CFELSE>
						<td class="MenuBox" nowrap style="text-align:center;">1</td>
						<td class="MenuBox" nowrap style="text-align:center;"> - </td>
						<td class="MenuBox" nowrap style="text-align:center;">#NumberFormat(tmpMaxQty,",")#</td>
					</CFIF>
					<td class="MenuBox" nowrap style="text-align:left;padding-left:10px;">#locale.formatCurrency(store, ProductPrice, "<BR>", JavaCast("boolean",true) )#</td>
				</tr>
				</CFIF>
			<CFLOOP query="GetDiscountMatrix">
				<CFIF intDiscountType EQ 0>
					<CFSET tmpMinQty = Int(GetDiscountMatrix.MinQty)>
					<CFSET tmpMaxQty = Int(GetDiscountMatrix.MaxQty)>
					<CFIF tmpMaxQty EQ 0>
						<CFSET tmpMaxQty = "--">
					</CFIF>
				<CFELSE>
					<CFSET tmpMinQty = Ceiling(GetDiscountMatrix.MinQty/ProductPrice)>
					<CFSET tmpMaxQty = Int(GetDiscountMatrix.MaxQty/ProductPrice)>
					<CFIF tmpMaxQty EQ 0>
						<CFSET tmpMaxQty = "--">
					</CFIF>
				</CFIF>
				<CFIF tmpMinQty LTE tmpMaxQty OR tmpMaxQty EQ "--">
				<tr>
	<!--- This Section Displays Min Qty and Max Qty in one cell. --->
	<!---
					<CFIF tmpMaxQty EQ "--" OR tmpMaxQty EQ tmpMinQty>
						<td class="MenuBox" nowrap style="text-align:center;" colspan="3">#NumberFormat(tmpMinQty,",")#<CFIF tmpMaxQty EQ "--">+</CFIF></td>
					<CFELSE>
						<td class="MenuBox" nowrap style="text-align:center;" colspan="3>#NumberFormat(tmpMinQty,",")# - #NumberFormat(tmpMaxQty,",")#</td>
					</CFIF>
					<CFIF GetDiscountMatrix.IsPercent EQ 1>
						<td class="MenuBox" nowrap style="text-align:left;padding-left:10px;">#locale.formatCurrency(store, ProductPrice * ((100 - GetDiscountMatrix.Amount)/100), "<BR>", JavaCast("boolean",true) )#</td>
					<CFELSE>
						<td class="MenuBox" nowrap style="text-align:left;padding-left:10px;">#locale.formatCurrency(store, ProductPrice - GetDiscountMatrix.Amount, "<BR>", JavaCast("boolean",true) )#</td>
					</CFIF>
	--->
	<!--- This Section Displays Min Qty and Max Qty in separate cells. --->
					<CFIF tmpMaxQty EQ "--" OR tmpMaxQty EQ tmpMinQty>
						<td class="MenuBox" nowrap style="text-align:center;" colspan="3">#NumberFormat(tmpMinQty,",")#<CFIF tmpMaxQty EQ "--">+</CFIF></td>
					<CFELSE>
						<td class="MenuBox" nowrap style="text-align:center;">#NumberFormat(tmpMinQty,",")#</td>
						<td class="MenuBox" nowrap style="text-align:center;"> - </td>
						<td class="MenuBox" nowrap style="text-align:center;">#NumberFormat(tmpMaxQty,",")#</td>
					</CFIF>
					<CFIF GetDiscountMatrix.IsPercent EQ 1>
						<td class="MenuBox" nowrap style="text-align:left;padding-left:10px;">#locale.formatCurrency(store, ProductPrice * ((100 - GetDiscountMatrix.Amount)/100), "<BR>", JavaCast("boolean",true) )#</td>
					<CFELSE>
						<td class="MenuBox" nowrap style="text-align:left;padding-left:10px;">#locale.formatCurrency(store, ProductPrice - GetDiscountMatrix.Amount, "<BR>", JavaCast("boolean",true) )#</td>
					</CFIF>
				</tr>
				</CFIF>
			</CFLOOP>
<!--- This Section Displays Over Max Qty, please call text from wizard. --->
			<CFSET txtMaxDiscount = Trim(ReplaceNoCase(strMaxDiscountText,"[MaxQty]",tmpMaxQty,"ALL"))>
			<CFIF txtMaxDiscount NEQ "" AND tmpMaxQty NEQ "--">
			<tr>
				<td colspan="4" class="MenuBox">#txtMaxDiscount#</td>
			</tr>
			</CFIF>
		</table>
	</CFIF>
	</CFLOOP>
</CFIF>
	</td>
</tr>
</table>
</CFOUTPUT>
</CFIF>
</CFFUNCTION>
<!--- ============ END W2M DISPLAY DISCOUNTS ============ --->
  • GetNewID() - Gets and increments the next ID for an AC 5.5 Database Table.
  • UpdateMaxIDLookup() - Updates current 5.5 records in Max_ID_Lookup.
  • GetCustNum() - Gets a customer's CustNum.
  • getCategoryTrail() - This function returns the category trail for the object passed to it.
  • W2MUpdateField() - Updates W2M Custom Fields in the database.
  • W2MGetField() - Gets W2M Custom Fields in the database.
  • AdjustShipping() - Enters adjusted shipping information when an order is placed, including price, name, and SKU.
  • DisplayDiscounts() - This function will display the discount pricing for a product in a table. It can be edited to adjust the HTML output.
Back To Top
eXTReMe Tracker