Lincoln Han wrote:
class Cart(Page, BasicItem, ExtendedItem, Shipping):
customer = Customer() #store the customer info into the customer object at check out
order = Order() #we will need to store the order into the order object at check out
itemlist = list()
subtotal = 0.00
shipping = Shipping() #Shipping object is part of the WebObjects class
I didn't read furher, but the above is a prominent sign IMO.
Your order, customer and other objects are class variables! That means they would be shared for all Cart servlet instances.
You must not put an "order" even to a servlet variable, not to mention class var but store them in Session object. For those that can't be stored there (as they, say, contains a db connection or simply not pickable) you could use, say, a global dict (singleton)
Here is a version I wrote to address this issue (attached).
""" Store for per-session data for WebKit which are stateful and not to be persisted. """
class WebKitSessionStore: """ Store for per-session data for WebKit. """ def __init__(self): self.constructors = {} self.store = {} def register(self, keyName, constructor): "Registers a C{constructor} to be used under specified name." self.constructors[keyName] = constructor def has(self, sessionId, keyName): "Returns C{True} if there is an object in session id for specified name." if self.store.has_key(sessionId) and \ self.store[sessionId].has_key(keyName): return True return False def put(self, sessionId, keyName, obj): "Puts an C{obj} into specified storage under name C{keyName}." if not self.store.has_key(sessionId): self.store[sessionId] = {} self.store[sessionId][keyName] = obj def get(self, sessionId, keyName, *args, **kwargs): """ Returns an object for requested C{sessionId} and C{keyName}. Any extra arguments (and keyword arguments), if any, are passed to the constructor when it is called. """ if not self.store.has_key(sessionId): self.store[sessionId] = {} perSessionStore = self.store[sessionId] if not perSessionStore.has_key(keyName): constructor = self.constructors[keyName] perSessionStore[keyName] = constructor(*args, **kwargs) return perSessionStore[keyName] def clear(self, sessionId): "Frees stored data for given session." if not self.store.has_key(sessionId): raise KeyError("Can't clear for unknown sessionId %s" % sessionId) del self.store[sessionId] store = WebKitSessionStore() ### testfile: tests\test_webstore.py