Hi,
I have an application which worked fine, until sizes were introduced for
products (yeah, I know, a small oversight!). The following code snippet is
passed the appropriate parameters (id, name, price, quantity, size etc). The
code I use to add a product to the cart is as follows (sorry, its pretty
long..):
<cfif not isdefined("session.cart")>
<cfset session.cart = structnew()>
</cfif>
<cfset tempvalue =
listtoarray('#attributes.id#,#attributes.name#,#attributes.price#,#attribute
s.quantity#,#attributes.size#')>
<!---If item is not yet in cart, simply add it to the basket--->
<cfif structKeyExists(session.cart, attributes.name) is false>
<cfset tempinsert =
StructInsert(session.cart,attributes.name,tempvalue)>
<cfelse>
<!---If item is already in cart, are we doing an update?--->
<cfif isdefined("attributes.update")><!---user has not added new
product, just changing quantity currently in cart--->
<cfset tempvalue[4]=attributes.quantity>
<cfelse><!---user is adding new product to cart--->
<!---Just update quantity on existing product, instead of
adding a new row--->
<cfset
tempvalue[4]=session.cart[attributes.name][4]+attributes.quantity>
</cfif>
<cfset tempupdate =
StructUpdate(session.cart,attributes.name,tempvalue)>
</cfif>
If an item is already in cart I want to check its size, if sizes are same
(eg both medium and both same product) then just update quantity (ie do not
add new product to cart). If products are same but sizes different (eg
small and a medium) then I want to add new entry in cart for this
product/size.
Hope this is clear!
Any help greatly appreciated.
Nick Betts..
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists