Meteor JS: Shopping Cart Without Login - session id, etc

1.9k views Asked by At

I'm working on a e-commerce project. I would like the customers of the e-commerce site to be able to add items to the shopping cart and checkout without having to login.

To do this, I have decided to store the items that the customers would like to add to the shopping cart inside a Collection. e.g.

CartItems = new Mongo.Collection("cartitems");

In order to differentiate this customer's shopping cart items from other customers, I have decided to add a extra field

 var sessid = Meteor.default_connection._lastSessionId;

e.g.

{
    "_id" : "HCo7JYsaruYBNQuC9",
    "qty" : 1,
    "productid" : "hAajzGxpLK4zJ3pXW",
    "session" : "uqTiaeqiawsxLMu7A"
}

to the document added to the CartItems collection.

The problem with this solution is that whenever the page is REFRESHED, the last session Id changes and therefore the cart becomes empty again even though the same user is still using the page.

Also, the documents added to the Collection does not get cleaned up (deleted) as I have no way of detecting if the session is going to be ended by the browser/user.

1.) What's the ideal solution to this problem?

2.) How do I implement the shopping cart for it to know that even though the page has been refreshed the user using the site is most likely the same person and therefore it should still keep the same items in the shopping cart? With my current solution of using session ids to differentiate one cart item from another seems to be not the suitable solution for this...

3.) With my current solution of using last session ids, the Collection will eventually be full of cart items with session ids from the past and I would like to provide a automatic clean-up functionality within the app for this. What's the best way to do this clean-up? Is there a way to detect an 'end of session'?

Thank you very much.

0

There are 0 answers