Hi Geoff, In a rush, but couple of quick comments.
The User is a cfc not a struct so your type is wrong: > <cfargument name="user" type="struct" required="yes"/> No real reason to pass address as a struct at all. If you're getting started I'd just pass User to the address function and get it to do things like User.getAddress1(), User,getCity() and so on. If you want to be cleverer and compose User of an address object, I'd say Address = User.getAddress() which would return the address object. Then I'd use the address objects getters and setters to Address.getAddress1(), Address.getCity(), etc. I'd just start with a User object and refactor (change) your code to add the composed address object later. Sure you'll get more detailed response from the rest of the crew! Best Wishes Peter On 10/3/06 11:35 AM, "Geoff Parkhurst" <[EMAIL PROTECTED]> wrote: >> Is it just me or has this list gone very quiet? > > Well, I have a question if everyone's twiddling their thumbs at the moment? > Here goes... > > I have a cfc stored in the session scope for a shopping cart app. It stores > various things, but I'll focus on the address bit. The user cfc has a > getAddress() function which returns a struct of the punter's address. > > I have another cfc stored in the application scope. It should do all the > checkout stuff for the cart(*). One of its functions is (will be...) > doCheckout() which expects a struct of all the user's info. > > Within this checkout.cfc, there is a private function, > insertAddressIntoDatabase(). It takes a struct and shoves it in the > database, returning the id of the row inserted. It should be called from > within doCheckout(), but never on its own. > > Now, I'm a little fuzzy on how these cfcs talk to each other. Obviously I > need to pass the user cfc into the checkout cfc, but I'm not sure how... If > I pass in the user struct entirely, am I right in accessing it within the > arguments of the doCheckout function? > > Vague code below. Does that look alright to everyone? > > Many thanks for any input. > > Geoff > > (*) I wondered if the user.cfc should have the ability to check itself out > (see PetMarket), but that didn't seem right to me... > > <cfcomponent displayName="Checkout" output="false" hint="Checkout CFC"> > > <cffunction name="doChecout" access="public" returntype="struct"> > <cfargument name="user" type="struct" required="yes"/> > <cfset var shippingid=""/> > <cfset shippingid=insertAddressIntoDatabase(user.getAddress())> > <!--- Do various other things, including billing the card ---> > <cfreturn SomeStructWithOrderDetails /> > </cffunction> > > <cffunction name="insertAddressIntoDatabase" access="private" > returntype="numeric"> > <cfargument name="address" type="struct" required="yes"/> > <cfset var shippingid=""> > <!--- Stick address in db, return id ---> > <cfreturn shippingid/> > > </cfcomponent> > > <cfcomponent displayName="User" output="false" hint="User CFC, probably > stored in session scope"> > > <cffunction name="init" access="public" returntype="user" > hint="Constructor for user CFC"> > <cfset variables.address=structnew()/> > <cfset variables.address.firstname=""/> > </cffunction> > > <cffunction name="getAddress" access="public" returntype="struct"> > <cfreturn variables.address/> > </cffunction> > > </cfcomponent> > > > > ______________________________________________________________________ > This email has been scanned by the MessageLabs Email Security System. > For more information please visit http://www.messagelabs.com/email > ______________________________________________________________________ > > > You are subscribed to cfcdev. To unsubscribe, please follow the instructions > at http://www.cfczone.org/listserv.cfm > > CFCDev is supported by: > Katapult Media, Inc. > We are cool code geeks looking for fun projects to rock! > www.katapultmedia.com > > An archive of the CFCDev list is available at > www.mail-archive.com/[email protected] > You are subscribed to cfcdev. To unsubscribe, please follow the instructions at http://www.cfczone.org/listserv.cfm CFCDev is supported by: Katapult Media, Inc. We are cool code geeks looking for fun projects to rock! www.katapultmedia.com An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
