I am learning to use playframework
by writing code to implement a webstore
for selling items.I have implemented the Admin
area using the crud
and secure
modules.Now, I want to create a shopping cart
to which a user can add items and proceed to checkout .
My knowledge of ecommerce is minimal,but I had gone through some textbooks which implement shopping carts and some webshop functionality using servlets
.In the books ,the cart used to keep a Set
of CartItem
s ,each of which contained an instance of the Product
and quantity
.After,the user added items to cart,the cart was stored in user session
.
So,anytime the user went to the cart details page,it showed all the added items.Only when the session was cleared,(either due to session timeout as defined in the server,or when the order was placed)the CartItem
s were removed from the ShoppingCart
.
I guess ,I can use the Cache in playframework to do the above.After adding a CartItem to ShoppingCart instance .I can
shopcart.add(mycartItem);
Cache.set(session.getId(), shopcart);
..
and later,in another page ,I can retrieve,the cart and its contents,process them and clear the cart.
ShopCart cart = Cache.get(session.getId(),ShopCart.class);
Set<CartItem> items = cart.getCartItems();
processOrder(items,userinfo);
...
cart.clearItems();
Is this the right way to go about this?If the way I am thinking is not correct,please help me with suggestions.