How best to store user data in Spring? - spring

Now I'm trying to develop Internet shop on Spring and now trying to create cart. What is the best way to store data like count, sum and list of products in the cart? I used HttpSession and Cookies, but Cookies can't store lists...

The cart is a pojo, those fields are properties of your object.
You can persist it in the database, or in session.
To do it in session, example:
Spring store object in session
https://www.youtube.com/watch?v=dcAYJSh_8ig
There is no best way, just the way you should do it given the context you have.
But persisting it in database allows you to have a cart history, you can remember the user cart after the session is gone, and you scale more easily because you can share your state between several server instances.
To do it with entities:
https://www.youtube.com/watch?v=DctbMWGZ42o
Just a proposition:
You can associate a anonymous account to the user session, and this anon account owns a cart. If the user create a real account, you transform the anon account to real account and keep the cart to order. If the user never go back, you should have a rule to clean the anon data every once in a while. If you can know the user email while it is an anon user (example: popup to register to newsletter), you can call him back to remember him that he has a waiting cart on the website.

Related

How to use Vuex store to manage registered users and guests (unregistered users)?

I currently have an application allowing users to purchase items, providing prior registration and login.
The stack is Vue (+Vuex) / Laravel. All users are registered in the app database and the Vuex store's user state is populated from the user's table in DB on login.
I would like to modify this process to allow guests to purchase without registering (like in some online store where you have the option to order with or without registration).
From an architectural perspective, how should I achieve this? I was thinking about creating a static "guest" user record in the database from which the Vuex store's user state will be initialised, then the store will be used during order and destroyed after. Is it the right path to go?

web application cart implementation for non-logged users

I am working for implementing a spring-boot based shopping application, where a feature exist called ‘add to cart’ for product which works when users is only logged in. Meaning spring-boot back-end creates session when user logged in to make mapping to cart object.
I am trying to implementing a features like real world shopping application like amazon, where product can be added into ‘cart’ even user is not logged in. Then after user log-in user session can be managed / merged with previous non-logged user.
Can some please give me any typical design pattern idea in details or book reference or tutorial link where I can get details idea about such kind of implementation.
If user is anonymous, I would save cart on server and save cart ID in browser using a persistent cookie. When user logs in, server can retrieve the anonymous cart from its ID. Alternatively, you could store full cart in cookie.

How to use existing server token with emberjs simple auth

I'm currently implementing this library ember-simple-auth to manage authentication in the emberjs application (shopping cart) that I am currently building.
The difficulty that I encounter is that the library manages authentication rules after logging in very well but not before logging in.
So here is the scenario:
The application must talk to the backend server to retrieve a session token for every user. This is necessary so that the user can save their items temporarily in the server side using session data. Something that you would expect for a shopping cart.
Then when the user is ready to move forward the application will then display the login screen and the user can authenticate themselves to checkout their items.
However, I can't seems to figure out yet how to do this using simple-auth. If I create a custom authenticator that just fetches token id from the server, it will mark the session as authenticated and will not ask for login on the authenticatedRoute.
In general what I'm trying to do are:
Customer visit the website
The application fetches session token from the server
Customer clicks around and saves item into the shopping cart. The data is synced with the server using the session token
Customer ready to checkout and navigates to checkout page
The application intercepts the route and redirect the customer to login route, where the customer can login and resume checkout.
I hope the above information is clear enough. Any hints and help will be much appreciated. Thanks.
I would probably only use Ember Simple Auth from the point on where the user actually logs in. Before that instead of using a session token to identify the basket, I'd probably explicitly create a basket on the server side (POST /basket) and then add to that via a REST interface (PUT /baskets/:id/items or so). That way you're not sharing state between the client and the server and have a clear interface. You also don't need to "abuse" Ember Simple Auth which probably only leads to other problems later on. When the user logs in then, you simply assign the previously created basket to that user and go on.

CodeIgniter sessions and Cart

please, I have an question about CI Cart library and sessions connected with this. I have setted "sess_time_to_update" to 300 secs (default value) and if this time expires I can´t see products which I saved to the Cart. Is it normal? If I look into database, the other datas here are stored, but cart products not.
Thank you
Yes it is:
How do Sessions work?
When a page is loaded, the session class will check to see if valid
session data exists in the user's session cookie. If sessions data
does not exist (or if it has expired) a new session will be created
and saved in the cookie. If a session does exist, its information will
be updated and the cookie will be updated. With each update, the
session_id will be regenerated.
Once the session has expired (or destroyed) any data stored on it will be deleted.
Shopping Cart Class
The Cart Class permits items to be added to a session that stays
active while a user is browsing your site.
So you have to save the cart's info in your own table if you want it to persist.
See this nice answer about saving cart's informatino into the database (as string, I mean not ideal way, but it help if you want it to retrieve "the last cart" even if the user's session ends) (if you want to keep this information like forever, better to save properly in your own table not as string):
Codeigniter Cart - saving data in database - how to approach?
May be helpful for your need.

Magento cart stored client side or server side?

If a visitor adds items to their cart on a Magento site, could they follow a URL (maybe containing a session id?) from another machine an see the contents of their cart? Or is the cart stored in a cookie on the client side and therefore not available from another machine?
Thank You.
See the new persistent cart feature in 1.6 CE:
Magento stores a long-term cookie in each browser (per device) once the customer logs in or creates an account using that browser. The long term cookie allows us to re-create some of the session the user had when they were logged in previously. For example, a users shopping cart is re-created upon subsequent visits to the site. It does not allow the customer or another user to access sensitive information. The user will not be able to complete the checkout process or access account information unless they are officially logged in. Persistent shopping cart is completely configurable by merchants, provides an additional way for the merchant to strengthen customer satisfaction and loyalty and helps increase conversion rates.

Resources