StarterCart 1.0 Beta Documentation: External Products

External Products

While StarterCart comes with its own built-in product management, it is also possible to use products from outside of StarterCart. In fact, you can use multiple sources for products (which may or may not include the built-in product management) in the same cart program at the same time.

Note that the "ProductIdentifier" should be a ":" delimited string. The first part of the string should identify the source of the products (the "source identifier"). For example, products handled internally by StarterCart use "prod", resulting in a ProductIdentifier like "prod:1" or "prod:12345". Each product source should have its own unique identifier here. The string should only contain letters (no numbers or special characters).

API Integration

If you are using only the StarterCart API, then the only thing that matters to StarterCart is the the required information is passed in for a product being purchased. The CFC docs for the various pieces of the API will describe what is needed in each case. Generally, the checkout needs only integration with the "addItem" method.

If you need to modify product information and have that reflected in people's cart, the API can handle that as well. Simply call the "updateItems" method, which has the following arguments:

This method should be called any time that a product is edited in the external product management system.

getCartItemStruct

While this isn't strictly necessary, we would highly recommend adding this method to the component used to manage products externally (or to a facade thereof). Use the method of the same name in "Productcs.cfc" as an example:

<cffunction name="getCartItemStruct" access="public" returntype="any" output="false" hint="">
	<cfargument name="ProductID" type="numeric" required="yes">
	
	<cfset var qProduct = getProduct(arguments.ProductID)>
	<cfset var sResult = StructNew()>
	
	<cfoutput query="qProduct">
		<cfscript>
		sResult["ProductIdentifier"] = "prod:#ProductID#";
		sResult["Price"] = Price;
		sResult["ProductName"] = "#ProductName#";
		sResult["LinkAdmin"] = "/admin/cart/product-edit.cfm?id=#ProductID#";
		sResult["LinkPublic"] = "/products/product.cfm?id=#ProductID#";
		</cfscript>
	</cfoutput>
	
	<cfreturn sResult>
</cffunction>

The method should produce a method that returns a structure with the keys matching the arguments listed for "updateItems" above as well as "addItem" and other methods.

Integration with Full Cart

If you are using the full cart then you will need to use "updateItems" when you update your cart as well as adding a method to "_cart.cfc" to integrate the checkout.

To add the method, copy the "getproductData_prod" from "/checkout/__cart.cfc" and paste it into "_cart.cfc". Change the "prod" part of the method name to the source identifier for your product source and then change the method accordingly.

<cffunction name="getproductData_prod" access="private" returntype="any" output="false" hint="I return a structure of the product information for the given product using StartCart's built-in products.">
	<cfargument name="prodident" type="string" required="yes">
	<cfargument name="Quantity" type="numeric" default="1">
	
	<cfset var sResult = variables.StarterCart.Products.getCartItemStruct(arguments.prodident)>
	
	<cfset sResult["Quantity"] = arguments.Quantity>
	
	<cfreturn sResult>
</cffunction>

So, if your source identifier was "ticket" (perhaps you need to manage even tickets sperately), then your "_cart.cfc" might look like this:

<cfcomponent displayname="Site Cart Controller" extends="__cart" output="no">

<cfset loadExternalVars("Tickets")>

<cffunction name="getproductData_ticket" access="private" returntype="any" output="false" hint="I return a structure of the product information for the given product using StartCart's built-in products.">
	<cfargument name="prodident" type="string" required="yes">
	<cfargument name="Quantity" type="numeric" default="1">
	
	<cfset var sResult = variables.Tickets.getCartItemStruct(arguments.prodident)>
	
	<cfset sResult["Quantity"] = arguments.Quantity>
	
	<cfreturn sResult>
</cffunction>

</cfcomponent>