Shopping Cart Best Practice

Results 1 to 2 of 2

Thread: Shopping Cart Best Practice

  1. #1
    Join Date
    Dec 1969

    Default Shopping Cart Best Practice

    This is an optimization question. There are a variety of shopping cart examples that use various methods for storing the values in the cart- dictionary object, arrays, database with basketID, Session variables for basketID. What is the best way to store the values and not lose performance? I have heard the dictionary object is bad. I know that making roundtrips to the db can also be bad. So I am not sure what to do.

  2. #2
    Join Date
    Dec 1969

    Default RE: Shopping Cart Best Practice

    Well personally I create the shopping cart, when the first item is select to buy. I insert a new invloice in the invoices table, and retreive the InvID, and store it in a session var. Then all I carry with me is this InvID accross the session. As I add invoice lines I key them to the master InvID. Wheneven I want to do anything with the cart (eg viewcart, checkout) I retrieve the Invoice and InvoiceLines recordsets.<BR><BR>I think this is reasonably efficient as the single session var carries little overhead, and with connection pooling for the database, it is just a quick db access.<BR><BR>To make if a little less db-hungry, I think it would be quite viable to just store the cart in an array session variable. Say you just need to store the ProductID and Quantity, this would possible just be two numbers, or astring and a number. In the worst case the string might be 10 chars and if the quantity is stored in a longint (64bit), then each item would take 18 bytes. So if you had 50 items in the cart, even with any overheads the cart would take less than one kilobyte. So this cart would probaly be okay with several shoppers at once. <BR><BR>Instead or an array you could just keep adding items by concatenating to a string, and using using commas to separate ProdID and Qty, and "&#124" to separate rows, eg:<BR><BR>"Prod001,10&#124Prod005,15&#124"<BR><BR >You would use the split() funtion to extract values, eg:<BR><BR>cartarray=split(cartstr,"&#124")<BR>ite marray=split(cartarray(n),",")<BR>code=Itemarray(0 )<BR>Qty=ItemArray(1)<BR><BR>in the above example,<BR><BR>cartarray would equal {"Prod001,10","Prod005,15&#124"}<BR>and itemarray(1) would equal {"Prod005",15}<BR>code would equal "Prod005"<BR>qty would equal 15<BR><BR>Hope these thought are helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts