Hi Everyone
I am building a site that requires multiple listings each with their own shopping cart.
Items can be ordered only from that business(1)and i need a way to stop surfers from going to another business and adding items from their business to the cart of business(1)
At the moment if i go from business(1)'s cart contents and then go to the cart contents for another business those items show up in the cart
I guess what i need is a way to setup business(1) cart and stop items being added from another business to that cart and when they go to another business it starts a completely new cart for that individual business

the code i am using to populate the array follows:

<!--- ADD  PRODUCT TO CART ARRAY ROUTINE--->
    <cfif IsDefined("btn_add")>
<!---is this ID already in the enquiry--->
    <cfset thisID = #form.ID#>
    <!---check that this ID is not already existing in the enquiryContents--->
        <cfloop from="1" to="#arrayLen(session.shoppingcart)#" index="i">
        <cfif session.shoppingcart[i].ID eq #thisID#>
<!---If this ID exists in enquirycontents - send to error page IF NOT carry on and add to array--->      
        <cflocation url="shopCartItemExists.cfm?ID=#getlistinginfo.ID#"> 
        </cfif>
      </cfloop>
    <a href="%5C">
    <cfset temp = arrayAppend(session.shoppingCart, structNew())>
    <cfset session.shoppingcart[arrayLen(session.shoppingcart)].custID = #getlistinginfo.ID#>
    <cfset session.shoppingcart[arrayLen(session.shoppingcart)].ID = #form.ID#>
    <cfset session.shoppingcart[arrayLen(session.shoppingcart)].prodnum = #getstock.prodnum#>
    <cfset session.shoppingcart[arrayLen(session.shoppingcart)].product = #getstock.product#>
    <cfset session.shoppingcart[arrayLen(session.shoppingcart)].price = #getstock.price#>
    <cfset session.shoppingcart[arrayLen(session.shoppingcart)].quantity = #form.Quantity#>
    <cfset session.shoppingcart[arrayLen(session.shoppingcart)].weight= #getstock.packweight#>
      <cflocation url="shopCartContents.cfm?custID=#getlistinginfo.ID#">
      </a>
  </cfif>
<!---FINISH ADDING TO CART ARRAY ROUTINE

Any help would be greatly appreciated
cheers and thanks in advance
Grabit

Youch! OK, you have two separate businesses that are apparently sharing an application, because they are now sharing sessions. Are these sites on different URL's? What is the application "name" in the root Application.cfc/cfm of each site? Are they different?

Hi Cutter and thanks for the reply
No the site has multiple listings for individual businesses that all have a shopping cart
Can I?
If when i set up the cart for say customer ID 1, add that ID to the neme of the new cart being set up.
<cfset temp = arrayAppend(session.shoppingCart(put the cust ID in here), structNew())>

Then if the shopper leaves that particular business and goes to another one, the cart for cust ID 1 clears (on another page i could put a message that says if you leave this customers cart it will clear its self) and starts a new cart for business 2??????

Am i making this clear enough? as i dont know how to fix this prob i am clutching at straws a bit
cheers
Grabit

You could maintain multiple nested structs

<cfscript>
    session['custId'] = CreateUUID();
    // user specific cart
    session['cart'] = StructNew();
    // cart for first business
    session.cart['biz1'] = ArrayNew(1);
    // cart for second business
    session.cart['biz2'] = ArrayNew(1);
    // add item to 'biz1' cart
    ArrayAppend(session.cart.biz1, newItem);
    // add item to 'biz2' cart
    ArrayAppend(session.cart.biz2, differentItem);
</cfscript>

i know this sounds like a pain but could you please give me a brief explanation of whats going on there?
I wont learn by just copying code eh?
cheers
Grabit

There are inline comments there. Line 2 applies a UUID to a variable denoting the customer ID. Line 4 initializes a 'cart' struct in the session. Lines 6 and 8 create cart arrays for 'biz1' and 'biz2'. These are for storing cart items by business, for the customer. Lines 10 and 12 show adding an item to a specific business's cart.

This example stuff is all very abstract, just showing you what is possible. The cart initialization stuff should occur in your application's onSessionStart() method (within Application.cfc), and anytime you are adding items to the cart (ArrayAppend(session.cart.bizq, newItem);) you should probably use locking, to help prevent race conditions. The documentation has great material on Managing Persistent Data and CFQuickDocs is a good quick reference guide to ColdFusion funcitons and tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.